Import mojo
Class Fractal Extends App
Field once:Bool
Field gen:int
Field Cell:Int[]
Field width:Int=640/2
Field height:Int=480/2
Method OnCreate()
SetUpdateRate(60)
InitCells(width,height)
End
Method InitCells(width:Int,height:int)
Local i
For Local y:Int=0 To height-1
For Local x:Int=0 To width-1
i+=1
Seed+=Millisecs()
Cell[i]=0
Next
Next
For i=0 To width
Seed+=Millisecs()
Cell[i]=Int(Rnd(0,2))
Next
End
Method DrawCells(width:Int,height:int)
Local i
Local c
Cls 64,64,64
For Local y:Int=0 To height-1
For Local x:Int=0 To width-1
i+=1
c=75+Float(180)/Float(width)*Float(x)
SetColor c,c,c
If Cell[i]>0 Then DrawRect (DeviceWidth/width)*x,(DeviceHeight/height)*y,(DeviceWidth/width),(DeviceHeight/height)
Next
Next
End
Method MoveCells(width:int,height:int)
Local i=(width*height)
For Local y:Int=0 To height-1
For Local x:Int=0 To width-1
Cell[i]=Cell[i-width]
i-=1
Next
Next
End
Method NextLine(width:Int,height:int)
Local l:Int
Local m:Int
Local r:Int
For Local i:Int=0 To width
l=(i+width)-1
m=(i+width)
r=(i+width)+1
If i=1 Then l=(2*width)
If i=width Then r=(width+1)
If Cell[l]=1 And Cell[m]=1 And Cell[r]=1 Then Cell[i]=0'0'0'0
If Cell[l]=1 And Cell[m]=1 And Cell[r]=0 Then Cell[i]=1'1'1'0
If Cell[l]=1 And Cell[m]=0 And Cell[r]=1 Then Cell[i]=1'1'1'0
If Cell[l]=1 And Cell[m]=0 And Cell[r]=0 Then Cell[i]=0'1'0'1
If Cell[l]=0 And Cell[m]=1 And Cell[r]=1 Then Cell[i]=1'1'1'1
If Cell[l]=0 And Cell[m]=1 And Cell[r]=0 Then Cell[i]=1'1'1'1
If Cell[l]=0 And Cell[m]=0 And Cell[r]=1 Then Cell[i]=1'1'1'1
If Cell[l]=0 And Cell[m]=0 And Cell[r]=0 Then Cell[i]=0'0'0'0
Next
End
Method OnUpdate()
If MouseDown=True Or once=False Then InitCells(width,height);once=True
MoveCells(width,height)
NextLine(width,height)
gen+=1
End
Method OnRender()
DrawCells(width,height)
End
End
Function Main()
New Fractal
End