PIPRIME.FR BLOG

Live fully to honor life

Tag Loop/for/while -- Asymptote Gallery

đź”—fractales-fig008

Figure fractales 008 Generated with Asymptote

Show fractales/fig0080.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Fractals
Tags : #Fractals | #Loop/for/while | #Picture

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);

đź”—fractales-fig011

Figure fractales 011 Generated with Asymptote

Show fractales/fig0110.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Fractals
Tags : #Fractals | #Recursion | #Geometry | #Triangle | #Array | #Loop/for/while

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)));

đź”—fractales-fig012

Figure fractales 012 Generated with Asymptote

Show fractales/fig0120.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Fractals
Tags : #Fractals | #Recursion | #Geometry | #Triangle | #Array | #Loop/for/while

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)));

đź”—generalities-fig058

Figure generalities 058 Generated with Asymptote

Show generalities/fig0580.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Fill/Unfill | #Shading | #Arc | #Loop/for/while | #Transform/scale/shift/rotate

// Author: John Bowman
size(10cm,0);

real r=1;
real R=3.8;

int step=30;
path p=arc(0,r,0,step);
path P=arc(0,R,step,0);
for(int h=0; h < 360; h += step) {
  transform t=rotate(90-h);
  tensorshade(t*p--t*P--cycle,
              new pen[] {white,white,hsv(h-step,1,1),hsv(h,1,1)});
}

for(int h=0; h < 360; h += 30) {
  pair v=R*dir(90-h);
  draw(Label(string(h)+"$^\circ$",EndPoint),(v--1.05v));
}

draw(circle(0,r));
draw(circle(0,R));

đź”—generalities-fig102

Figure generalities 102 Generated with Asymptote

Show generalities/fig1020.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Loop/for/while | #Fill/Unfill | #Arc

size(6cm,0);

real a=360/6;
for (int i = -1; i < 5; ++i)
  fill(arc((0,0),1,i*a,(i+1)*a)--cycle,grey);

đź”—generalities-fig103

Figure generalities 103 Generated with Asymptote

Show generalities/fig1030.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Loop/for/while | #Fill/Unfill | #Arc

size(6cm,0);

real n=7, a=360/n;
for (int i = 0; i < n; ++i)
  filldraw((0,0)--arc((0,0),1,i*a,(i+1)*a)--cycle, i/n*blue + (1-i/n)*green + grey);

đź”—generalities-fig104

Figure generalities 104 Generated with Asymptote

Show generalities/fig1040.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Loop/for/while | #Fill/Unfill | #Arc | #Label | #Number format | #Align

size(6cm,0);

real a=360/6;
for (int i = -1; i < 5; ++i)
  draw(Label(format("%i",i+1)),arc((0,0),10,i*a,(i+1)*a)--cycle,grey);

đź”—generalities-fig136

Figure generalities 136 Generated with Asymptote

Show generalities/fig1370.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Path | #Circle | #Loop/for/while

size(0,0);

path cle=scale(4cm)*unitcircle;

draw(cle);

for(real i=0; i<=length(cle); i+=.2)
  draw(point(cle,i)--2cm*dir(cle,i)+point(cle,i),Arrow,p=i/length(cle)*red);

đź”—generalities-fig137

Figure generalities 137 Generated with Asymptote

Show generalities/fig1380.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Path | #Circle | #Loop/for/while

size(0,0);

path cle=scale(4cm)*reverse(unitcircle);

draw(cle);

for(real i=0; i<=length(cle); i+=.2)
  draw(point(cle,i)--2cm*dir(cle,i)+point(cle,i),Arrow,p=i/length(cle)*red);

đź”—generalities-fig139

Figure generalities 139 Generated with Asymptote

Show generalities/fig1400.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Path | #Circle | #Loop/for/while

size(0,0);

path cle=scale(4cm)*reverse(unitcircle);

draw(cle);

for(real i=0; i<=length(cle); i+=.2)
  draw(point(cle,i)--(1cm*I*dir(cle,i))+point(cle,i),Arrow,p=i/length(cle)*red);

đź”—generalities-fig141

Figure generalities 141 Generated with Asymptote

Show generalities/fig1420.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Path | #Loop/for/while

size(6cm,0);

path curv=reverse((0,2){dir(-60)}..(1,0)..{dir(60)}(2,2));

draw(curv);

for(real i=0; i<=length(curv); i+=.1)
  draw(point(curv,i)--dir(curv,i)+point(curv,i),grey);

đź”—generalities-fig142

Figure generalities 142 Generated with Asymptote

Show generalities/fig1430.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Path | #Loop/for/while

size(10cm,0);

path curv=reverse((0,2){dir(10)}..(1,0)..{dir(-50)}(3,2));
guide dirc;

draw(curv,linewidth(1mm)+grey);

for(real i=0; i<=length(curv); i+=.005)
  {
    draw(point(curv,i)--dir(curv,i)+point(curv,i),grey+yellow);
    dirc=dirc..dir(curv,i)+point(curv,i);
  }

draw(dirc,grey);

đź”—generalities-fig153

Figure generalities 153 Generated with Asymptote

Show generalities/fig1540.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Path | #Function creation | #Loop/for/while

size(10cm,0);

path unitpolygon(int n)
{
  guide opath;
  for (int i=1; i<=n; ++i)
    opath=opath--rotate((i-1)*360/n)*E;
  return opath--cycle;
}

for (int i=3; i<9; ++i)
  draw(shift(2.5*(i%3),-2.5*quotient(i,3))*unitpolygon(i));

đź”—generalities-fig154

Figure generalities 154 Generated with Asymptote

Show generalities/fig1550.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Array | #Path | #Loop/for/while | #Direction | #Label

size(0,0);

pair [] P, Q, R, S;
real u=1cm;

for (int i=0; i<=4; ++i)
  P[i] = rotate(i*360/5)*(0,-u);

P[5] = P[0];
for (int i=0; i<=4; ++i)
  Q[i] = 3*midpoint(P[i]--P[i+1]);

Q[5] = Q[0];
for (int i=0; i<=4; ++i)
  R[i] = 1/3*( Q[i] + Q[i+1] + P[i+1] );

R[5] = R[0];
for (int i=0; i<=5; ++i)
  S[i] = 1.5*Q[i];

for (int i=0; i<=4; ++i)
  {
    draw(P[i]   -- P[i+1]);
    draw(P[i+1] -- R[i]);
    draw(Q[i]   -- R[i]);
    draw(R[i]   -- Q[i+1]);
    draw(Q[i]   -- S[i]);
    draw(S[i]   -- S[i+1]);
    label(format("\small$P_%i$",i),P[i],-unit(P[i]));
    label(format("\small$Q_%i$",i),Q[i],rotate(60)*unit(Q[i]));
    label(format("\small$R_%i$",i),R[i],unit(R[i]));
    label(format("\small$S_%i$",i),S[i],unit(S[i]));
  }

đź”—generalities-fig156

Figure generalities 156 Generated with Asymptote

Show generalities/fig1570.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Array | #Loop/for/while | #Fill/Unfill | #Shading

size(0,0);

pair [] P, Q, R, S;
real u=2cm;

for (int i=0; i<=4; ++i)
  P[i] = rotate(i*360/5)*(0,-u);

P[5] = P[0];
for (int i=0; i<=4; ++i)
  Q[i] = 3*midpoint(P[i]--P[i+1]);

Q[5] = Q[0];
for (int i=0; i<=4; ++i)
  R[i] = 1/3*( Q[i] + Q[i+1] + P[i+1] );

R[5] = R[0];
for (int i=0; i<=5; ++i)
  S[i] = 1.5*Q[i];

fill(shift(-abs(S[0]),-abs(S[0]))*scale(2*abs(S[0]))*unitsquare,.2grey);

radialshade(scale(abs(S[0]))*unitcircle,lightgrey,(0,0),abs(S[0]),
            black,(0,0),abs(.85*midpoint(S[0]--S[1])));

P[6]=P[1];
for (int i=0; i<=4; ++i)
  {
    radialshade(S[i]--Q[i]--R[i]--Q[i+1]--S[i+1]--cycle,
                lightgrey,(0,0),abs(R[i]),
                black,(0,0),abs(S[i]));
    radialshade(R[i]--Q[i+1]--R[i+1]--P[i+2]--P[i+1]--cycle,
                .8red,(0,0),sqrt(1-(2-2cos(pi/5))/4)*u,
                black,(0,0),abs(Q[i+1]));
  }

for (real i=1; i>0; i-=.05)
  fill(rotate(90*(1-i))*scale(i)*(P[0]--P[1]--P[2]--P[3]--P[4]--cycle),
       (1-i)*red);

pen p=linewidth(1pt);
for (int i=0; i<=4; ++i)
  {
    draw(P[i]   -- P[i+1],p);
    draw(P[i+1] -- R[i],p);
    draw(Q[i]   -- R[i],p);
    draw(R[i]   -- Q[i+1],p);
    draw(Q[i]   -- S[i],p);
    draw(S[i]   -- S[i+1],p);
  }

shipout(bbox(0,black+4mm));

đź”—generalities-fig161

Figure generalities 161 Generated with Asymptote

Show generalities/fig1620.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Examples 2D | Generalities
Tags : #Basis | #Circle | #Loop/for/while | #Function creation

size(6cm,0);

pair A=2expi(pi/2);

pair homography(pair z)
{
  return (z^2+A)/(z+2);
}

guide image;
pair tpt;

draw(unitcircle);
for(real t=0; t<length(unitcircle);t+=.05)
  {
    tpt=homography(point(unitcircle,t));
    image=image..tpt;
    draw(point(unitcircle,t)--tpt,dotted);
  }
draw(image..cycle,red);

đź”—randomwalk-fig001

Figure randomwalk 001 Generated with Asymptote

Show randomwalk/fig0010.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Surveys | Random Walk (3D)
Tags : #Random | #Function (creating) | #Array | #Loop/for/while

import three;
settings.render=0;

// The available directions of steps
triple[] dirs={X,-X,Y,-Y,Z,-Z};
dirs.cyclic=true;

// Return the nodes of the path
triple[] randWalk(real Srnd(), int n)
{
  triple[] randPath;
  triple camera=1e10*currentprojection.camera;
  triple pos=O, tpos;
  int R;
  for (int i=0; i < n; ++i) {
    R=round(Srnd());
    tpos=pos+dirs[R];
    randPath.push(tpos);
    pos=tpos;
  }
  return randPath;
}
triple[] randWalk(int Srnd(), int n)
{
  real R(){ return Srnd();}
  return randWalk(R,n);
}

void drawWalk(triple[] nodes, pen p=white)
{
  triple camera=currentprojection.camera;
  if(currentprojection.infinity)
    camera *= max(abs(minbound(nodes)),abs(maxbound(nodes)));
  real[][] depth;
  for(int i=0; i < nodes.length-1; ++i) {
    real d=abs(camera-0.5*(nodes[i]+nodes[i+1]));
    depth.push(new real[] {d,i});
  }
  depth=sort(depth);
  triple M=nodes[round(depth[0][1])];
  triple m=nodes[round(depth[depth.length-1][1]+1)];
  // Draw from farthest to nearest
  while(depth.length > 0) {
    real[] a=depth.pop();
    int i=round(a[1]);
    draw(nodes[i]--nodes[i+1],abs(nodes[i]-m)/abs(M-m)*p);
  }
}


size(18cm);
currentprojection=orthographic((1,1,1));

drawWalk(randWalk(rand,50000),cyan);
shipout(bbox(3mm,Fill));

đź”—various-fig001

Figure various 001 Generated with Asymptote

Show various/fig0100.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Miscellaneous
Tags : #Loop/for/while | #Transform | #Fill/Unfill

size(10cm);

path g=box((-1,-1),(1,1));
pen [] col= new pen[]{gray,yellow};
real k=sqrt(10)/4;
transform T=scale(k)*rotate(degrees(acos(17/(16*k*sqrt(2)))));
int nb=10;

for (int i=0; i<nb; ++i) filldraw(T^i*g,col[i%2]);

đź”—various-fig002

Figure various 002 Generated with Asymptote

Show various/fig0200.asy on Github.
Generated with Asymptote 3.00-0.
Categories : Miscellaneous
Tags : #Loop/for/while | #Fill/Unfill | #Basis | #Function (creating)

size(10cm);
path g=box((-1,-1),(1,1));
pen [] col= new pen[]{gray,yellow};

path pairToSquare(pair pt){ return pt -- I*pt -- -pt -- -I*pt --cycle; }

int nb=10;
for (int i=0; i<nb; ++i)
  {
    filldraw(g,col[i%2]);
    g=pairToSquare(relpoint(g,1/16));
  }

0%