## Asymptote Generalities – fig0780

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 3 h 39 min

 (Compiled with Asymptote version 2.14svn-r5318)

label(scale(4)*"\textbf{Cancel}");
draw((min(currentpicture).x,0)--(max(currentpicture).x,0), 2bp+yellow);



Étiquettes : , , ,

## Asymptote Generalities – fig0790

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 4 h 39 min

 (Compiled with Asymptote version 2.14svn-r5318)

label(scale(4)*"\textbf{Cancel}");
layer();
draw((min(currentpicture).x,0)--(max(currentpicture).x,0), 2bp+yellow);



Étiquettes : , , ,

## Asymptote Generalities – fig0890

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 14 h 39 min

 (Compiled with Asymptote version 2.14svn-r5318)

//From documentation of Asymptote
size(6cm,0);

void distance(picture pic=currentpicture, pair A, pair B, Label L="", real n=0, pen p=currentpen)
{
real d=3mm;
guide g=A--B;
transform T=shift(-n*d*unit(B-A)*I);
pic.add(new void(frame f, transform t) {
picture opic;
guide G=T*t*g;
draw(opic,G,p,Arrows(NoFill),Bars,PenMargins);
label(opic,L,midpoint(G),UnFill(1));
});
}

pair A=(0,0), B=(3,3);

dot(A);
dot(B);
distance(A,B,rotate(dir(A--B))*Label("$\ell$"),1);



Étiquettes : , , , ,

## Asymptote Generalities – fig1010

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 2 h 39 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(6cm,0);

picture pic;
pen [] P={.8red,.7green,blue+.5grey,yellow+.6grey};

fill(scale(10)*unitcircle,.2blue);

for (int i = 0; i <= 3; ++i)
draw(pic, arc((0,0),10,i*90,(i+1)*90), P[i]);

for (real i = 1; i <= 10; i+=.05)



Étiquettes : , , , ,

## Asymptote Generalities – fig1090

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 10 h 39 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(4cm,0);

pair A=0, B=(1,0), C=(.7,1);

void fillangle(picture pic=currentpicture,
pair O=0, pair A, pair B,
pen p=grey)
{
picture tpic;
real a1=degrees(shift(-O)*A,false);
real a2=degrees(shift(-O)*B,false);
}

draw(A--B--C--cycle);

real r1=15, r2=20;
fillangle(A,B,C,r1,.8red);
fillangle(A,B,C,-r2);
fillangle(B,A,C,r1,.8red);
fillangle(B,A,C,-r2);
fillangle(C,B,A,r1,.8red);
fillangle(C,B,A,-r2);



Étiquettes : , ,

## Asymptote Generalities – fig1980

Category: Asymptote,Examples 2D,GeneralitiesPh. Ivaldi @ 3 h 39 min

 (Compiled with Asymptote version 2.14svn-r5318)

void enclose(picture pic=currentpicture, envelope e,
Label[] L=new Label[],
real xmargin=0, real ymargin=xmargin, pen p=currentpen,
filltype filltype=NoFill, bool above=true)
{

real H;
real[] h;
pic.add(new void (frame f, transform t) {
frame[] d=new frame[];
for (int i=0; i<L.length; ++i) {
d[i]=newframe;
Label LL=L[i].copy();
h[i]=ypart(max(d[i])-min(d[i]));
if(H < h[i]) H=h[i];
}
for (int i=0; i<L.length; ++i) {
real emy=(H-h[i])/2;
e(f,d[i],xmargin,ymargin+emy,p,filltype,above);
}
});
}

void box(picture pic=currentpicture, Label[] L=new Label[],
real xmargin=0, real ymargin=xmargin, pen p=currentpen,
filltype filltype=NoFill, bool above=true)
{
enclose(pic,box,L,xmargin,ymargin,p,filltype,above);
}

box(new Label[] {
Label("\begin{minipage}{3cm}Some text some text some text.\end{minipage}",(2.2cm,0)),
Label("Hello.",0),
Label("\begin{minipage}{3cm}Some text some text some
text some text some text some text some text.\end{minipage}",(5.4cm,0)),
Label("Bye.\rule{0pt}{1.5cm}",(1cm,-3cm))
});



Étiquettes : , ,

## Asymptote using graph.asy – fig0350

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 12 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

// From Asymptote's FAQ
import graph;

real width=15cm;
real aspect=0.3;

picture pic1,pic2;

size(pic1,width,aspect*width,IgnoreAspect);
size(pic2,width,aspect*width,IgnoreAspect);

scale(pic1,false);
scale(pic2,false);

real xmin1=6;
real xmax1=9;
real xmin2=8;
real xmax2=16;

real a1=1;
real a2=0.001;

real f1(real x) {return a1*sin(x/2*pi);}
real f2(real x) {return a2*sin(x/4*pi);}

draw(pic1,graph(pic1,f1,xmin1,xmax1));
draw(pic2,graph(pic2,f2,xmin2,xmax2));

xaxis(pic1,Bottom,LeftTicks());
yaxis(pic1,"$f_1(x)$",Left,RightTicks);

xaxis(pic2,Bottom,LeftTicks(Step=4));
yaxis(pic2,"$f_2(x)$",Left,RightTicks);

yequals(pic1,0,Dotted);
yequals(pic2,0,Dotted);

pair min1=point(pic1,SW);
pair max1=point(pic1,NE);

pair min2=point(pic2,SW);
pair max2=point(pic2,NE);

real scale=(max1.x-min1.x)/(max2.x-min2.x);
real shift=min1.x/scale-min2.x;

transform t1 = pic1.calculateTransform();
transform t2 = pic2.calculateTransform();
transform T=xscale(scale*t1.xx)*yscale(t2.yy);

real height=truepoint(N).y-truepoint(S).y;



Étiquettes : , , , ,

## Tiling with Asymptote – fig0010

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 12 h 06 min

 (Compiled with Asymptote version 1.87svn-r4652)

size(10cm,0);

picture pavehexagonal(int depth=1)
{
picture opic;
path hexa=polygon(6);
pair center;
real a,ap,r,rp,r_d=180/pi;

for(int j=0; j<depth; ++j)
{
for (int i=1; i<=6; ++i)
{
a=i*60-30;
r=j*sqrt(3);
center=r*(rotate(a)*(1,0));
filldraw(opic, shift(center)*hexa, j/depth*.8red+(1-j/depth)*.8*blue);
//Uncomment to see centers of hexagons
dot(opic, shift(center)*midpoint(point(hexa,0)--point(hexa,3)));
//Uncomment to see circles passing by centers
//draw(opic, scale(r)*unitcircle, j/depth*red+(1-j/depth)*blue);
rp=r;
ap=0;
for (real k=0; k<j-1; ++k)
{
r=sqrt((1.5*(j-1 - k))^2 + 3/4*(j+1 + k)^2);
ap+=r_d*acos((rp^2 + r^2 - 3)/(2*r*rp));
center=r*(rotate(a + ap)*(1,0));
filldraw(opic, shift(center)*hexa, j/depth*.8*red+(1-j/depth)*.8*blue);
//Uncomment to see the centers of hexagons
//dot(opic, shift(center)*midpoint(point(hexa,0)--point(hexa,3)));
rp=r;
//Uncomment to see circles passing by centers
//draw(opic, scale(r)*unitcircle, j/depth*red+(1-j/depth)*blue);
}
}
}
return opic;
}



Étiquettes : , ,

## Tiling with Asymptote – fig0030

Category: Asymptote,Examples 2D,TilingPh. Ivaldi @ 14 h 06 min

 (Compiled with Asymptote version 1.87svn-r4652)

size(10cm,0);

transform r60=rotate(60);

pair A=(sqrt(3)/2,-.5);
pair B=r60*A, C=r60*B, D=r60*C, E=r60*D, F=r60*E;

path AB=A{dir(90)}..(.6,.5)..B{dir(0)};
path DE=shift(E-A)*reverse(AB);
path BC=B{dir(45)}..(.75,.7){dir(150)}..{dir(135)}(.65,.75){dir(70)}..(.5,1.25)..C{dir(255)};
path EF=shift(F-B)*reverse(BC);
path CD=C{dir(255)}..(-.4,.5){dir(200)}..D{dir(160)};
path FA=shift(A-C)*reverse(CD);

draw(A--B--C--D--E--F--cycle,linewidth(2pt));
draw(AB,2pt+.8red);
draw(DE,2pt+.8red);
draw(BC,2pt+.8blue);
draw(EF,2pt+.8blue);
draw(CD,2pt+.8green);
draw(FA,2pt+.8green);

picture hexa;
picture eye;

filldraw(hexa,AB--BC--CD--DE--EF--FA--cycle,black,white);
filldraw(eye,rotate(5)*xscale(.4)*unitcircle,white);
filldraw(hexa,subpath(AB,1,2)--subpath(BC,0,2){dir(225)}..{dir(245)}cycle,.1red+yellow,white);
draw(hexa,point(BC,0.1){dir(115)}.. (.8,.55) ..(.6,.65){dir(180)},yellow+grey);
filldraw(eye,rotate(5)*xscale(.4)*unitcircle,white);
fill(eye,rotate(5)*shift(0,-.1)*xscale(.25)*scale(.5)*unitcircle);



Étiquettes : , ,

## 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 – 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 – 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 : , , , ,

## Official Asymptote example – BezierSurface

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

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

import three;

string viewpoint="
COO=-684.0787963867188 206.90650939941406 218.13809204101562
C2C=0.8244762420654297 -0.563306450843811 0.0540805421769619
ROO=1009.7407942621448
ROLL=17.39344555165265
";

// viewpoint=getstring("viewpoint",viewpoint);
currentprojection=perspective(viewpoint);

triple[][][] P={
{
{(-1.6,0,1.875),(-2.3,0,1.875),(-2.7,0,1.875),(-2.7,0,1.65),},
{(-1.6,-0.3,1.875),(-2.3,-0.3,1.875),(-2.7,-0.3,1.875),(-2.7,-0.3,1.65),},
{(-1.5,-0.3,2.1),(-2.5,-0.3,2.1),(-3,-0.3,2.1),(-3,-0.3,1.65),},
{(-1.5,0,2.1),(-2.5,0,2.1),(-3,0,2.1),(-3,0,1.65),}
},{
{(-2.7,0,1.65),(-2.7,0,1.425),(-2.5,0,0.975),(-2,0,0.75),},
{(-2.7,-0.3,1.65),(-2.7,-0.3,1.425),(-2.5,-0.3,0.975),(-2,-0.3,0.75),},
{(-3,-0.3,1.65),(-3,-0.3,1.2),(-2.65,-0.3,0.7275),(-1.9,-0.3,0.45),},
{(-3,0,1.65),(-3,0,1.2),(-2.65,0,0.7275),(-1.9,0,0.45),}
},{
{(-2.7,0,1.65),(-2.7,0,1.875),(-2.3,0,1.875),(-1.6,0,1.875),},
{(-2.7,0.3,1.65),(-2.7,0.3,1.875),(-2.3,0.3,1.875),(-1.6,0.3,1.875),},
{(-3,0.3,1.65),(-3,0.3,2.1),(-2.5,0.3,2.1),(-1.5,0.3,2.1),},
{(-3,0,1.65),(-3,0,2.1),(-2.5,0,2.1),(-1.5,0,2.1),}
},{
{(-2,0,0.75),(-2.5,0,0.975),(-2.7,0,1.425),(-2.7,0,1.65),},
{(-2,0.3,0.75),(-2.5,0.3,0.975),(-2.7,0.3,1.425),(-2.7,0.3,1.65),},
{(-1.9,0.3,0.45),(-2.65,0.3,0.7275),(-3,0.3,1.2),(-3,0.3,1.65),},
{(-1.9,0,0.45),(-2.65,0,0.7275),(-3,0,1.2),(-3,0,1.65),}
}
};

picture pic;
size(pic,15cm);
size3(pic,10cm);
draw(pic,surface(P),blue);



Étiquettes : , , ,

## Official Asymptote example – Bode

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

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

import graph;
texpreamble("\def\Arg{\mathop {\rm Arg}\nolimits}");

size(10cm,5cm,IgnoreAspect);

real ampl(real x) {return 2.5/(1+x^2);}
real phas(real x) {return -atan(x)/pi;}

scale(Log,Log);
draw(graph(ampl,0.01,10));
ylimits(0.001,100);

xaxis("$\omega\tau_0$",BottomTop,LeftTicks);
yaxis("$|G(\omega\tau_0)|$",Left,RightTicks);

picture q=secondaryY(new void(picture pic) {
scale(pic,Log,Linear);
draw(pic,graph(pic,phas,0.01,10),red);
ylimits(pic,-1.0,1.5);
yaxis(pic,"$\Arg G/\pi$",Right,red,
LeftTicks("$% #.1f$",
begin=false,end=false));
yequals(pic,1,Dotted);
});
label(q,"(1,0)",Scale(q,(1,0)),red);



Étiquettes : , , ,

## Official Asymptote example – Klein

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

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

import graph3;

size(469pt);

viewportmargin=0;

currentprojection=perspective(
camera=(25.0851928432063,-30.3337528952473,19.3728775115443),
up=Z,
target=(-0.590622314050054,0.692357205025578,-0.627122488455679),
zoom=1,

triple f(pair t) {
real u=t.x;
real v=t.y;
real r=2-cos(u);
real x=3*cos(u)*(1+sin(u))+r*cos(v)*(u < pi ? cos(u) : -1);
real y=8*sin(u)+(u < pi ? r*sin(u)*cos(v) : 0);
real z=r*sin(v);
return (x,y,z);
}

surface s=surface(f,(0,0),(2pi,2pi),8,8,Spline);
draw(s,lightolive+white,"bottle",render(merge=true));

string lo="$\displaystyle u\in[0,\pi]: \cases{x=3\cos u(1+\sin u)+(2-\cos u)\cos u\cos v,\cr y=8\sin u+(2-\cos u)\sin u\cos v,\cr z=(2-\cos u)\sin v.\cr}$";

string hi="$\displaystyle u\in[\pi,2\pi]:\\\cases{x=3\cos u(1+\sin u)-(2-\cos u)\cos v,\cr y=8\sin u,\cr z=(2-\cos u)\sin v.\cr}$";

real h=0.0125;

begingroup3("parametrization");
draw(surface(xscale(-0.38)*yscale(-0.18)*lo,s,0,1.7,h,bottom=false),
"[0,pi]");
draw(surface(xscale(0.26)*yscale(0.1)*rotate(90)*hi,s,4.9,1.4,h,bottom=false),
"[pi,2pi]");
endgroup3();

begingroup3("boundary");
draw(s.uequals(0),blue+dashed);
draw(s.uequals(pi),blue+dashed);
endgroup3();

add(new void(frame f, transform3 t, picture pic, projection P) {
draw(f,invert(box(min(f,P),max(f,P)),P),"frame");
});



Étiquettes : , , , , ,

## Official Asymptote example – basealign

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

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

import fontsize;
import three;

settings.autobillboard=false;
settings.embed=false;
currentprojection=orthographic(Z);

defaultpen(fontsize(100pt));

dot(O);

label("acg",O,align=N,basealign);
label("ace",O,align=N,red);
label("acg",O,align=S,basealign);
label("ace",O,align=S,red);
label("acg",O,align=E,basealign);
label("ace",O,align=E,red);
label("acg",O,align=W,basealign);
label("ace",O,align=W,red);

picture pic;
dot(pic,(labelmargin(),0,0),blue);
dot(pic,(-labelmargin(),0,0),blue);
dot(pic,(0,labelmargin(),0),blue);
dot(pic,(0,-labelmargin(),0),blue);

dot((0,0));

label("acg",(0,0),align=N,basealign);
label("ace",(0,0),align=N,red);
label("acg",(0,0),align=S,basealign);
label("ace",(0,0),align=S,red);
label("acg",(0,0),align=E,basealign);
label("ace",(0,0),align=E,red);
label("acg",(0,0),align=W,basealign);
label("ace",(0,0),align=W,red);

picture pic;
dot(pic,(labelmargin(),0),blue);
dot(pic,(-labelmargin(),0),blue);
dot(pic,(0,labelmargin()),blue);
dot(pic,(0,-labelmargin()),blue);



Étiquettes : , , , ,

## Official Asymptote example – binarytreetest

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

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

import binarytree;

picture pic,pic2;

binarytree bt=binarytree(1,2,4,nil,5,nil,nil,0,nil,nil,3,6,nil,nil,7);
draw(pic,bt);

binarytree st=searchtree(10,5,2,1,3,4,7,6,8,9,15,13,12,11,14,17,16,18,19);
draw(pic2,st,blue);



Étiquettes : ,

## Official Asymptote example – errorbars

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 */

import graph;

picture pic;
real xsize=200, ysize=140;
size(pic,xsize,ysize,IgnoreAspect);

pair[] f={(5,5),(50,20),(90,90)};
pair[] df={(0,0),(5,7),(0,5)};

errorbars(pic,f,df,red);
draw(pic,graph(pic,f),"legend",
marker(scale(0.8mm)*unitcircle,red,FillDraw(blue),above=false));

scale(pic,true);

xaxis(pic,"$x$",BottomTop,LeftTicks);
yaxis(pic,"$y$",LeftRight,RightTicks);

picture pic2;
size(pic2,xsize,ysize,IgnoreAspect);

frame mark;
filldraw(mark,scale(0.8mm)*polygon(6),green,green);
draw(mark,scale(0.8mm)*cross(6),blue);

draw(pic2,graph(pic2,f),marker(mark,markuniform(5)));

scale(pic2,true);

xaxis(pic2,"$x$",BottomTop,LeftTicks);
yaxis(pic2,"$y$",LeftRight,RightTicks);

yequals(pic2,55.0,red+Dotted);
xequals(pic2,70.0,red+Dotted);

// Fit pic to W of origin:

// Fit pic2 to E of (5mm,0):



Étiquettes : , , , ,

## Official Asymptote example – fjortoft

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

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

size(15cm,0);

pair d=(1.5,1);
real s=d.x+1;

picture box(string s) {
picture pic;
draw(pic,box(0,d));
label(pic,s,d/2);
return pic;
}

add(box("$k_1$"));
add(shift(s)*box("$k_2$"));
add(shift(s)^2*box("$k_3$"));

path g=(d.x,d.y/2)--(s,d.y/2);
path G=(d.x/2,-(s-d.x))--(d.x/2,0);

draw(Label(baseline("$\ldots$")),shift(-s)*g,BeginArrow,BeginPenMargin);
draw(Label("$Z_1$"),g,BeginArrow,BeginPenMargin);
draw(Label("$E_1$",LeftSide),g,Blank);
draw(Label("$Z_3$"),shift(s)*g,Arrow,PenMargin);
draw(Label("$E_3$",LeftSide),shift(s)*g,Blank);
draw(Label("$Z_2$"),shift(s)*G,Arrow,PenMargin);
draw(Label("$E_2$",LeftSide),shift(s)*G,Blank);
draw(Label(baseline("$\ldots$")),shift(s)^2*g,Arrow,PenMargin);



Étiquettes : ,

## Official Asymptote example – icon

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

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

import graph;

size(30,30,IgnoreAspect);

real f(real t) {return t < 0 ? -1/t : -0.5/t;}

picture logo(pair s=0, pen q)
{
picture pic;
pen p=linewidth(3)+q;
real a=-0.5;
real b=1;
real eps=0.1;
draw(pic,shift((eps,-f(a)))*graph(f,a,-eps),p);
real c=0.5*a;
pair z=(0,f(c)-f(a));
draw(pic,z+c+eps--z,p);
yaxis(pic,p);
return shift(s)*pic;
}



Étiquettes : ,

## Official Asymptote example – laserlattice

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

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

import graph;
import palette;

int n=256;
pen[] Palette=BWRainbow();

real w(real w0, real z0, real z) {return w0*sqrt(1+(z/z0)^2);}

real pot(real lambda, real w0, real r, real z)
{
real z0=pi*w0^2/lambda, kappa=2pi/lambda;
return exp(-2*(r/w(w0,z0,z))^2)*cos(kappa*z)^2;
}

picture make_field(real lambda, real w0)
{
real[][] v=new real[n][n];
for(int i=0; i < n; ++i)
for(int j=0; j < n; ++j)
v[i][j]=pot(lambda,w0,i-n/2,abs(j-n/2));

picture p=new picture;
size(p,250,250,IgnoreAspect);
real xm=-n/lambda, ym=-n/(2*w0), xx=n/lambda, yx=n/(2*w0);
image(p,v,(xm,ym),(xx,yx),Palette);
xlimits(p,xm,xx);
ylimits(p,ym,yx);
xaxis(p,"{\Large $z/\frac{\lambda}{2}$}",BottomTop,LeftTicks);
yaxis(p,"{\Large $r/w_0$}",LeftRight,RightTicks);
label(p,format("{\LARGE $w_0/\lambda=%.2f$}",w0/lambda),point(p,NW),5N);

return p;
}

picture p=make_field(160,80);
picture q=make_field(80,80);
picture r=make_field(16,80);
picture s=make_field(2,80);

real margin=1cm;



Étiquettes : , , , , ,

## Official Asymptote example – logo

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

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

size(140,80,IgnoreAspect);

picture logo(pair s=0, pen q)
{
picture pic;
pen p=linewidth(2)+fontsize(24pt)+q;
real a=-0.4;
real b=0.95;
real y1=-5;
real y2=-3y1/2;
path A=(a,0){dir(10)}::{dir(89.5)}(0,y2);
draw(pic,A,p);
draw(pic,(0,y1){dir(88.3)}::{dir(20)}(b,0),p);
real c=0.5*a;
pair z=(0,2.5);
label(pic,"{\it symptote}",z,0.25*E+0.169S,p);
pair w=(0,1.7);
draw(pic,intersectionpoint(A,w-1--w)--w,p);
draw(pic,(0,y1)--(0,y2),p);
draw(pic,(a,0)--(b,0),p);
return shift(s)*pic;
}

pair z=(-0.015,0.08);
for(int x=0; x < 10; ++x)



Étiquettes :

## Official Asymptote example – mosquito

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(9cm,10cm,IgnoreAspect);

pair d=(1,0.25);
real s=1.6d.x;
real y=0.6;
defaultpen(fontsize(8pt));

picture box(string s, pair z=(0,0)) {
picture pic;
draw(pic,box(-d/2,d/2));
label(pic,s,(0,0));
return shift(z)*pic;
}

label("Birds",(0,y));
picture removed=box("Removed ($R_B$)");
picture infectious=box("Infectious ($I_B$)",(0,-1.5));
picture susceptible=box("Susceptible ($S_B$)",(0,-3));

label("Mosquitoes",(s,y));
picture larval=box("Larval ($L_M$)",(s,0));
picture susceptibleM=box("Susceptible ($S_M$)",(s,-1));
picture exposed=box("Exposed ($E_M$)",(s,-2));
picture infectiousM=box("Infectious ($I_M$)",(s,-3));

path ls=point(larval,S)--point(susceptibleM,N);
path se=point(susceptibleM,S)--point(exposed,N);
path ei=point(exposed,S)--point(infectiousM,N);
path si=point(susceptible,N)--point(infectious,S);

draw(minipage("\flushright{recovery rate ($g$) \& death rate from virus
($\mu_V$)}",40pt),point(infectious,N)--point(removed,S),LeftSide,Arrow,
PenMargin);

draw(si,LeftSide,Arrow,PenMargin);

draw(minipage("\flushright{maturation rate ($m$)}",50pt),ls,RightSide,
Arrow,PenMargin);
draw(minipage("\flushright{viral incubation rate ($k$)}",40pt),ei,
RightSide,Arrow,PenMargin);

path ise=point(infectious,E)--point(se,0.5);

draw("$(ac)$",ise,LeftSide,dashed,Arrow,PenMargin);
label(minipage("\flushleft{biting rate $\times$ transmission
probability}",50pt),point(infectious,SE),dir(-60)+S);

path isi=point(infectiousM,W)--point(si,2.0/3);

draw("$(ab)$",isi,LeftSide,dashed,Arrow,PenMargin);
draw(se,LeftSide,Arrow,PenMargin);

real t=2.0;
draw("$\beta_M$",
point(susceptibleM,E){right}..tension t..{left}point(larval,E),
2*(S+SE),red,Arrow(Fill,0.5));
draw(minipage("\flushleft{birth rate ($\beta_M$)}",20pt),
point(exposed,E){right}..tension t..{left}point(larval,E),2SW,red,
Arrow(Fill,0.5));
draw("$\beta_M$",
point(infectiousM,E){right}..tension t..{left}point(larval,E),2SW,
red,Arrow(Fill,0.5));

path arrow=(0,0)--0.75cm*dir(35);
draw(point(larval,NNE),
Label(minipage("\flushleft{larval death rate ($\mu_L$)}",45pt),1),
arrow,blue,Arrow);
draw(point(susceptibleM,NNE),
Label(minipage("\flushleft{adult death rate ($\mu_A$)}",20pt),1),
arrow,N,blue,Arrow);
draw(point(exposed,NNE),Label("$\mu_A$",1),arrow,blue,Arrow);
draw(point(infectiousM,NNE),Label("$\mu_A$",1),arrow,blue,Arrow);



Étiquettes : ,

## Official Asymptote example – secondaryaxis

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

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

import graph;

size(9cm,6cm,IgnoreAspect);
string data="secondaryaxis.csv";

file in=input(data).line().csv();

string[] titlelabel=in;
string[] columnlabel=in;

real[][] a=in.dimension(0,0);
a=transpose(a);
real[] t=a[0], susceptible=a[1], infectious=a[2], dead=a[3], larvae=a[4];
real[] susceptibleM=a[5], exposed=a[6],infectiousM=a[7];

scale(true);

draw(graph(t,susceptible,t >= 10 & t <= 15));
draw(graph(t,dead,t >= 10 & t <= 15),dashed);

xaxis("Time ($\tau$)",BottomTop,LeftTicks);
yaxis(Left,RightTicks);

picture secondary=secondaryY(new void(picture pic) {
scale(pic,Linear(true),Log(true));
draw(pic,graph(pic,t,infectious,t >= 10 & t <= 15),red);
yaxis(pic,Right,red,LeftTicks(begin=false,end=false));
});

label(shift(5mm*N)*"Proportion of crows",point(NW),E);



Étiquettes : , , , ,

## Official Asymptote example – spectrum

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 */

import graph;
usepackage("ocg");
settings.tex="pdflatex";

// Dan Bruton algorithm
pen nm2rgb(real wl, real gamma=0.8, bool intensity=true) {
triple rgb;
if(wl >= 380 && wl <= 440) {rgb=((440-wl)/60,0,1);}
if(wl >  440 && wl <= 490) {rgb=(0,(wl-440)/50,1);}
if(wl >  490 && wl <= 510) {rgb=(0,1,(510-wl)/20);}
if(wl >  510 && wl <= 580) {rgb=((wl-510)/70,1,0);}
if(wl >  580 && wl <= 645) {rgb=(1,(645-wl)/65,0);}
if(wl >  645 && wl <= 780) {rgb=(1,0,0);}

real Intensity=1;
if(intensity) {
if(wl >= 700) {Intensity=0.3+0.7*(780-wl)/80;}
else if(wl <= 420) {Intensity=0.3+0.7*(wl-380)/40;}
}

return rgb((Intensity*rgb.x)**gamma,(Intensity*rgb.y)**gamma,
(Intensity*rgb.z)**gamma);
}

real width=1;
real height=50;

begin("spectrum");
for(real i=380 ; i <= 780 ; i += width) {
draw((i,0)--(i,height),width+nm2rgb(wl=i,false)+squarecap);
}
begin("Extinction",false); // nested
for(real i=380 ; i <= 780 ; i += width) {
draw((i,0)--(i,height),width+nm2rgb(wl=i,true)+squarecap);
}
end();
end();

begin("Wavelength");
xaxis(scale(0.5)*"$\lambda$(nm)",BottomTop,380,780,
RightTicks(scale(0.5)*rotate(90)*Label(),step=2,Step=10),above=true);
end();

// From Astronomical Data Center(NASA)
// Neutral only
real[] Na={423.899, 424.208, 427.364, 427.679, 428.784, 429.101,
432.14, 432.462, 434.149, 434.474, 439.003, 439.334, 441.989, 442.325,
449.418, 449.766, 454.163, 454.519, 568.2633, 568.8204, 588.995,
589.5924};
begin("Na absorption");
for(int i=0; i < Na.length; ++i) {
draw((Na[i],0)--(Na[i],height),0.1*width+squarecap);
}
end();

begin("Na emission");
for(int i=0; i < Na.length; ++i) {
draw((Na[i],0)--(Na[i],-height),0.1*width+nm2rgb(Na[i],false)+squarecap);
}
end();

// Neutral only
real[] Zn={388.334, 396.543, 411.321, 429.288, 429.833, 462.981,
468.014, 472.215, 481.053 , 506.866, 506.958, 518.198, 530.865,
531.024, 531.102, 577.21, 577.55, 577.711, 623.79, 623.917, 636.234,
647.918, 692.832, 693.847, 694.32, 779.936};
begin("Zn absorption",false);
for(int i=0; i < Zn.length; ++i) {
draw((Zn[i],0)--(Zn[i],height),width+squarecap);
}
end();

begin("Zn emission",false);
for(int i=0; i < Zn.length; ++i) {
draw((Zn[i],0)--(Zn[i],-height),width+nm2rgb(Zn[i],false)+squarecap);
}
end();

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



Étiquettes : , , , ,

## Official Asymptote example – subpictures

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

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

picture pic1;
real size=50;
size(pic1,size);
fill(pic1,(0,0)--(50,100)--(100,0)--cycle,red);

picture pic2;
size(pic2,size);
fill(pic2,unitcircle,green);

picture pic3;
size(pic3,size);
fill(pic3,unitsquare,blue);

picture pic;



Étiquettes : , ,

## Official Asymptote example – threeviews

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 */

import three;

picture pic;
unitsize(pic,5cm);

currentlight.viewport=false;
settings.render=4;
settings.toolbar=false;
viewportmargin=(1cm,1cm);

draw(pic,scale3(0.5)*unitsphere,green,render(compression=Low,merge=true));
draw(pic,Label("$x$",1),O--X);
draw(pic,Label("$y$",1),O--Y);
draw(pic,Label("$z$",1),O--Z);

// Europe and Asia: