02-06-2025, 11:29 AM
Code: (Select All)
_Title "Stochastic Tree in QB64PE"
Randomize Timer
Screen _NewImage(800, 600, 32)
For a = -_Pi / 2 To 0 Step .1 'just to show how to rotate the angle of the tree
For d = 1 To 10 'the depth of branches on the tree
Cls , &HFF000000&&
DrawStochasticTree 400, 550, a, 100, d
_Delay .25 'as these are the same and we're repeating them for various angles, I went with a low pause
_Display
Next
Next
System
Sub DrawStochasticTree (x As Single, y As Single, angle As Single, length As Single, depth As Integer)
If depth = 0 Or length < 2 Then Exit Sub
x2 = x + length * Cos(angle)
y2 = y + length * Sin(angle)
Line (x, y)-(x2, y2), _RGB32(139, 69, 19)
new_length = length * 0.7
new_depth = depth - 1
DrawStochasticTree x2, y2, angle + RandomAngle, new_length, new_depth
DrawStochasticTree x2, y2, angle - RandomAngle, new_length, new_depth
End Sub
Function RandomAngle
RandomAngle = (Rnd * _Pi / 4 + _Pi / 8) - _Pi / 16
End Function
(And that's the last of these that I'm playing with for tonight. More may come later sometime.)