' turtle essence.bas SmallBASIC 0.12.9 (B+=MGA) 2017-06-13
' From my experience with Draw Strings and Nano series,
' I think I have discovered the essence of Turtle Drawing
' I contend that all can be done with 5 global variables
' x, y the start position of ray = ra line
' a, r the radian angle of direction to go and r the distance
' p is pen color, draw if 0 <= p <= 15 (QB colors 0 - 15)
' and one graphics command ra (as sub or gosub)
sub ra
local x1 = x + r * cos(a)
local y1 = y + r * sin(a)
' if pen p has a color draw, else just update x, y position
if 0 <= p and p <= 15 then line x, y, x1, y1, p
x = x1 : y = y1 'update x, y with current turtle position
end
'===== that's all the setup you need to do turle drawing
'but let's setup a Home position in middle of screen
homeX = xmax/2 : homeY = ymax/2
' lines commented out are from Galileo's tree code found at
' http://retrogamecoding.org/board/index.php?topic=581.0
'this code modifies Galileo's allowing tree to grow and sway with beautiful background!
'import turtle3
'clear screen
'startTurtle()
'home() ' oh this sets start angle at 270 degrees or 3*pi/2
x = homex: y =homey
a = 3*pi/2
'goy(200)
y = y + 200
'pen(1)
'color 0, 255, 0
p = 6
horizon = ymax/2 + 100
for i = 1 to 300
cls
for h= 0 to horizon
midInk 0,0,128, 40, 200, 255, h/horizon
line 0, h, xmax, h
next
for h = horizon to ymax
midInk 40,200,255, 50, 200, 50, (h-horizon)/(ymax-horizon)
line 0, h, xmax, h
next
tree i
showpage
next
while 1
sway = sway + (rnd*2) -1
if sway > 25 then sway = 25
if sway < -25 then sway = -25
cls
for h= 0 to horizon
midInk 0,0,128, 40, 200, 255, h/horizon
line 0, h, xmax, h
next
for h = horizon to ymax
midInk 40,200,255, 50, 200, 50, (h-horizon)/(ymax-horizon)
line 0, h, xmax, h
next
a = a + rad(sway)
tree i
a = a - rad(sway)
showpage
wend
pause
sub tree(size)
if size < 5 then
'move(size)
r = size
ra
'move(-size)
r = -size
ra
'return
exit sub
end if
'move(size/3)
r = size/3
ra
'turn(-30)
a = a - rad(30 + sway)
tree(size*2/3)
'turn(30)
a = a + rad(30 + sway)
'move(size/6)
r = size/6
ra
'turn(25)
a = a + rad(25 + sway)
tree(size/2)
'turn(-25)
a = a - rad(25 + sway)
'move(size/3)
r = size/3
ra
'turn(25)
a = a + rad(25 + sway)
tree(size/2)
'turn(-25)
a = a - rad(25 + sway)
'move(size/6)
r = size/6
ra
'move(-size)
r = -size
ra
end sub
sub midInk(r1, g1, b1, r2, g2, b2, fr)
color rgb(r1+(r2-r1)*fr, g1+(g2-g1)*fr, b1+(b2-b1)*fr)
end