00: Getting started - Drawing points
To get things started we will be playing a game and putting points on a canvas. It is a game of chance and might not seem like much when you see the description, but you will be surprised what can arise from something so simple!
Getting lost in a triangle
Our game can be described pretty quickly.
We specify three fixed points in the plane.
We also choose one additional point .
Where this point is doesn't really matter, so let's just say .
Now we repeat the following process:
- Choose one of the fixed points randomly. Let's call this chosen point with index .
- Replace with
- Put a color on your pixel at position
In the following script, you have to implement the update procedure described above.
The picture will appear below the script.
What do you think will be the result?
The solution is hidden below!
Exercise:
-
Implement the process described above
- Choose one of the
pointsrandomly and call it - Replace with
- Choose one of the
Solution:
You are seeing the famous Sierpinski triangle! When plotted, this looks like four triangles cut out of a larger one... repeatedly. The wonderful thing is, that the randomness doesn't really affect the result. Sure, the exact point that you see are slightly different, but the overall shape will not change. And if you use enough points, you won't be able to see a difference anymore!