Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » How does this formula work?
- ExtraCheeeeese
-
5 posts
How does this formula work?
How does this generate a Sierpinski Triangle?
(Assuming there are sprites in 3 different locations called “1”, “2”, and “3”.)
(Assuming there are sprites in 3 different locations called “1”, “2”, and “3”.)
when green flag clicked
set pen size to (1)
forever
set[Point v]to (pick random (1) to (3))
point towards(Point)
move((distance to (Point))/(2))steps
pen down
pen up
- Steve0Greatness
-
1000+ posts
How does this formula work?
That looks like an implementation of the chaos game:

Essentially, all that's going on is it's going halfway towards its destination. Assuming it starts at a random point, it could go to any other point, then it picks another point and goes halfway there; it keeps going at this, and yet never lands into a space that should be clear.
Video demo
As for why it actually does the Sierpiński triangle, I'd assume there's a lot more in-depth information on the prior linked Wikipedia article.

Essentially, all that's going on is it's going halfway towards its destination. Assuming it starts at a random point, it could go to any other point, then it picks another point and goes halfway there; it keeps going at this, and yet never lands into a space that should be clear.
Video demo
As for why it actually does the Sierpiński triangle, I'd assume there's a lot more in-depth information on the prior linked Wikipedia article.
- nembence
-
100+ posts
How does this formula work?
If the sprite starts at a point of the Sierpinski triangle, then after it moves, it ends up at the same point of one of the the sub-triangles
- Discussion Forums
- » Advanced Topics
-
» How does this formula work?