//tourne_gauche;arbre3(60,4) arbre3(h,p):={ si (h<5) alors avance(h); recule(h); sinon avance(h); tourne_droite(90*(p-1)/p); repete(p,arbre3(h/2,p),tourne_gauche(180/p)); tourne_droite(90*(p+1)/p); recule(h); fsi }Ou bien, on rajoute un paramètre n (la profondeur) pour faire le test d'arrêt, on tape :
//tourne_gauche;arbre4(60,5,3) arbre4(h,p,n):={ si (n==0) alors avance(h); recule(h); sinon avance(h); tourne_droite(90*(p-1)/p); repete(p,arbre4(h/2,p,n-1),tourne_gauche(180/p)); tourne_droite(90*(p+1)/p); recule(h); fsi }Et maintenant, un arbre aléatoire :
//tourne_gauche ;saute(-80);arbre5(60,4,3); arbre5(h,p,n):={ local k; si (n==0) alors avance(h); recule(h); sinon avance(h); tourne_droite(90*(p-1)/p); k:=rand(0,1); repete(p,arbre5(h*k,p,n-1),tourne_gauche(180/p)); tourne_droite(90*(p+1)/p); recule(h); fsi; }
efface(); tourne_gauche ; saute(-80); arbre5(60,4,3);
Et enfin, un arbre encore plus aléatoire :
pour chaque branche on choisit, de façon aléatoire le rapport
rand(0,1) de réduction, qui fera cette branche comme un arbre réduit
avec ce coefficient.
On tape
//tourne_gauche ;saute(-80);arbre6(60,4,3); arbre6(h,p,n):={ si (n==0) alors avance(h); recule(h); sinon avance(h); tourne_droite(90*(p-1)/p); repete(p,arbre6(h*rand(0,1),p,n-1),tourne_gauche(180/p)); tourne_droite(90*(p+1)/p); recule(h); fsi; }
efface(); tourne_gauche ; saute(-80); arbre6(60,4,3);