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 p0,p1,p2\mathbf{p}_0,\mathbf{p}_1,\mathbf{p}_2 in the plane.

We also choose one additional point p\mathbf{p}.

Where this point is doesn't really matter, so let's just say p=p0\mathbf{p} = \mathbf{p}_0.

Now we repeat the following process:

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:

Solution:

See the solution

You can adjust parameters or run it multiple times to see how the randomness affects the result.

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!