## Fractals with Asymptote – fig0010

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 21 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
// From documentation of Asymptote
size(250);

real a=3;
real b=4;
real c=hypot(a,b);

transform ta=shift(c,c)*rotate(-aCos(a/c))*scale(a/c)*shift(-c);
transform tb=shift(0,c)*rotate(aCos(b/c))*scale(b/c);

picture Pythagorean(int n) {
picture pic;
fill(pic,scale(c)*unitsquare,1/(n+1)*green+n/(n+1)*brown);
if(n == 0) return pic;
picture branch=Pythagorean(--n);
return pic;
}

```

Étiquettes : , , , ,

## Fractals with Asymptote – fig0020

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 22 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
size(10cm,0);

transform scale(pair center, real k) {
return shift(center)*scale(k)*shift(-center);
}

path trk=(0,0)--(0,1);

void tree(path p, int n, real a=30, real b=40, real r=.75) {
if (n!=0) {
pair h=point(p,length(p));
transform tb=rotate(180-b,h)*scale(h,r);
transform ta=rotate(-180+a,h)*scale(h,r);
draw(p,n/3+1/(n+1)*green+n/(n+1)*brown);
tree(tb*reverse(p),n-1,a,b,r);
tree(ta*reverse(p),n-1,a,b,r);
}
}

tree(trk,12,a=25,b=40,r=.75);

```

Étiquettes : , , ,

## Fractals with Asymptote – fig0030

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 23 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
// Barnsley's fern
// Fougère de Barnsley
size(5cm,0);

real ab=85, ac=-5;
real rc=.85, rb=-.31;
path trk=(0,0)--(0,1);

transform ta=shift(0,1)*rotate(ab)*scale(rb);
transform tb=shift(0,1)*rotate(-ab)*scale(rb);
transform tc=shift(0,1)*rotate(ac)*scale(rc);

picture fern(int n) {
picture opic;
draw(opic,trk^^ta*trk^^tb*trk^^tc*trk);
if (n==0) return opic;
picture branch=fern(n-1);
return opic;
}

```

Étiquettes : , , , ,

## Fractals with Asymptote – fig0040

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 0 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
// Barnsley's fern
// Fougère de Barnsley
size(10cm,0);

real ab=72, ac=-7;
real rc=0.85, rb=0.35;
path trk=(0,0)--(0,1);

transform ta=shift(0,1)*rotate(ab)*scale(rb);
transform tb=shift(0,1)*rotate(-ab)*scale(rb);
transform tc=shift(0,1)*rotate(ac)*scale(rc);
transform td=shift(0,1)*rotate((ab+ac)/2)*scale(rb);
transform te=shift(0,1)*rotate(-(ab+ac)/2)*scale(rb);

picture pic;
draw(pic,trk,red+.8green);

//Construct a fern branch as atractor
int nbit=7;
for(int i=1; i<=nbit; ++i) {
picture pict;
draw(pict,(0,0)--(0,1), (2*(i/nbit)^2)*bp+((1-i/nbit)*green+i/nbit*brown));
pic=pict;
}

//Use the fern branch to construct... a fern branch
picture pict;

pair x=(0,1);
nbit=23;
for(int i=1; i<=nbit; ++i) {
draw(tc^i*((0,0)--(0,1)), 2*(1.5-i/nbit)^2*bp+brown);
x=tc*x;
}

shipout(bbox(3mm, 2mm+black, FillDraw(paleyellow)));

```

Étiquettes : , ,

## Fractals with Asymptote – fig0050

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 1 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
// Barnsley's fern
// Fougère de Barnsley
size(5cm,0);

real ab=85, ac=-5;
real rc=0.8, rb=0.3;
path trk=(0,0)--(0,1);

transform [] t;
t[1] =shift(0,1)*rotate(ab)*scale(rb);
t[2] =shift(0,1)*rotate(-ab)*scale(rb);
t[3] =shift(0,1)*rotate(ac)*scale(rc);
real sum=0;

for(int i=0; i<100; ++i) sum+=(rc*cos(ac*pi/180))^i;
t[4] =xscale(0.01)*yscale(1/sum);

picture pic;
draw(pic,trk);
pair pt=(0,0);

for(int i=0; i < 1000; ++i) {
pt=t[ 1+floor((3.0*rand()/randMax)) ]*pt;
}

int nbt;
for(int i=0; i < 200000; ++i) {
nbt=1+floor((4.0*rand()/randMax));
pt=t[nbt]*pt;
draw(pt);
}

```

Étiquettes : , ,

## Fractals with Asymptote – fig0060

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 2 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
//From documentation of Asymptote
size(10cm);

// Draw Sierpinski triangle with top vertex A, side s, and depth q.
void Sierpinski(pair A, real s, int q,
bool top=true, bool randcolor=false) {
pair B=A-(1,sqrt(2))*s/2;
pair C=B+s;
if(top) draw(A--B--C--cycle);
if (randcolor) {
filldraw((A+B)/2--(B+C)/2--(A+C)/2--cycle,
(.33*rand()/randMax*red+.33*rand()/randMax*green+.33*rand()/randMax*blue));
} else draw((A+B)/2--(B+C)/2--(A+C)/2--cycle);
if(q > 0) {
Sierpinski(A,s/2,q-1,false,randcolor);
Sierpinski((A+B)/2,s/2,q-1,false,randcolor);
Sierpinski((A+C)/2,s/2,q-1,false,randcolor);
}
}

Sierpinski((0,1), 1, 5, randcolor=true);

```

Étiquettes : , , ,

## Fractals with Asymptote – fig0070

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 3 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
//Translate from http://zoonek.free.fr/LaTeX/Metapost/metapost.html
size(8cm);
void koch(pair A, pair B, int n) {
pair C;
C =rotate(120, point(A--B,1/3))*A;
if (n>0) {
koch( A,        point(A--B,1/3), n-1);
koch( point(A--B,1/3), C,        n-1);
koch( C,        point(A--B,2/3), n-1);
koch( point(A--B,2/3), B,        n-1);
} else draw(A--point(A--B,1/3)--C--point(A--B,2/3)--B);
}

pair z0=(1,0);
pair z1=rotate(120)*z0;
pair z2=rotate(120)*z1;
koch( z0, z1, 3 );
koch( z1, z2, 3 );
koch( z2, z0, 3 );

```

Étiquettes : ,

## Fractals with Asymptote – fig0080

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 4 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
size(10cm,0);

real mandelbrot(pair c, real r, int count=100) {
int i=0;
pair z=c;
do {
++i;
z=z^2+c;
} while (length(z) <= r && i<count);

return (i<count) ? i/count : 0;
}

real r=4;
real step=.01;
real xmin=-2.25, xmax=.75;
real ymin=-1.3, ymax=0;

real x=xmin, y=ymin;
int xloop=round((xmax-xmin)/step);
int yloop=round((ymax-ymin)/step);
pen p;
path sq=scale(step)*unitsquare;

for(int i=0; i < xloop; ++i) {
for(int j=0; j < yloop; ++j) {
p=mandelbrot((x,y),r,20)*red;
filldraw(shift(x,y)*sq,p,p);
y += step;
}
x += step;
y=ymin;
}

```

Étiquettes : , ,

## Fractals with Asymptote – fig0090

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 5 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
size(10cm,0);

real a=-1.5, b=2a/3;

picture H(pen p=currentpen) {
picture H;
draw(H,(-a,0)--(a,0)^^(-a,-b)--(-a,b)^^(a,-b)--(a,b),p);
return H;
}

transform sc=scale(0.5);
transform[] t={identity(),
shift(-a,b)*sc, shift(-a,-b)*sc,
shift(a,b)*sc,  shift(a,-b)*sc};

picture Hfractal(int n, pen p=currentpen)
{
picture pic;
if(n == 0) return H(p);
picture Ht=Hfractal(n-1,p);
for (int i=0; i < 5; ++i) add(pic,t[i]*Ht);
return pic;
}

```

Étiquettes : , , , ,

## Fractals with Asymptote – fig0100

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 6 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
size(10cm,0);

real a=-1.5, b=2a/3;

path[] H=(-a,0)--(a,0)^^(-a,-b)--(-a,b)^^(a,-b)--(a,b);

transform sc=scale(0.5);
transform[] t={shift(-a,b)*sc, shift(-a,-b)*sc,
shift(a,b)*sc,  shift(a,-b)*sc};

void Hfractal(path[] g, int n, pen[] p=new pen[]{currentpen})
{
p.cyclic=true;
if(n == 0) draw(H,p[0]); else {
for (int i=0; i < 4; ++i) {
draw(t[i]*g,p[n]);
Hfractal(t[i]*g,n-1,p);
}
}
}

Hfractal(H, 5, new pen[] {0.8*red, 0.8*green, 0.8*blue, black, blue+red});

```

Étiquettes : , , , ,

## Fractals with Asymptote – fig0110

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 7 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
/* Explanations HERE */
import geometry;
size(10cm,0);

triangle[] dissect(triangle T, int n)
{
if(n <= 0) return new triangle[]{T};
triangle[] OT;
point M=midpoint(T.BC);
triangle[] Tp=dissect(triangle(M,T.A,T.B),n-1);
for(triangle t : Tp) OT.insert(0,t);
triangle[] Tp=dissect(triangle(M,T.C,T.A),n-1);
for(triangle t : Tp) OT.insert(0,t);
return OT;
}

triangle T=rotate(45)*triangle((1,1),(0,0),(2,0));
triangle[] DT=dissect(T,9);
path g;
transform R=reflect(T.BC);

for(int i : DT.keys) {
draw(DT[i],miterjoin+0.9*red);
draw(R*DT[i],miterjoin+0.9*red);
g=g--centroid(DT[i]);
}

draw(scale(sqrt(2))*unitsquare,bp+miterjoin+0.8*blue);
draw(g--reverse(R*g)--cycle,bp+miterjoin+yellow);

shipout(bbox(sqrt(2)*mm, Fill(black)));

```

Étiquettes : , , , , ,

## Fractals with Asymptote – fig0120

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 8 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
/* Explanations HERE */
size(12cm,0);

import geometry;

triangle T=triangleAbc(90,Tan(30),1);

triangle[] reverse(triangle[] arr)
{
triangle[] or;
int l=arr.length;
for(int i=0; i < l; ++i) {
or.push(arr[l-i-1]);
}
return or;
}

triangle[] dissect(triangle T, int n, bool reverse=false)
{
if(n <= 0) return new triangle[]{T};
triangle[] OT;

point M=curpoint(T.AB,T.b()*Tan(30));
point H=projection(T.BC)*M;
triangle[] OT1, OT2, OT3;
OT.append(dissect(triangle(H,T.B,M),n-1,!reverse));
OT.append(reverse((dissect(triangle(H,T.C,M),n-1,!reverse))));
OT.append(dissect(triangle(T.A,T.C,M),n-1,!reverse));
return OT;
}

triangle[] DT=dissect(T,5);
point O=centroid(DT[0]);
path g;
transform Ro=rotate(30,T.B), Re=reflect(T.BC), Roj;

for(int i : DT.keys) {
O=incenter(DT[i]);
g=g--O;
}

g=reverse(g);
path G, g=g--Re*reverse(g) ;
for (int j=0; j < 12; j += 2) G=G--Ro^(-j)*g;

fill(G--cycle,0.3*blue);

for(int i : DT.keys) {
for (int j=0; j < 12; j += 2) {
Roj=Ro^j;
draw(Roj*DT[i],miterjoin+0.8*red);
draw(Roj*(Re*DT[i]),miterjoin+0.8*red);
}
}

draw(G--cycle,bp+miterjoin+0.9*yellow);

shipout(bbox(2mm, FillDraw(black, 1mm+miterjoin+deepblue)));

```

Étiquettes : , , , , ,

## L-System with Asymptote – fig0010

Category: Asymptote,L-SystemPh. Ivaldi @ 19 h 40 min

 (Compiled with Asymptote version 1.86svn-r4626)
```
import Lsystem;
size(10cm);

string[][] rules={{"F","FF"}, {"X","--FXF++FXF++FXF--"}};
Lsystem Sierpinski=Lsystem("FXF--FF--FF", rules, La=60, Lai=0);
Sierpinski.iterate(5);
draw(Sierpinski.paths(), bp+0.2*green);

shipout(bbox(Fill(paleyellow)));

```

Étiquettes : ,

## L-System with Asymptote – fig0020

Category: Asymptote,L-SystemPh. Ivaldi @ 20 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
import Lsystem;
size(10cm,0);

Lsystem SierpinskiCurve=
Lsystem("YF",
new string[][]{{"X","YF+XF+Y"},{"Y","XF-YF-X"}},
La=60, Lai=0);
SierpinskiCurve.iterate(7);
draw(SierpinskiCurve.paths(), bp+0.2*green);

shipout(bbox(Fill(paleyellow)));

```

Étiquettes : ,

## L-System with Asymptote – fig0030

Category: Asymptote,L-SystemPh. Ivaldi @ 21 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/* Source */
import Lsystem;
size(10cm,0);

Lsystem SierpinskiCarpet=
Lsystem("F+F+F+F",
new string[][]{{"F","FF+F+F+F+FF"}},
La=90, Lai=0);
SierpinskiCarpet.iterate(4);
draw(SierpinskiCarpet.paths(), bp+0.2*green);

shipout(bbox(Fill(paleyellow)));

```

Étiquettes : ,

## L-System with Asymptote – fig0040

Category: Asymptote,L-SystemPh. Ivaldi @ 22 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*Source*/
import Lsystem;

size(8cm,0);
Lsystem Koch=Lsystem("+F--F--F",
new string[][]{{"F","F+F--F+F"}},
La=60, Lai=0);
Koch.iterate(4);
filldraw(Koch.paths()[0]&cycle, paleyellow, 1bp+black);
shipout(bbox(2mm, Fill(lightyellow)));

```

Étiquettes : ,

## L-System with Asymptote – fig0050

Category: Asymptote,L-SystemPh. Ivaldi @ 23 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*Source*/
import Lsystem;

size(8cm,0);
Lsystem Koch=Lsystem("+F+F+F+F+F",
new string[][]{{"F","F-F++F-F"}},
La=72);
Koch.iterate(4);
filldraw(Koch.paths()[0]&cycle, paleyellow, 1bp+black);
shipout(bbox(2mm, Fill(lightyellow)));

```

Étiquettes : ,

## L-System with Asymptote – fig0060

Category: Asymptote,L-SystemPh. Ivaldi @ 0 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*Source*/
import Lsystem;

size(8cm,0);
Lsystem Koch=Lsystem("-F--F--F",
new string[][]{{"F","F-F++F-F"}},
La=60);
Koch.iterate(4);
filldraw(Koch.paths()[0]&cycle, paleyellow, 1bp+black);
shipout(bbox(2mm, Fill(lightyellow)));

```

Étiquettes : ,

## L-System with Asymptote – fig0070

Category: Asymptote,L-SystemPh. Ivaldi @ 1 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
import Lsystem;
size(10cm,0);

string[][] rules={{"F","F-F+F+FFF-F-F+F"}};
shipout(bbox(3mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0080

Category: Asymptote,L-SystemPh. Ivaldi @ 2 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*Source*/
import Lsystem;
size(8cm,0);

Lsystem HilbertCurve=Lsystem("X",
new string[][]{{"X","-YF+XFX+FY-"},{"Y","+XF-YFY-FX+"}},
La=90, Lai=0);
HilbertCurve.iterate(6);
draw(HilbertCurve.paths(), linewidth(1bp));

shipout(bbox(Fill(lightgrey)));

```

Étiquettes : ,

## L-System with Asymptote – fig0090

Category: Asymptote,L-SystemPh. Ivaldi @ 3 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*Source*/
import Lsystem;
size(8cm,0);

Lsystem Fass=Lsystem("-L",
new string[][]{{"L","LFLF+RFR+FLFL-FRF-LFL-FR+F+RF-LFL-FRFRFR+"},
{"R","-LFLFLF+RFR+FL-F-LF+RFR+FLF+RFRF-LFL-FRFR"}},
La=90);
Fass.iterate(3);
draw(Fass.paths(), linewidth(1bp));

shipout(bbox(Fill(lightgrey)));

```

Étiquettes : ,

## L-System with Asymptote – fig0100

Category: Asymptote,L-SystemPh. Ivaldi @ 4 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*An animation of the 3D Hilbert curve may be found HERE*/
import Lsystem;
size(10cm,0);
currentprojection=currentprojection=orthographic((10,5,6));

string[][] rules={{"X","^<XF^<XFX-F^>>XFX&F+>>XFX-F>X->"}};
Lsystem3 HilbertCurve3D=Lsystem3("X", rules, La=90);
HilbertCurve3D.iterate(3);

// !! Use a lot of memory !!
/* path3[] g=HilbertCurve3D.paths3();
draw(g[0], linewidth(bp)+0.9*yellow);
*/

HilbertCurve3D.drawpaths3(linewidth(bp)+0.9*yellow);

shipout(bbox(3mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0110

Category: Asymptote,L-SystemPh. Ivaldi @ 5 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*Source*/
import Lsystem;
size(8cm,0);

string[][] rules={{"F","FF"},
{"H","+F+FH++FFH++F+FF+FH++FFH++F+F-"}};

Lsystem H=Lsystem("+H",rules, La=90);
H.iterate(5);
draw(H.paths(), white);

shipout(bbox(3mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0120

Category: Asymptote,L-SystemPh. Ivaldi @ 6 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*Source*/
import Lsystem;
size(10cm,0);

string[][] rules=new string[][]{{"F",""},{"X","-FX++FY-"},{"Y","+FX--FY+"}};
Lsystem dragon=Lsystem("X",rules, La=45, Lai=0);
dragon.iterate(12);
draw(dragon.paths(), white);

shipout(bbox(3mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0130

Category: Asymptote,L-SystemPh. Ivaldi @ 7 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
import Lsystem;
size(12cm,0);

string[][] rules={{"F","-F+F-F-F+F+FF-F+F+FF+F-F-FF+FF-FF+F+F-FF-F-F+FF-F-F+F+F-F+"}};
Lsystem segment32Curve= Lsystem("F+F+F+F", rules, La=90, Lai=45);
segment32Curve.iterate(2);
filldraw(segment32Curve.paths()[0]&cycle, 0.8*yellow, blue);
shipout(bbox(3mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0140

Category: Asymptote,L-SystemPh. Ivaldi @ 8 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
// Peano Gosper curve
import Lsystem;
size(8cm,0);

Lsystem PeanoGosperCurve=
Lsystem("FX",
new string[][]{{"X","X+YF++YF-FX--FXFX-YF+"},{"Y","-FX+YFYF++YF+FX--FX-Y"}},
La=60, Lai=0);
PeanoGosperCurve.iterate(4);
draw(PeanoGosperCurve.paths(), bp+0.9*yellow);

shipout(bbox(3mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0150

Category: Asymptote,L-SystemPh. Ivaldi @ 9 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
import Lsystem;
size(8cm,0);

string[][] rules={{"X","XF-F+F-XF+F+XF-F+F-X"}};
Lsystem squareCurve= Lsystem("F+XF+F+XF", rules, La=90, Lai=45);
squareCurve.iterate(5);
filldraw(squareCurve.paths()[0]&cycle, grey, 1bp+0.9*yellow);
shipout(bbox(3mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0160

Category: Asymptote,L-SystemPh. Ivaldi @ 10 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
import Lsystem;
size(8cm,0);

string[][] rules={{"L","+R-F-R+"}, {"R","-L+F+L-"}};
Lsystem squareCurve= Lsystem("L--F--L--F", rules, La=45, Lai=45);
squareCurve.iterate(9);
filldraw(squareCurve.paths()[0]&cycle, grey, 1bp+0.9*yellow);

shipout(bbox(3mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0170

Category: Asymptote,L-SystemPh. Ivaldi @ 11 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/* Source */
import Lsystem;
size(8cm,0);

string[][] rules={
{"F", "F+f-FF+F+FF+Ff+FF-f+FF-F-FF-Ff-FFF"},
{"f", "ffffff"}
};

Lsystem oer=Lsystem("F+F+F+F",rules,La=91);

oer.iterate(2);
draw(oer.paths(), bp+0.8*yellow);
shipout(bbox(2mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0180

Category: Asymptote,L-SystemPh. Ivaldi @ 12 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
import Lsystem;
size(10cm,0);

string[][] rules={
{"F", ""},
{"P", "--FR++++FS--FU"},
{"Q", "FT++FR----FS++"},
{"R", "++FP----FQ++FT"},
{"S", "FU--FP++++FQ--"},
{"T", "+FU--FP+"},
{"U", "-FQ++FT-"}
};

Lsystem pentive=Lsystem("Q", rules, La=36, Lai=180);

pentive.iterate(8);
draw(pentive.paths(), 0.8*yellow);
shipout(bbox(2mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0190

Category: Asymptote,L-SystemPh. Ivaldi @ 13 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/* Source */
import Lsystem;
size(8cm,0);

string[][] rules={
{"A", "X+X+X+X+X+X+"},
{"X", "[F+F+F+F[---X-Y]+++++F++++++++F-F-F-F]"},
{"Y", "[F+F+F+F[---Y]+++++F++++++++F-F-F-F]"}
};

Lsystem spiral=Lsystem("AAAA",rules,La=15);

spiral.iterate(6);
draw(spiral.paths(), 0.9*green);

shipout(bbox(2mm, Fill(black)));

```

Étiquettes : ,

## L-System with Asymptote – fig0230

Category: Asymptote,L-SystemPh. Ivaldi @ 17 h 40 min

 (Compiled with Asymptote version 1.86svn-r4626)
```
/*Inspirtaion*/
import Lsystem;
size(10cm,10cm);
settings.outformat="pdf"; // for opacity

string[][] rules=new string[][]{{"F", "FF-[-F+F+F]+[+F-F-F]"}};
Lsystem plant=Lsystem("F", rules, La=22.5, Lai=90);
plant.iterate(5);
path[] g=plant.paths();

tree g=plant.tree();

for (int i:g.keys) {
if((g[i].depth == 0)) draw(g[i].g, yellow);
}

for (int i:g.keys) {
if((g[i].depth > 0 )) draw(g[i].g, green+opacity(0.5));
}

for (int i:g.keys) {
if((g[i].depth > 15)) draw(g[i].g, brown+opacity(0.3));
}

shipout(bbox(Fill(paleyellow)));

```

Étiquettes : ,

## L-System with Asymptote – fig0240

Category: Asymptote,L-SystemPh. Ivaldi @ 18 h 40 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
/*Inspirtaion*/
import Lsystem;
size(10cm,10cm);
settings.outformat="pdf"; // for opacity

string[][] rules=new string[][]{{"F", "FF"},{"X", "F-[[X]+X]+F[+FX]-X"}};
Lsystem plant=Lsystem("X", rules, La=22.5, Lai=90);
plant.iterate(8);
path[] g=plant.paths();

tree g=plant.tree();

for (int i:g.keys) {
if((g[i].depth <= 2 )) draw(g[i].g, yellow);
}

for (int i:g.keys) {
if((g[i].depth > 2 ) && (g[i].depth <= 10 )) draw(g[i].g, green+opacity(0.5));
}

for (int i:g.keys) {
if((g[i].depth > 11)) draw(g[i].g, brown+opacity(0.3));
}

shipout(bbox(Fill(paleyellow)));

```

Étiquettes : ,

## Official Asymptote example – PythagoreanTree

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 22 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
```/* This code comes from The Official Asymptote Gallery */

size(250);

real a=3;
real b=4;
real c=hypot(a,b);

transform ta=shift(c,c)*rotate(-aCos(a/c))*scale(a/c)*shift(-c);
transform tb=shift(0,c)*rotate(aCos(b/c))*scale(b/c);

picture Pythagorean(int n) {
picture pic;
fill(pic,scale(c)*unitsquare,1/(n+1)*green+n/(n+1)*brown);
if(n == 0) return pic;
picture branch=Pythagorean(--n);
return pic;
}

```

Étiquettes :

## Official Asymptote example – Sierpinski

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 1 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
```/* This code comes from The Official Asymptote Gallery */

size(10cm);

// Draw Sierpinski triangle with top vertex A, side s, and depth q.
void Sierpinski(pair A, real s, int q, bool top=true)
{
pair B=A-(1,sqrt(2))*s/2;
pair C=B+s;
if(top) draw(A--B--C--cycle);
draw((A+B)/2--(B+C)/2--(A+C)/2--cycle);
if(q > 0) {
Sierpinski(A,s/2,q-1,false);
Sierpinski((A+B)/2,s/2,q-1,false);
Sierpinski((A+C)/2,s/2,q-1,false);
}
}

Sierpinski((0,1),1,5);

```

Étiquettes :

## Official Asymptote example – dragon

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 14 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
```/* This code comes from The Official Asymptote Gallery */

pair crease(pair z1, pair z2, bool left)
{
pair dz = z2 - z1;

if (left)
return z1 + dz * (0.5, 0.5);
else
return z1 + dz * (0.5, -0.5);
}

pair[] fold(pair[] oldz)
{
int n = oldz.length;
pair[] newz = new pair[2n-1];

for (int i = 0; i < n-1; ++i)
{
newz[2i] = oldz[i];
newz[2i+1] = crease(oldz[i], oldz[i+1], i%2==0);
}

newz[2(n-1)] = oldz[n-1];

return newz;
}

pair[] dragon(int n, pair[] base={})
{
if (base.length == 0)
if (n%2 == 0)
base = new pair[] {(0,0), (1,1) };
else
base = new pair[] {(0,0), (1,0) };

pair[] z = base;

for (int i = 1; i < n; ++i)
z = fold(z);

return z;
}

void drawtris(pair[] z, pen p = currentpen)
{
int n = z.length;

for (int i = 0; i < n-2; i+=2)
fill(z[i]--z[i+1]--z[i+2]--cycle, p);
}

void drawtris(pair[] z, pen p1, pen p2)
{
int n = z.length;

for (int i = 0; i < n-2; i+=2)
fill(z[i]--z[i+1]--z[i+2]--cycle, 2i < n-1 ? p1 : p2);
}

size(500,0);

int n = 10;

drawtris(dragon(n, new pair[] {(0,0), (1,0)}), black);
drawtris(dragon(n, new pair[] {(0,0), (0,-1)}), blue);
drawtris(dragon(n, new pair[] {(0,0), (-1,0)}), red);
drawtris(dragon(n, new pair[] {(0,0), (0,1)}),  green);

```

Étiquettes : ,

## Official Asymptote example – fractaltree

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 12 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
```/* This code comes from The Official Asymptote Gallery */

size(200);

path ltrans(path p,int d)
{
path a=rotate(65)*scale(0.4)*p;
return shift(point(p,(1/d)*length(p))-point(a,0))*a;
}
path rtrans(path p, int d)
{
path a=reflect(point(p,0),point(p,length(p)))*rotate(65)*scale(0.35)*p;
return shift(point(p,(1/d)*length(p))-point(a,0))*a;
}

void drawtree(int depth, path branch)
{
if(depth == 0) return;
real breakp=(1/depth)*length(branch);
draw(subpath(branch,0,breakp),deepgreen);
drawtree(depth-1,subpath(branch,breakp,length(branch)));
drawtree(depth-1,ltrans(branch,depth));
drawtree(depth-1,rtrans(branch,depth));
return;
}

path start=(0,0)..controls (-1/10,1/3) and (-1/20,2/3)..(1/20,1);
drawtree(6,start);

```

Étiquettes : ,