11-09-2022, 11:57 PM
Just some digital doodling. Generate a simple forest landscape of leafy trees.
Code: (Select All)
'BAM_Trees
'quick random leafy random trees
'why is it called BAM-Trees? Because the draw_leaves routine is a variant from a sample at:
' https://sites.google.com/view/basicanywheremachine
'
'press any key to generate a new image
'press <esc> to quit
'
Randomize Timer
Screen _NewImage(1100, 600, 32)
_Title "BAM_Trees!"
Do
Cls
hrz = Int(Rnd * 30 + 120)
Line (0, 0)-(_Width, hrz), _RGB32(Rnd * 10, Rnd * 10, Rnd * 200 + 40), BF
Line (0, hrz)-(_Width, _Height), _RGB32(Rnd * 200 + 40, Rnd * 200 + 40, Rnd * 10), BF
For r = 1 To 4
treetopx = 10: treetopy = r * 120
numtinrow = Int(Rnd * 13 + 6)
For b = 1 To numtinrow
treetopx = treetopx + Int(Rnd * 5 + 5) * (10 * 25 / numtinrow): treetopy = Int(Rnd * 100 + r * 100)
draw_trunk treetopx, treetopy
draw_leaves treetopx, treetopy, Int(Rnd * 20) + 20, Rnd * 5 + 6, Int(Rnd * 360)
Next b
Next r
Do
_Limit 30
kk$ = InKey$
Loop Until kk$ <> ""
Loop Until kk$ = Chr$(27)
Sub draw_leaves (x%, y%, length%, line_count%, start_angle%)
angle_increment% = 360 / line_count%
my_color~& = _RGB32(40, Rnd * (256 - (y% / 6)), 60)
For i% = 0 To (line_count% - 1)
_Limit 40000
Draw "bm " + Str$(x%) + "," + Str$(y%)
Draw "C" + Str$(my_color~&) + " TA" + Str$(start_angle% + angle_increment% * i%) + " r" + Str$(length%)
If length% > (Rnd * 11.4 + 3.5) Then
Call draw_leaves(Point(0), Point(1), Int(length% / (1.125 + Rnd * 2.25)), line_count%, start_angle% + angle_increment% * (i% + 1))
End If
Next
End Sub
Sub draw_trunk (tx, ty)
tw = Int(Rnd * 25 + 10)
For t = 1 To tw
trunk~& = _RGB32(Rnd * 50 + 20, Rnd * 50 + 50, Rnd * 20)
Line (tx, ty)-(tx + Rnd * (8 * tw / 30), ty + 60 + Rnd * 30), trunk~&, BF
Next t
End Sub