Play
with the Billiards Simulation
**********************************************************************************
Users are able to choose the dimensions of a table
by typing ~ in the command center ~ BILLIARDS 7 3
(7 being length and 3 being width, as an example.)
To get things rolling push the hit.the.ball button.
But first, make a prediction... Hit at a 45 degree
angle, the ball will go out which pocket?
**********************************************************************************
to begin
newturtle "t1 st
setsh 3
newturtle "t2 ht
end
to billiards :length :width
setup
table :length :width
pockets :length :width
setball
conditions
end
to setup
cg ht setbg 4
pu
setpos [160 -135]
pd
end
to table :length :width
pd setpensize 1
setc 5
repeat :width [repeat :length [square fd 30]
bk (:length * 30)
move]
setpockets
end
to square
setbg 4
pd setc 5
repeat 4 [fd 30 rt 90]pd rt 45 fd 3 setc 54 pd fill pu bk 3 lt 45
end
to move
lt 90 fd 30 rt 90
end
to setpockets
setc 0
rt 90 fd 30 lt 90
setsize 20
setsh 3 st
end
to pockets :length :width
pocketD
pocketC
pocketB
pocketA
rt 45 fd 9
end
to pocketD
fd (:length * 30)
lt 45 bk 20
setsize 30
setsh 7 stamp
fd 20 rt 45
rt 90
end
to pocketC
fd (:width * 30)
lt 45 bk 20
setsize 30
setsh 8 stamp
fd 20 rt 45
rt 90
end
to pocketB
fd (:length * 30)
lt 45 bk 22
setsize 30
setsh 14 stamp
fd 22 rt 45
rt 90
end
to pocketA
fd (:width * 30)
lt 45 bk 20
setsh 15 stamp
fd 20 rt 45
rt 90
end
to setball
fd 15
setsize 20
setsh 3 st
t2, ht
t1, fd 3
end
to conditions
end
to hit
setpensize 1
setc 125 pu
fd .25
ifelse colorunder = 4 [lt 90] []
if colorunder = 9 [ flash stopall]
hit
end
to flash
repeat 10 [setbg 15 wait 1 setbg 0 wait 1 setbg 15]
wait 40 setbg 4
end
to hit.the.ball
hit
end
to make.table
billiards length width
setbg 4
end
to play
page1
end
to instructions
page2
end
|