Here a program of a walking duck on a 50x50 grid.
Rules are:
When cell has no color:
Duck will color cell yellow and move right.
When cell has yellow:
Duck will color red and move left.
When color has red:
Duck will color yellow and move right.
It turns out the grid is coloured quite frantic.
Code: Select all
graphics
maxx = screen_width()
maxy = screen_height()
circlex = maxx / 50
circley = maxy /50
dim field(51,51)
gosub fieldclear
gosub drawfield
duckx = 24
ducky = 24
xr =1
yr=0
padr=1
field(duckx, ducky) = 1
gosub drawfield
for walk = 1 to 10000
gosub drawcell
gosub move
if field(duckx, ducky)= 0 then
vulkleur = 1
end if
if field(duckx, ducky)= 1 then
vulkleur=2
end if
if field(duckx, ducky)= 2 then
vulkleur=1
end if
field(duckx, ducky) = vulkleur
gosub drawcell
gosub newr
pause 0.02
next walk
gosub drawfield
end
drawcell:
if field(duckx, ducky) = 0 then
fill color 0.1, 0.1, 0.1
end if
if field(duckx, ducky) = 1 then
fill color 0.7, 0.7, 0
end if
if field(duckx, ducky) = 2 then
fill color 0.8, 0.2, 0.2
end if
posx = circlex * duckx -6
posy = circley * ducky -6
fill circle posx, posy size 6
return
drawfield:
for i=1 to 50
for j=1 to 50
if field(i,j) = 0 then
fill color 0.1, 0.1, 0.1
end if
if field(i,j) = 1 then
fill color 0.7, 0.4, 0
end if
if field(i,j) = 2 then
fill color 0.8, 0.2, 0.5
end if
posx = circlex * i -6
posy = circley * j -6
fill circle posx, posy size 6
next j
next i
return
fieldclear:
for i=1 to 50
for j=1 to 50
field(i,j)=0
next j
next i
return
move:
duckx = duckx + xr
ducky = ducky + yr
return
newr:
r = field(duckx,ducky)
if r=1 then
gosub left
else
gosub right
end if
return
left:
padr=0
if xr=1 then
xr=0
yr=-1
return
end if
if xr=-1 then
xr=0
yr=1
return
end if
if yr=-1 then
yr=0
xr=-1
return
end if
if yr=1 then
yr=0
xr=1
return
end if
right:
padr=1
if xr=1 then
xr=0
yr=1
return
end if
if xr = -1 then
let xr=0
yr=-1
return
end if
if yr =-1 then
yr=0
xr=1
return
end if
if yr=1 then
yr=0
xr=-1
return
end if
return