Langtons Ant

Community Forums/Showcase/Langtons Ant

SilentAssaSIN(Posted 2003) [#1]
I was reading "The Science of Discworld" and thought it would be cool to program the ant for myself, so here is my version, at 0.7 anyway...

1) you can add in/change the colour of the squares by clicking where you want the change, then when you are done press space and the ant will walk away...

Dim floorxy(50,50)
Graphics 300,50,16,2

Global Ax=25,Ay=25,Ad=2,steps
;==== U=1 R=2 D=3 L=4
;==== 1 left 0 right

While Not KeyDown(57)
If MouseDown(1) Then
If floorxy(MouseX(),MouseY())=0 Then
floorxy(MouseX(),MouseY())=1
Else
floorxy(MouseX(),MouseY())=0
EndIf
EndIf

For x=0 To 49
For y=0 To 49
Color floorxy(x,y)*100,floorxy(x,y)*100,floorxy(x,y)*100
Plot x,y
Next
Next

Flip

Wend

While Not KeyDown(1)
Cls

Select Ad
Case 1

Ay=Ay-1
If Ay=0 Then Ay=48
If floorxy(Ax,Ay)=1 Then
floorxy(Ax,Ay)=0
Ad=4
Else
floorxy(Ax,Ay)=1
Ad=2
EndIf
Case 2

Ax=Ax+1
If Ax=49 Then Ax=1
If floorxy(Ax,Ay)=1 Then
floorxy(Ax,Ay)=0
Ad=1
Else
floorxy(Ax,Ay)=1
Ad=3
EndIf
Case 3

Ay=Ay+1
If Ay=49 Then Ay=1
If floorxy(Ax,Ay)=1 Then
floorxy(Ax,Ay)=0
Ad=2
Else
floorxy(Ax,Ay)=1
Ad=4
EndIf
Case 4
Ax=Ax-1
If Ax=0 Then Ax=48
If floorxy(Ax,Ay)=1 Then
floorxy(Ax,Ay)=0
Ad=1
Else
floorxy(Ax,Ay)=1
Ad=3
EndIf
End Select


For x=0 To 49
For y=0 To 49
Color floorxy(x,y)*100,floorxy(x,y)*100,floorxy(x,y)*100
Plot x,y
Next
Next

Color 0,255,0
Plot Ax,Ay

steps=steps+1
If KeyDown(57) Then createimg()

Flip

Wend


Function createimg()
Text 100,0,"Steps taken: "+steps
Text 100,10,"Direction: "+Ad
a=CreateImage(300,50)
GrabImage a,0,0
SaveImage a,"Screen grab"+MilliSecs()+".bmp"
End Function


Neuro(Posted 2003) [#2]
So...what does this do?


SilentAssaSIN(Posted 2003) [#3]
its a basic make the 'ant' obide by a few simple rules...
1) If it hits a white square it turns left
2) If it hits a black square it turns right
3) It inverses the color of each square when it touches it

makes patterns and is very famous, but


Case 4
Ax=Ax-1
If Ax=0 Then Ax=48
If floorxy(Ax,Ay)=1 Then
floorxy(Ax,Ay)=0
Ad=1
Else
floorxy(Ax,Ay)=1
Ad=3



needs to be changed to


Case 4
Ax=Ax-1
If Ax=0 Then Ax=48
If floorxy(Ax,Ay)=1 Then
floorxy(Ax,Ay)=0
Ad=3
Else
floorxy(Ax,Ay)=1
Ad=1

...I believe

serach on google for Jack Cohens paper "Figment of Reality" for more until I do more