RosettaCodeData/Task/Pythagoras-tree/M2000-Interpreter/pythagoras-tree-1.m2000
2026-02-01 16:33:20 -08:00

29 lines
813 B
Text

MODULE Pythagoras_tree {
CLS 5, 0 ' MAGENTA, NO SPLIT SCREEN
PEN 14 ' YELLOW
\\ code from zkl/Free Basic
LET w = scale.x, h = w * 11 div 16
LET w2 = w div 2, diff = w div 12
LET TreeOrder = 6
pythagoras_tree(w2 - diff, h -10, w2 + diff, h -10, 0)
SUB pythagoras_tree(x1, y1, x2, y2, depth)
IF depth > TreeOrder THEN EXIT SUB
LOCAL dx = x2 - x1, dy = y1 - y2
LOCAL x3 = x2 - dy, y3 = y2 - dx
LOCAL x4 = x1 - dy, y4 = y1 - dx
LOCAL x5 = x4 + (dx - dy) / 2
LOCAL y5 = y4 - (dx + dy) / 2
MOVE x1, y1
DRAW TO x2, y2
DRAW TO x3, y3
DRAW TO x4, y4
DRAW TO x1, y1
pythagoras_tree(x4, y4, x5, y5, depth +1)
pythagoras_tree(x5, y5, x3, y3, depth +1)
END SUB
}
Pythagoras_tree