Sierpinski Triangle, generated with the Chaos Game (port of a javascript implementation found at ycombinator)
// triangle corners (about equilateral, hardcoded)
a = {"x": (960 - 600) / 2, "y": (640 - 520) / 2}
b = {"x": (960 + 600) / 2, "y": (640 - 520) / 2}
c = {"x": 960 / 2, "y": (640 + 520) / 2 }
// random point inside triangle
randomPoint = function(a, b, c)
p = rnd; q = rnd
if p + q > 1.0 then
p = 1.0 - p; q = 1.0 - q
end if
v1 = {"x": (b.x - a.x) * p, "y": (b.y - a.y) * p}
v2 = {"x": (c.x - a.x) * q, "y": (c.y - a.y) * q}
return {"x": a.x + v1.x + v2.x, "y": a.y + v1.y + v2.y}
end function
// midway between two points
midwayPoint = function(a, b)
return {"x": (a.x + b.x) / 2, "y": (a.y + b.y) / 2}
end function
// random element of a list
getRandom = function(list)
return list[floor(rnd * list.len)]
end function
// clear graphics, draw a triangle
gfx.clear
gfx.line a.x, a.y, b.x, b.y, color.yellow
gfx.line b.x, b.y, c.x, c.y, color.yellow
gfx.line c.x, c.y, a.x, a.y, color.yellow
// choose a random point
point = randomPoint(a, b, c)
gfx.setPixel point.x, point.y, color.aqua
// iterate
for i in range(2, 10000)
point = midwayPoint(point, getRandom([a, b, c]))
gfx.setPixel point.x, point.y, color.aqua
end for