Fractals with Asymptote – fig0010

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

Figure 0001
(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);
  add(pic,ta*branch);
  add(pic,tb*branch);
  return pic;
}

add(Pythagorean(12));

Étiquettes : , , , ,


Fractals with Asymptote – fig0020

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

Figure 0002
(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

Figure 0003
(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);
  add(opic,branch);
  add(opic,ta*branch);
  add(opic,tb*branch);
  add(opic,tc*branch);
  return opic;
}

add(fern(6));

Étiquettes : , , , ,


Fractals with Asymptote – fig0040

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

Figure 0004
(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;
  add(pict,ta*pic);
  add(pict,tb*pic);
  add(pict,tc*pic);
  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;
add(pict,ta*pic);
add(pict,tb*pic);

pair x=(0,1);
nbit=23;
for(int i=1; i<=nbit; ++i) {
  add(shift(x)*rotate(ac*i)*scale(rc^i)*pict);
  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

Figure 0005
(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

Figure 0006
(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

Figure 0007
(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

Figure 0008
(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;
}

add(reflect((0,0),(1,0))*currentpicture);

Étiquettes : , ,


Fractals with Asymptote – fig0090

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

Figure 0009
(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;
}

add(Hfractal(4, bp+0.5*red));

Étiquettes : , , , ,


Fractals with Asymptote – fig0100

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

Figure 0010
(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 : , , , ,


  • Page 1 of 2
  • 1
  • 2
  • >