## Saturday, April 13, 2013

### Cellular automation 2

# The cellular automation program was malfunctioning for a long time because I did not update the code for the New Basic 256 version .
# This is a new version where the chaotic rule and the fractal rule are used different alternating patterns.
#http://mathworld.wolfram.com/ElementaryCellularAutomaton.html

fastgraphics
graphsize 600,300
For n = 1 to 300
plot (300,1)
Print "Fractal rule every "+n+" rows"
For y = 1 to 300
For x = 1 to 600
a=0
if pixel(x-1,y)=black then a=a+1
if pixel(x,y)=black then a=a+10
if pixel(x+1,y)=black then a=a+100

if y/n = int (y/n) then
gosub fractal
else
gosub chaotic
end if

next x
refresh
next y
refresh
clg
next n

chaotic:
if a=001 or a=110 or a =010 or a=100 then plot (x,y+1)
return
fractal:
if a=001 or a=010 or a=100 then plot (x,y+1)
return

## Wednesday, April 3, 2013

### Fastest Lap

# This program is just a big fat loop with a goto in the end.  All the wrong stuff.

graphsize(800,600)
fastgraphics
outputvisible (false)
clg
font ("arial",15,100)
dim track(30)

track={-14,2,-13,4,-12,5,-10,6,10,6,12,5,13,4,14,2,14,0,13,-0,12,-0,11,0,10,1,8,2,7,2,6,1,6,-4,5,-6,4,-7,2,-8,-0,-8,-2,-7,-3,-6,-4,-4,-4,-0,-5,1,-6,2,-7,2,-8,1,-9,-0,-9,-5,-10,-7,-11,-8,-12,-8,-13,-7,-14,-5,-14,2}

dim car1(38)
dim car2(18)
car1={0,-10,-4,-9,-5,-8,-5,-4,-4,2,-4,4,-5,6,-5,9,-4,10,4,10,5,9,5,6,4,4,4,2,5,-4,5,-8,4,-9,0,-10}
car2={0,-2,-1,-2,-3,-0,-3,2,0,1,3,2,3,-0,1,-2,0,-2}
dim pointer (10)
pointer={3,-0,0,1,-15,-0,0,-1,3,-0}

dim tree(100,2)
for n = 0 to 99
tree [n,0]=int (rand*2200-1200)
tree [n,1]=int (rand*2000-1800)
next n

px=-200
py=-50
turn =0
speed =0
flag =0
time =0
laps=-1
bestime=999
init=second()+minute()*60+hour()*3600

#intro####################################
for n = 1 to 100 step .2
penwidth(2*n)
Color (black,green)
clg
stamp 500,250-n*5,n,2*pi*(n/100),track
refresh
next n
penwidth(1)

loop:
# controls arrow keys ###################
z = key
if z = 16777235 then speed=speed+.1
if z = 16777237 then speed=speed-.1
if z = 16777234 and turn>-.2 then
turn =turn-pi/90
else
turn=turn*.95
end if
if z = 16777236 and turn<.2 then turn =turn+pi/90
py = py + yspeed
px = px + xspeed
#Track#######################
color green
rect 0,0,600,600
color darkgreen
for n = 0 to 99
circle tree[n,0]-px, tree[n,1]-py,20
next n
Color (black,0)
penwidth(200)
stamp -px,-350-py,100,0,track
color black
penwidth(1)
color white
rect -px+300,-py+150,20,200
color grey
rect -px,-py+50,300,80
rect -px,-py+370,300,80
color black
Text -px+70,-py+370,"Use arrow keys"
#Car and lake #######################
color red
color blue
color blue
circle -px+70,-py-700,300

#Result panel###############
color blue
rect 600,0,200,600
Color (black,blue)
penwidth(5)
stamp 700,70,5,0,track
color red
circle px/20+715,py/20+102,3
circle 700,200,80
color white
stamp 700,200,5,speed,pointer
time=second()+minute()*60+hour()*3600-init
text 610,300,"Time= "+time+"sec"
text 610,350, "Lap count ="+laps
text 610,400, "Best Time ="+bestime
refresh
#Car goes to grass##########
grass =0
if pixel(321,321)<>black then grass=grass+1
if pixel(279,279)<>black then grass=grass+1
if pixel(279,321)<>black then grass=grass+1
if pixel(321,279)<>black then grass=grass+1
if grass>2 and speed>.2 then speed = speed*.9
#lapcount###########
If pixel (321,300)=white then
if flag=0 then
laps = laps + 1
flag =1
init =second()+minute()*60+hour()*3600
if time<bestime and laps >0 then bestime=time
end if
else
flag = 0
end if
####################
clg
goto loop