RosettaCodeData/Task/Pythagoras-tree/XPL0/pythagoras-tree.xpl0
2023-07-01 13:44:08 -04:00

21 lines
596 B
Text

proc DrawTree(X1, Y1, X2, Y2, Depth);
int X1, Y1, X2, Y2, Depth;
int X3, Y3, X4, Y4, X5, Y5, DX, DY, Color;
[if Depth < 7 then
[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;
Color:= $2A + Depth;
Move(X1, Y1);
Line(X2, Y2, Color); Line(X3, Y3, Color);
Line(X4, Y4, Color); Line(X1, Y1, Color);
DrawTree(X4, Y4, X5, Y5, Depth+1);
DrawTree(X5, Y5, X3, Y3, Depth+1);
];
];
def ScrW=320, ScrH=200;
[SetVid($13);
DrawTree(9*ScrW/20, 3*ScrH/4, 11*ScrW/20, 3*ScrH/4, 0);
]