Sieprinski Triangle

Cybermonkey 24 Jul 2010 21:55

Just a fractal. (Thanx toTomaaz for the code …)

```
require "math"
math.randomseed (os.time())
openwindow (800,600,32,"Sierpinski triangle")
timer1=timerticks()
backcolour (0,0,0)
cls()
x1 = 400
x2 = 400
y1 = 0
y2 = 0
for k = 1,100000 do
los = math.random (0,2)
if los == 0 then
x1 = (x2 + 400) / 2
y1 = y2 / 2
elseif los == 1 then
x1 = x2 / 2
y1 = (y2 + 600) / 2
elseif los == 2 then
x1 = (x2 + 800) / 2
y1 = (y2 + 600) / 2
end
a = math.floor (y1 / 2.4)
b = math.floor (x1 / 3.2)
colour (a, b, 255 - a)
dot (x1, y1)
x2 = x1
y2 = y1
end --loop
timer2=timerticks()
now=timer2-timer1
drawtext (0,0,"Time to calculate in ms: "..now)
redraw()
key=inkey()
closewindow()
```