32 lines
761 B
Plaintext
32 lines
761 B
Plaintext
Sub pythagoras_tree(x1, y1, x2, y2, depth)
|
|
local dx, dy, x3, y3, x4, y4, x5, y5
|
|
|
|
If depth > limit Return
|
|
|
|
dx = x2 - x1 : dy = y1 - y2
|
|
x3 = x2 - dy : y3 = y2 - dx
|
|
x4 = x1 - dy : y4 = y1 - dx
|
|
x5 = x4 + (dx - dy) / 2
|
|
y5 = y4 - (dx + dy) / 2
|
|
//draw the box
|
|
color 255 - depth * 20, 255, 0
|
|
fill triangle x1, y1, x2, y2, x3, y3
|
|
fill triangle x3, y3, x4, y4, x1, y1
|
|
fill triangle x4, y4, x5, y5, x3, y3
|
|
|
|
pythagoras_tree(x4, y4, x5, y5, depth +1)
|
|
pythagoras_tree(x5, y5, x3, y3, depth +1)
|
|
|
|
End Sub
|
|
|
|
// ------=< MAIN >=------
|
|
w = 800 : h = int(w * 11 / 16)
|
|
w2 = int(w / 2) : diff = int(w / 12)
|
|
limit = 12
|
|
|
|
open window w, h
|
|
//backcolor 0, 0, 0
|
|
clear window
|
|
|
|
pythagoras_tree(w2 - diff, h -10 , w2 + diff , h -10 , 1)
|