RosettaCodeData/Task/Fractal-tree/PARI-GP/fractal-tree.pari
2016-12-05 22:15:40 +01:00

33 lines
771 B
Text

\\ Fractal tree (w/recursion)
\\ 4/10/16 aev
plotline(x1,y1,x2,y2)={plotmove(0, x1,y1);plotrline(0,x2-x1,y2-y1);}
plottree(x,y,a,d)={
my(x2,y2,d2r=Pi/180.0,a1=a*d2r,d1);
if(d<=0, return(););
if(d>0, d1=d*10.0;
x2=x+cos(a1)*d1;
y2=y+sin(a1)*d1;
plotline(x,y,x2,y2);
plottree(x2,y2,a-20,d-1);
plottree(x2,y2,a+20,d-1),
return();
);
}
FractalTree(depth,size)={
my(dx=1,dy=0,ttlb="Fractal Tree, depth ",ttl=Str(ttlb,depth));
print1(" *** ",ttl); print(", size ",size);
plotinit(0);
plotcolor(0,6); \\green
plotscale(0, -size,size, 0,size);
plotmove(0, 0,0);
plottree(0,0,90,depth);
plotdraw([0,size,size]);
}
{\\ Executing:
FractalTree(9,500); \\FracTree1.png
FractalTree(12,1100); \\FracTree2.png
FractalTree(15,1500); \\FracTree3.png
}