Coding challenge

Can complete randomness produce perfect geometric order?

Define three vertices of an equilateral triangle: $(0, 150)$, $(-150, -100)$, and $(150, -100)$. Start a point $(x, y)$ at $(0, 0)$. In a loop of $5{,}000$ steps:

  1. Randomly pick one of the three vertices using math.random(1, 3).
  2. Move $(x, y)$ halfway toward that vertex: $x = (x + x_v)/2$ and $y = (y + y_v)/2$.
  3. Plot the point using pset(x, y).
What famous fractal shape emerges on the screen?

Type your code here:


Lua reference

See your results here: