Fall Foliage.bas


'fall foliage.bas SmallBASIC 0.12.9 (B+=MGA) 2017-10-21

'test landscape and portrait views for Android
xmx = min(xmax, 800) : ymx = min(600, ymax) 'portrait
'OK it's just plain better in landscape view

'now for full viewing enjoyment
xmx = xmax : ymx = ymax

n = 3
while 1
if n < 15 then n = n + 3
horizon = rand(.8 * ymx, .9 * ymx)
for i= 0 to horizon
midInk 0, 0, 128, 10, 120, 128, i/horizon
line 0, i, xmx, i
next
for i = horizon to ymx
midInk 70, 108, 30, 60, 10, 5, (i-horizon)/(ymx-horizon)
line 0, i, xmx, i
next
for i = 1 to xmx * ymx * .00018
leaf rand(0, xmx), rand(horizon * 1.002, ymx)
next
if n < .01 * xmx then trees = n else trees = rand(.01 * xmx, .03 * xmx)
for i = 1 to trees
y = horizon + .04 * ymx + i / trees * (ymx - horizon - .1 * ymx)
r = .01 * y : h = rand(y * .15, y * .18)
branch rand(10, xmx - 10), y, r, 90, h, 0
next
rect xmx, 0, xmax, ymax, 0 filled
rect 0, ymx, xmx, ymax, 0 filled
showpage
delay 2000
wend

sub
branch(x, y, startr, angD, length, lev)
local x2, y2, dx, dy, bc, i
x2 = x + cos(rad(angD)) * length
y2 = y - sin(rad(angD)) * length
dx = (x2 - x) / length
dy = (y2 - y) / length
bc = rgb(30 + 6 * lev, 15 + 3 * lev, 5 + 2 * lev)
for i = 0 to length
circle x + dx * i, y + dy * i, startr, 1, bc filled
next
if lev > 1 then leaf x2, y2
if .8 * startr < .1 or lev > 7 or length < 3 then exit sub
lev += 1
branch x2, y2, .8 * startr, angD + 22 + rand(-10, 19), rand(.75 * length, .9 * length), lev
branch x2, y2, .8 * startr, angD - 22 - rand(-10, 19), rand(.75 * length, .9 * length), lev
end

sub
leaf(x, y)
local sp, n, c, xoff, yoff, woff, hoff
sp = 15 : leafs = rand(xmx * ymx * .00001, xmx * ymx * .00002)
for n = 1 to leafs
c = rgb(rand(50, 250), rand(25, 255), rand(0, 40))
xoff = x + rnd * sp - rnd * sp
yoff = y + rnd * sp - rnd * sp
woff = 3 + rnd * 3
hoff = 3 + rnd * 3
rect xoff, yoff step woff, hoff, c filled
next
end

sub
midInk(r1, g1, b1, r2, g2, b2, fr)
color rgb(r1 + (r2 - r1) * fr, g1 + (g2 - g1) * fr, b1 + (b2 - b1) * fr)
end

def rand(lo, hi) = (rnd * (hi - lo + 1)) \ 1 + lo