RosettaCodeData/Task/Pythagoras-tree/Maple/pythagoras-tree.maple

24 lines
833 B
Plaintext

pythtree := proc(ax, ay, bx, By, P, colors, depth)
local dx, dy, x3, y3, x4, y4, x5, y5;
if depth <= 0 then return; end if;
dx:=bx-ax; dy:=ay-By;
x3:=bx-dy; y3:=By-dx;
x4:=ax-dy; y4:=ay-dx;
x5:=x4+(dx-dy)/2; y5:=y4-(dx+dy)/2;
P ,= plots:-polygonplot([ax,bx,x3,x4,ax],-[ay,By,y3,y4,ay],color=colors[depth]);
P ,= plots:-polygonplot([x4,x5,x3],-[y4,y5,y3],color=colors[depth]);
pythtree(x4, y4, x5, y5, P, colors, depth - 1);
pythtree(x5, y5, x3, y3, P, colors, depth - 1);
end proc:
pythagorastree := proc(x1, y1, x2, y2, size, maxdep)
local P := Array(1..0);
local colors := ColorTools:-Gradient("Green".."yellow",number=maxdep):
pythtree(x1, y1, x2, y2, P, colors, maxdep);
plots:-display(convert(P,list),axes=none);
end proc:
pythagorastree(275.,500.,375.,500.,640., 9);