RosettaCodeData/Task/Fractal-tree/QB64/fractal-tree.qb64
2023-07-01 13:44:08 -04:00

25 lines
697 B
Text

_Title "Fractal Tree"
Const sw% = 640
Const sh% = 480
Screen _NewImage(sw, sh, 8)
Cls , 15: Color 2
Call tree(sw \ 2, sh - 10, _Pi * 1.5, _Pi / 180 * 29, 112, 15)
Sleep
System
Sub tree (x As Integer, y As Integer, initAngle As Double, theta As Double, length As Double, depth As Integer)
Dim As Integer iL, newX, newY, iX, iY, iD
iL = length: iX = x: iY = y: iD = depth
newX = Cos(initAngle) * length + iX
newY = Sin(initAngle) * length + iY
Line (iX, iY)-(newX, newY)
iL = length * .78
iD = iD - 1
If iD > 0 Then
Call tree(newX, newY, initAngle - theta, theta, iL, iD)
Call tree(newX, newY, initAngle + theta, theta, iL, iD)
End If
End Sub