39 lines
976 B
Plaintext
39 lines
976 B
Plaintext
' version 03-12-2016
|
|
' compile with: fbc -s gui
|
|
' or fbc -s console
|
|
|
|
Sub pythagoras_tree(x1 As Double, y1 As Double, x2 As Double, y2 As Double, depth As ULong)
|
|
|
|
If depth > 10 Then Return
|
|
|
|
Dim As Double dx = x2 - x1, dy = y1 - y2
|
|
Dim As Double x3 = x2 - dy, y3 = y2 - dx
|
|
Dim As Double x4 = x1 - dy, y4 = y1 - dx
|
|
Dim As Double x5 = x4 + (dx - dy) / 2
|
|
Dim As Double y5 = y4 - (dx + dy) / 2
|
|
'draw the box
|
|
Line (x1, y1) - (x2, y2) : Line - (x3, y3)
|
|
Line - (x4, y4) : Line - (x1, y1)
|
|
|
|
pythagoras_tree(x4, y4, x5, y5, depth +1)
|
|
pythagoras_tree(x5, y5, x3, y3, depth +1)
|
|
|
|
End Sub
|
|
|
|
' ------=< MAIN >=------
|
|
' max for w is about max screensize - 500
|
|
Dim As ULong w = 800, h = w * 11 \ 16
|
|
Dim As ULong w2 = w \ 2, diff = w \ 12
|
|
|
|
ScreenRes w, h, 8
|
|
pythagoras_tree(w2 - diff, h -10 , w2 + diff , h -10 , 0)
|
|
' BSave "pythagoras_tree.bmp",0
|
|
|
|
|
|
|
|
' empty keyboard buffer
|
|
While Inkey <> "" : Wend
|
|
Print : Print "hit any key to end program"
|
|
Sleep
|
|
End
|