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



Mots-clefs : , , , ,

## Official Asymptote example – axis3

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

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

import graph3;

size(0,200);
size3(200,IgnoreAspect);

currentprojection=perspective(5,2,2);

scale(Linear,Linear,Log);

xaxis3("$x$",0,1,red,OutTicks(2,2));
yaxis3("$y$",0,1,red,OutTicks(2,2));
zaxis3("$z$",1,30,red,OutTicks(beginlabel=false));



Mots-clefs : , ,

## Official Asymptote example – arrows3

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

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

import three;

size(15cm);

defaultrender.merge=true;

currentprojection=perspective(24,14,13);
currentlight=light(gray(0.5),specularfactor=3,viewport=false,
(0.5,-0.5,-0.25),(0.5,0.5,0.25),(0.5,0.5,1),(-0.5,-0.5,-1));

defaultpen(0.75mm);

path3 g=arc(O,1,90,-60,90,60);
transform3 t=shift(invert(3S,O));



Mots-clefs : ,

## Official Asymptote example – alignedaxis

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;

real Freq=60.0;
real margin=5mm;

pair exp(pair x) {
return exp(x.x)*(cos(x.y)+I*sin(x.y));
}

real Merr(real x, real w) {
real tau=x/(2*Freq);
return 20*log(abs((tau*w+tau/(exp(I*2*pi*Freq*tau)-1))*(I*2*pi*Freq)));
}

real Aerr(real x, real w) {
real tau=x/(2*Freq);
return degrees((tau*w+tau/(exp(I*2*pi*Freq*tau)-1))*(I*2*pi*Freq));
}

picture pic1;
scale(pic1,Log,Linear);
real Merr1(real x){return Merr(x,1);}
draw(pic1,graph(pic1,Merr1,1e-4,1),black+1.2);

ylimits(pic1,-60,20);
yaxis(pic1,"magnitude (dB)",LeftRight,RightTicks(new
real[] {-60,-40,-20,0,20}));
xaxis(pic1,"$f/f_\mathrm{Ny}$",BottomTop,LeftTicks(N=5));
yequals(pic1,0,Dotted);
yequals(pic1,-20,Dotted);
yequals(pic1,-40,Dotted);
xequals(pic1,1e-3,Dotted);
xequals(pic1,1e-2,Dotted);
xequals(pic1,1e-1,Dotted);

size(pic1,100,100,point(pic1,SW),point(pic1,NE));

label(pic1,"$\theta=1$",point(pic1,N),2N);

frame f1=pic1.fit();

picture pic1p;
scale(pic1p,Log,Linear);
real Aerr1(real x){return Aerr(x,1);}
draw(pic1p,graph(pic1p,Aerr1,1e-4,1),black+1.2);

ylimits(pic1p,-5,95);
yaxis(pic1p,"phase (deg)",LeftRight,RightTicks(new real[] {0,45,90}));
xaxis(pic1p,"$f/f_\mathrm{Ny}$",BottomTop,LeftTicks(N=5));
yequals(pic1p,0,Dotted);
yequals(pic1p,45,Dotted);
yequals(pic1p,90,Dotted);
xequals(pic1p,1e-3,Dotted);
xequals(pic1p,1e-2,Dotted);
xequals(pic1p,1e-1,Dotted);

size(pic1p,100,100,point(pic1p,SW),point(pic1p,NE));

frame f1p=pic1p.fit();
f1p=shift(0,min(f1).y-max(f1p).y-margin)*f1p;

picture pic2;
scale(pic2,Log,Linear);
real Merr2(real x){return Merr(x,0.75);}
draw(pic2,graph(pic2,Merr2,1e-4,1),black+1.2);

ylimits(pic2,-60,20);
yaxis(pic2,"magnitude (dB)",LeftRight,RightTicks(new
real[] {-60,-40,-20,0,20}));
xaxis(pic2,"$f/f_\mathrm{Ny}$",BottomTop,LeftTicks(N=5));
yequals(pic2,0,Dotted);
yequals(pic2,-20,Dotted);
yequals(pic2,-40,Dotted);
xequals(pic2,1e-3,Dotted);
xequals(pic2,1e-2,Dotted);
xequals(pic2,1e-1,Dotted);

size(pic2,100,100,point(pic2,SW),point(pic2,NE));

label(pic2,"$\theta=0.75$",point(pic2,N),2N);

frame f2=pic2.fit();
f2=shift(max(f1).x-min(f2).x+margin)*f2;

picture pic2p;
scale(pic2p,Log,Linear);
real Aerr2(real x){return Aerr(x,0.75);}
draw(pic2p,graph(pic2p,Aerr2,1e-4,1),black+1.2);

ylimits(pic2p,-5,95);
yaxis(pic2p,"phase (deg)",LeftRight,RightTicks(new real[] {0,45.1,90}));
xaxis(pic2p,"$f/f_\mathrm{Ny}$",BottomTop,LeftTicks(N=5));
yequals(pic2p,0,Dotted);
yequals(pic2p,45,Dotted);
yequals(pic2p,90,Dotted);
xequals(pic2p,1e-3,Dotted);
xequals(pic2p,1e-2,Dotted);
xequals(pic2p,1e-1,Dotted);

size(pic2p,100,100,point(pic2p,SW),point(pic2p,NE));

frame f2p=pic2p.fit();
f2p=shift(max(f1p).x-min(f2p).x+margin,min(f2).y-max(f2p).y-margin)*f2p;



Mots-clefs : , ,

## Official Asymptote example – alignbox

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

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

real margin=1.5mm;

object left=align(object("$x^2$",ellipse,margin),W);
object right=align(object("$\sin x$",ellipse,margin),4E);
add(new void(frame f, transform t) {
draw(f,point(left,NE,t)--point(right,W,t));
});



Mots-clefs : ,

## Official Asymptote example – advection

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

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

size(0,22cm);

texpreamble("
\usepackage{bm}
\def\v{\bm}
\def\cross{{\v\times}}
\def\del{\nabla}
");

defaultpen(fontsize(10pt));

real margin=1.5mm;

object IC=draw("initial condition $\v U_0$",box,(0,1),
margin,black,FillDraw(palegray));
object Adv0=draw("Lagrangian state $\v U(t)$",ellipse,(1,1),
margin,red,FillDraw(palered));
object Adv=draw("Lagrangian prediction $\v U(t+\tau)$",ellipse,(1,0),
margin,red,FillDraw(palered));
margin,red,FillDraw(palered));
object Ur=draw("rearranged $\v \widetilde U$",box,(0,0),
margin,orange+gray,FillDraw(paleyellow));
object Ui=draw("interpolated $\v \widetilde U$",box,(1,-1),
margin,blue,FillDraw(paleblue));
object Crank=draw("${\cal L}^{-1}(-\tau){\cal L}(\tau)\v \widetilde U$",
box,(0.5,-1),margin,blue,FillDraw(paleblue));
object CrankR=draw("${\cal L}^{-1}(-\tau){\cal L}(\tau)\v \widetilde U$",
box,(0,-1),margin,orange+gray,FillDraw(paleyellow));
object Urout=draw(minipage("\center{Lagrangian rearranged solution~$\v U_R$}",
100pt),box,(0,-2),margin,orange+gray,
FillDraw(paleyellow));
object Diff=draw("$\v D\del^2 \v \widetilde U$",box,(0.75,-1.5),
margin,blue,FillDraw(paleblue));
object UIout=draw(minipage("\center{semi-Lagrangian solution~$\v U_I$}",80pt),
box,(0.5,-2),margin,FillDraw(palered+paleyellow));
object psi=draw("$\psi=\del^{-2}\omega$",box,(1.6,-1),
margin,darkgreen,FillDraw(palegreen));
object vel=draw("$\v v=\v{\hat z} \cross\grad\psi$",box,(1.6,-0.5),
margin,darkgreen,FillDraw(palegreen));

add(new void(frame f, transform t) {
picture pic;
PenMargin);
draw(pic,Label("Lagrange $\rightarrow$ Euler",0.45),
Arrow,PenMargin);
draw(pic,"Lagrange $\rightarrow$ Euler",point(Adv,S,t)--point(Ui,N,t),
RightSide,blue,Arrow,PenMargin);
Arrow(Relative(0.7)),PenMargin);
draw(pic,minipage("\flushleft{diffuse: multigrid Crank--Nicholson}",80pt),
point(Ui,W,t)--point(Crank,E,t),5N,blue,MidArrow,PenMargin);
draw(pic,minipage("\flushleft{diffuse: multigrid Crank--Nicholson}",80pt),
point(Ur,S,t)--point(CrankR,N,t),LeftSide,orange+gray,Arrow,PenMargin);
draw(pic,"output",point(CrankR,S,t)--point(Urout,N,t),RightSide,
orange+gray,Arrow,PenMargin);
draw(pic,point(Ui,S,t)--point(Diff,N,t),blue,MidArrow,PenMargin);
draw(pic,point(Crank,S,t)--point(Diff,N,t),blue,MidArrow,PenMargin);
label(pic,"subtract",point(Diff,N,t),12N,blue);
draw(pic,Label("Euler $\rightarrow$ Lagrange",0.5),
Arrow(position=1.5),PenMargin);
PenMargin);
draw(pic,"output",point(Crank,S,t)--point(UIout,N,t),RightSide,brown,Arrow,
PenMargin);
draw(pic,Label("$t+\tau\rightarrow t$",0.45),
draw(pic,point(psi,N,t)--point(vel,S,t),darkgreen,Arrow,PenMargin);
draw(pic,Label("multigrid",0.5,S),point(Ui,E,t)--point(psi,W,t),darkgreen,
Arrow,PenMargin);

});



Mots-clefs :

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



Mots-clefs :

## Official Asymptote example – RiemannSurfaceRoot

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

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

// Riemann surface of z^{1/n}
import graph3;
import palette;

int n=3;

size(200,300,keepAspect=false);

currentprojection=orthographic(10,10,30);
currentlight=(10,10,5);
triple f(pair t) {return (t.x*cos(t.y),t.x*sin(t.y),t.x^(1/n)*sin(t.y/n));}

surface s=surface(f,(0,0),(1,2pi*n),8,16,Spline);
s.colors(palette(s.map(zpart),Rainbow()));

draw(s,meshpen=black,render(merge=true));



Mots-clefs : , , ,

## Official Asymptote example – RiemannSurface

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

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

import graph3;
import palette;

size(200,300,keepAspect=false);
//settings.nothin=true;

currentprojection=orthographic(10,10,30);
currentlight=(10,10,5);
triple f(pair t) {return (exp(t.x)*cos(t.y),exp(t.x)*sin(t.y),t.y);}

surface s=surface(f,(-4,-2pi),(0,4pi),8,16,Spline);
s.colors(palette(s.map(zpart),Rainbow()));
draw(s,render(merge=true));



Mots-clefs : , , , ,

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