Java Reference
In-Depth Information
B
A
C
To draw the Sierpinski gasket follow the algorithm:
1. Randomly pick one of the three corners. Call this the current point.
(Alternatively, you could also randomly select any point inside the triangle).
2. Randomly pick one of the three corners. Call this the target point.
3. Calculate the midpoint between the current point and the target point.
4. Draw a single pixel at the midpoint.
5. Set the current point to the midpoint.
6. Go back to step 2 and repeat many times (e.g., 50,000 iterations).
It would seem like you should get a random mess of dots since the algorithm
randomly picks a target corner each time. Instead, if this process is repeated
many times, you will get a very orderly picture with a repeating structure:
To draw a single pixel at coordinate (X,Y) use the drawLine method where the
start and endpoints are both (X,Y).
Search WWH ::




Custom Search