Import mojo Class Langton Extends App Field s:Int[] Field w:Int=640 Field h:Int=480 Field ccw:Int=80 Field cch:Int=60 Field px:Int Field py:Int Field md:Int=1 Field dr:Int=1 Field once:Bool Field i:Int Field cw:Int Field ch:Int Field clock:Int Field d:Int[] Field reset:Bool Field rule:String[13] Field rlen:Int Field rmin:Int Field rmax:Int Method OnCreate() SetUpdateRate(0) Local n:Int px=Int(ccw*0.5) py=Int(cch*0.5) cw=Int(w/ccw) ch=int(h/cch) For Local x:Int=1 To ccw+1 For Local y:Int=1 To cch n+=1 s[n]=0 Next Next i=cch*(ccw*0.5)+(ccw*0.5) s[i]=1 rlen=4 rule[1]="R" rule[2]="L" rule[3]="L" rule[4]="R" End Method OnUpdate() Local n:Int If MouseDown(MOUSE_LEFT)=True And reset=false Then px=Int(ccw*0.5) py=Int(cch*0.5) md=1 dr=1 For Local x:Int=1 To ccw+1 For Local y:Int=1 To cch n+=1 s[n]=0 Next Next For Local rc:Int=1 To 12 rule[rc]="" Next Seed+=Millisecs() rlen=Int(Rnd(2,13)) Select Int(Rnd(1,3)) Case 1 rmin=1;rmax=5 Case 2 rmin=1;rmax=3 End Select For Local rc:Int=1 To rlen Seed+=Millisecs() Select Int(Rnd(rmin,rmax)) Case 1 rule[rc]="R" Case 2 rule[rc]="L" Case 3 rule[rc]="F" Case 4 rule[rc]="B" End Select next i=cch*(ccw*0.5)+(ccw*0.5) s[i]=1 clock=0 once=False reset=True End If If MouseDown(MOUSE_LEFT)=False Then reset=false clock+=1 Select md Case 1'up py-=1;If py<0 Then py+=cch;i+=cch i-=1 Select s[i] Case 0 If rlen>1 Then s[i]=1 Else s[i]=0 If rule[1]="L" Then md=4 If rule[1]="R" Then md=2 If rule[1]="F" Then md=1 If rule[1]="B" Then md=3 Case 1 If rlen>2 Then s[i]=2 Else s[i]=0 If rule[2]="L" Then md=4 If rule[2]="R" Then md=2 If rule[2]="F" Then md=1 If rule[2]="B" Then md=3 Case 2 If rlen>3 Then s[i]=3 Else s[i]=0 If rule[3]="L" Then md=4 If rule[3]="R" Then md=2 If rule[3]="F" Then md=1 If rule[3]="B" Then md=3 Case 3 If rlen>4 Then s[i]=4 Else s[i]=0 If rule[4]="L" Then md=4 If rule[4]="R" Then md=2 If rule[4]="F" Then md=1 If rule[4]="B" Then md=3 Case 4 If rlen>5 Then s[i]=5 Else s[i]=0 If rule[5]="L" Then md=4 If rule[5]="R" Then md=2 If rule[5]="F" Then md=1 If rule[5]="B" Then md=3 Case 5 If rlen>6 Then s[i]=6 Else s[i]=0 If rule[6]="L" Then md=4 If rule[6]="R" Then md=2 If rule[6]="F" Then md=1 If rule[6]="B" Then md=3 Case 6 If rlen>7 Then s[i]=7 Else s[i]=0 If rule[7]="L" Then md=4 If rule[7]="R" Then md=2 If rule[7]="F" Then md=1 If rule[7]="B" Then md=3 Case 7 If rlen>8 Then s[i]=8 Else s[i]=0 If rule[8]="L" Then md=4 If rule[8]="R" Then md=2 If rule[8]="F" Then md=1 If rule[8]="B" Then md=3 Case 8 If rlen>9 Then s[i]=9 Else s[i]=0 If rule[9]="L" Then md=4 If rule[9]="R" Then md=2 If rule[9]="F" Then md=1 If rule[9]="B" Then md=3 Case 9 If rlen>10 Then s[i]=10 Else s[i]=0 If rule[10]="L" Then md=4 If rule[10]="R" Then md=2 If rule[10]="F" Then md=1 If rule[10]="B" Then md=3 Case 10 If rlen>11 Then s[i]=11 Else s[i]=0 If rule[11]="L" Then md=4 If rule[11]="R" Then md=2 If rule[11]="F" Then md=1 If rule[11]="B" Then md=3 Case 11 If rlen>12 Then s[i]=12 Else s[i]=0 If rule[12]="L" Then md=4 If rule[12]="R" Then md=2 If rule[12]="F" Then md=1 If rule[12]="B" Then md=3 Case 12 If rlen>13 Then s[i]=0 Else s[i]=0 If rule[13]="L" Then md=4 If rule[13]="R" Then md=2 If rule[13]="F" Then md=1 If rule[13]="B" Then md=3 End Select Case 2'right px+=1;If px=ccw Then px-=ccw;i-=cch*ccw i+=cch Select s[i] Case 0 If rlen>1 Then s[i]=1 Else s[i]=0 If rule[1]="L" Then md=1 If rule[1]="R" Then md=3 If rule[1]="F" Then md=2 If rule[1]="B" Then md=4 Case 1 If rlen>2 Then s[i]=2 Else s[i]=0 If rule[2]="L" Then md=1 If rule[2]="R" Then md=3 If rule[2]="F" Then md=2 If rule[2]="B" Then md=4 Case 2 If rlen>3 Then s[i]=3 Else s[i]=0 If rule[3]="L" Then md=1 If rule[3]="R" Then md=3 If rule[3]="F" Then md=2 If rule[3]="B" Then md=4 Case 3 If rlen>4 Then s[i]=4 Else s[i]=0 If rule[4]="L" Then md=1 If rule[4]="R" Then md=3 If rule[4]="F" Then md=2 If rule[4]="B" Then md=4 Case 4 If rlen>5 Then s[i]=5 Else s[i]=0 If rule[5]="L" Then md=1 If rule[5]="R" Then md=3 If rule[5]="F" Then md=2 If rule[5]="B" Then md=4 Case 5 If rlen>6 Then s[i]=6 Else s[i]=0 If rule[6]="L" Then md=1 If rule[6]="R" Then md=3 If rule[6]="F" Then md=2 If rule[6]="B" Then md=4 Case 6 If rlen>7 Then s[i]=7 Else s[i]=0 If rule[7]="L" Then md=1 If rule[7]="R" Then md=3 If rule[7]="F" Then md=2 If rule[7]="B" Then md=4 Case 7 If rlen>8 Then s[i]=8 Else s[i]=0 If rule[8]="L" Then md=1 If rule[8]="R" Then md=3 If rule[8]="F" Then md=2 If rule[8]="B" Then md=4 Case 8 If rlen>9 Then s[i]=9 Else s[i]=0 If rule[9]="L" Then md=1 If rule[9]="R" Then md=3 If rule[9]="F" Then md=2 If rule[9]="B" Then md=4 Case 9 If rlen>10 Then s[i]=10 Else s[i]=0 If rule[10]="L" Then md=1 If rule[10]="R" Then md=3 If rule[10]="F" Then md=2 If rule[10]="B" Then md=4 Case 10 If rlen>11 Then s[i]=11 Else s[i]=0 If rule[11]="L" Then md=1 If rule[11]="R" Then md=3 If rule[11]="F" Then md=2 If rule[11]="B" Then md=4 Case 11 If rlen>12 Then s[i]=12 Else s[i]=0 If rule[12]="L" Then md=1 If rule[12]="R" Then md=3 If rule[12]="F" Then md=2 If rule[12]="B" Then md=4 Case 12 If rlen>13 Then s[i]=0 Else s[i]=0 If rule[13]="L" Then md=1 If rule[13]="R" Then md=3 If rule[13]="F" Then md=2 If rule[13]="B" Then md=4 End Select Case 3'down py+=1;If py=cch Then py-=cch;i-=cch i+=1 Select s[i] Case 0 If rlen>1 Then s[i]=1 Else s[i]=0 If rule[1]="L" Then md=2 If rule[1]="R" Then md=4 If rule[1]="F" Then md=3 If rule[1]="B" Then md=1 Case 1 If rlen>2 Then s[i]=2 Else s[i]=0 If rule[2]="L" Then md=2 If rule[2]="R" Then md=4 If rule[2]="F" Then md=3 If rule[2]="B" Then md=1 Case 2 If rlen>3 Then s[i]=3 Else s[i]=0 If rule[3]="L" Then md=2 If rule[3]="R" Then md=4 If rule[3]="F" Then md=3 If rule[3]="B" Then md=1 Case 3 If rlen>4 Then s[i]=4 Else s[i]=0 If rule[4]="L" Then md=2 If rule[4]="R" Then md=4 If rule[4]="F" Then md=3 If rule[4]="B" Then md=1 Case 4 If rlen>5 Then s[i]=5 Else s[i]=0 If rule[5]="L" Then md=2 If rule[5]="R" Then md=4 If rule[5]="F" Then md=3 If rule[5]="B" Then md=1 Case 5 If rlen>6 Then s[i]=6 Else s[i]=0 If rule[6]="L" Then md=2 If rule[6]="R" Then md=4 If rule[6]="F" Then md=3 If rule[6]="B" Then md=1 Case 6 If rlen>7 Then s[i]=7 Else s[i]=0 If rule[7]="L" Then md=2 If rule[7]="R" Then md=4 If rule[7]="F" Then md=3 If rule[7]="B" Then md=1 Case 7 If rlen>8 Then s[i]=8 Else s[i]=0 If rule[8]="L" Then md=2 If rule[8]="R" Then md=4 If rule[8]="F" Then md=3 If rule[8]="B" Then md=1 Case 8 If rlen>9 Then s[i]=9 Else s[i]=0 If rule[9]="L" Then md=2 If rule[9]="R" Then md=4 If rule[9]="F" Then md=3 If rule[9]="B" Then md=1 Case 9 If rlen>10 Then s[i]=10 Else s[i]=0 If rule[10]="L" Then md=2 If rule[10]="R" Then md=4 If rule[10]="F" Then md=3 If rule[10]="B" Then md=1 Case 10 If rlen>11 Then s[i]=11 Else s[i]=0 If rule[11]="L" Then md=2 If rule[11]="R" Then md=4 If rule[11]="F" Then md=3 If rule[11]="B" Then md=1 Case 11 If rlen>12 Then s[i]=12 Else s[i]=0 If rule[12]="L" Then md=2 If rule[12]="R" Then md=4 If rule[12]="F" Then md=3 If rule[12]="B" Then md=1 Case 12 If rlen>13 Then s[i]=0 Else s[i]=0 If rule[13]="L" Then md=2 If rule[13]="R" Then md=4 If rule[13]="F" Then md=3 If rule[13]="B" Then md=1 End Select Case 4'left px-=1;If px<0 Then px+=ccw;i+=ccw*cch i-=cch Select s[i] Case 0 If rlen>1 Then s[i]=1 Else s[i]=0 If rule[1]="L" Then md=3 If rule[1]="R" Then md=1 If rule[1]="F" Then md=4 If rule[1]="B" Then md=2 Case 1 If rlen>2 Then s[i]=2 Else s[i]=0 If rule[2]="L" Then md=3 If rule[2]="R" Then md=1 If rule[2]="F" Then md=4 If rule[2]="B" Then md=2 Case 2 If rlen>3 Then s[i]=3 Else s[i]=0 If rule[3]="L" Then md=3 If rule[3]="R" Then md=1 If rule[3]="F" Then md=4 If rule[3]="B" Then md=2 Case 3 If rlen>4 Then s[i]=4 Else s[i]=0 If rule[4]="L" Then md=3 If rule[4]="R" Then md=1 If rule[4]="F" Then md=4 If rule[4]="B" Then md=2 Case 4 If rlen>5 Then s[i]=5 Else s[i]=0 If rule[5]="L" Then md=3 If rule[5]="R" Then md=1 If rule[5]="F" Then md=4 If rule[5]="B" Then md=2 Case 5 If rlen>6 Then s[i]=6 Else s[i]=0 If rule[6]="L" Then md=3 If rule[6]="R" Then md=1 If rule[6]="F" Then md=4 If rule[6]="B" Then md=2 Case 6 If rlen>7 Then s[i]=7 Else s[i]=0 If rule[7]="L" Then md=3 If rule[7]="R" Then md=1 If rule[7]="F" Then md=4 If rule[7]="B" Then md=2 Case 7 If rlen>8 Then s[i]=8 Else s[i]=0 If rule[8]="L" Then md=3 If rule[8]="R" Then md=1 If rule[8]="F" Then md=4 If rule[8]="B" Then md=2 Case 8 If rlen>9 Then s[i]=9 Else s[i]=0 If rule[9]="L" Then md=3 If rule[9]="R" Then md=1 If rule[9]="F" Then md=4 If rule[9]="B" Then md=2 Case 9 If rlen>10 Then s[i]=10 Else s[i]=0 If rule[10]="L" Then md=3 If rule[10]="R" Then md=1 If rule[10]="F" Then md=4 If rule[10]="B" Then md=2 Case 10 If rlen>11 Then s[i]=11 Else s[i]=0 If rule[11]="L" Then md=3 If rule[11]="R" Then md=1 If rule[11]="F" Then md=4 If rule[11]="B" Then md=2 Case 11 If rlen>12 Then s[i]=12 Else s[i]=0 If rule[12]="L" Then md=3 If rule[12]="R" Then md=1 If rule[12]="F" Then md=4 If rule[12]="B" Then md=2 Case 12 If rlen>13 Then s[i]=0 Else s[i]=0 If rule[13]="L" Then md=3 If rule[13]="R" Then md=1 If rule[13]="F" Then md=4 If rule[13]="B" Then md=2 End Select End Select End Method OnRender() If once=False Then Cls 64,64,64;once=True MoveAnt() End Method MoveAnt() Local c:int Select s[i] Case 0 SetColor 64,64,64 Default c=Float(190)/Float(rlen)*Float(s[i]) SetColor 255-c,255-c,c End Select DrawRect px*cw,py*ch,cw,ch SetColor 250,250,250 DrawText "Rule: "+rule[1]+rule[2]+rule[3]+rule[4]+rule[5]+rule[6]+rule[7]+rule[8]+rule[9]+rule[10]+rule[11]+rule[12]+" ("+rlen+") Generation: "+clock,10,10 End End Function Main() New Langton End