Retour

Source : dragon03.mp

dragon03.mp
input tortue.mp; 
numeric d,iter; 
color couleur; 
 
vardef trace(expr a,b) = 
 draw a--b 
 withpen pencircle scaled 2pt 
 withcolor (.6,.1,.3) 
enddef; 
 
vardef D(expr n,m) = 
save couleur; 
color couleur; 
couleur := blue; 
if m>0: 
 tourne(n,-45); 
 D(n,m-1); 
 tourne(n,90); 
 E(n,m-1); 
else: 
 tourne(n,-90); 
 avance(n,d,trace); 
 tourne(n,90); 
 fill (fullcircle scaled 6mm) shifted tortue_xy[n] withcolor (.9,.9,0); 
 avance(n,d,trace); 
fi 
enddef; 
 
vardef E(expr n,m) = 
save couleur; 
color couleur; 
couleur := red+green; 
if m>0: 
 D(n,m-1); 
 tourne(n,-90); 
 E(n,m-1); 
 tourne(n,45); 
else: 
 avance(n,d,trace); 
 fill (fullcircle scaled 7mm) shifted tortue_xy[n] withcolor (.4,.9,.2); 
 tourne(n,-90); 
 avance(n,d,trace); 
 tourne(n,90); 
fi 
enddef;  
dragon03.mp (figure 1)
beginfig(1);
iter := 9; 
d := .45cm; 
tortue(1,0,0,0,1); 
D(1,iter);  
endfig;
end