Official Asymptote example – penfunctionimage

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

Figure 0162
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import palette;

size(200);

real fracpart(real x) {return (x-floor(x));}

pair pws(pair z) {
  pair w=(z+exp(pi*I/5)/0.9)/(1+z/0.9*exp(-pi*I/5));
  return exp(w)*(w^3-0.5*I);
}

int N=512;

pair a=(-1,-1);
pair b=(0.5,0.5);
real dx=(b-a).x/N;
real dy=(b-a).y/N;

pen f(int u, int v) {
  pair z=a+(u*dx,v*dy);
  pair w=pws(z);
  real phase=degrees(w,warn=false);
  real modulus=w == 0 ? 0: fracpart(log(abs(w)));
  return hsv(phase,1,sqrt(modulus));
}

image(f,N,N,(0,0),(300,300),antialias=true);


Official Asymptote example – partitionExample

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

Figure 0159
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
size(15cm);
import bezulate;

path[] p = texpath("$\sigma \Theta$");
pair m = min(p);
pair M = max(p);
real midy = 0.5(M.y+m.y);

path[] alpha = p[0:2];
path[] theta = p[2:5];
filldraw(p,lightgrey,black);

draw("{\tt partition}",(M.x+1mm,midy)--(M.x+5mm,midy),Arrow);
draw((M.x+1mm,midy+1mm)--(M.x+5mm,midy+2mm),Arrow);
draw((M.x+1mm,midy-1mm)--(M.x+5mm,midy-2mm),Arrow);

filldraw(shift((M.x+8.5mm,midy+3.5mm))*alpha,lightgrey,black);
filldraw(shift((M.x+5.5mm,0))*theta[0:2],lightgrey,black);
filldraw(shift(M.x+5.5mm,midy-2.5mm)*theta[2:3],lightgrey,black);

draw("{\tt merge}, {\tt bezulate}",(M.x+9mm,midy+3mm)--(M.x+15mm,midy+3mm),Arrow);
draw("{\tt merge}, {\tt bezulate}",(M.x+9mm,midy)--(M.x+15mm,midy),Arrow);
draw("{\tt bezulate}",(M.x+9mm,midy-2.5mm)--(M.x+15mm,midy-2.5mm),Arrow);

filldraw(shift(M.x+16mm-min(alpha).x,midy+3.5mm)*bezulate(alpha),lightgrey,black);
filldraw(shift(M.x+16mm-min(theta[0:2]).x,0)*bezulate(theta[0:2]),lightgrey,black);
filldraw(shift(M.x+16mm-min(theta[0:2]).x,midy-2.5mm)*bezulate(theta[2:3]),lightgrey,black);


Official Asymptote example – mergeExample

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

Figure 0142
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
size(16cm);
import bezulate;

pen edgepen=linewidth(1)+blue;
pen dotpen=deepgreen;
pen labelpen=fontsize(8pt);

path outer = (0.5,5){E}..(5,-1){S}..{W}(4,-4)..{W}(2.5,-1.5){W}..(-0.3,-2.5){W}..(-3,0)..cycle;
outer = subdivide(outer);
path[] p = {outer,shift(-0.5,1.0)*rotate(-22)*scale(1.5,2.4)*subdivide(unitcircle),shift(2.3,0.3)*scale(0.7)*unitcircle};

// a
filldraw(p,lightgrey+evenodd);

real w = 1.1*(max(p).x-min(p).x);

// b
p = shift(w)*p;
draw(p);
path l = point(p[1],2)--point(p[0],4);
draw(l,red);
for(int i = 0; i < p.length; ++i)
{
  real[][] ts = intersections(l,p[i]);
  for(real[] t:ts)
    dot(point(l,t[0]));
}
path l2 = point(l,intersections(l,p[0])[0][0])--point(l,intersections(l,p[2])[1][0]);
real to = intersections(l,p[0])[0][1];
real ti = intersections(l,p[2])[1][1];
draw(l2,edgepen);
label("$A$",point(l2,1),2E,labelpen);
label("$B$",point(l2,0),1.5E,labelpen);

// c
p = shift(w)*p;
l2 = shift(w)*l2;
draw(p);
real timeoffset=2;
path t1=subpath(p[0],to,to+timeoffset);
t1=t1--point(p[2],ti)--cycle;
fill(t1,lightgrey);
draw(point(p[2],ti)--point(p[0],to+4),red);
dot(Label("$A$",labelpen),point(p[2],ti),2E,dotpen);
dot(Label("$B$",labelpen),point(p[0],to),1.5E,dotpen);
dot(Label("$C$",labelpen),point(p[0],to+timeoffset),1.5S,dotpen);
draw(t1,edgepen);
dot(point(p[0],to+4));
draw(shift(-0.5,-0.5)*subpath(p[0],to+4,to+timeoffset+0.5),Arrow(4));

// d
p = shift(w)*p;
p[0] = subpath(p[0],to+timeoffset,to+length(p[0]))--uncycle(p[2],ti)--cycle;
p.delete(2);
draw(p);

// e
p = shift(w)*p;
path q=point(p[1],0)--subpath(p[0],15.4,16)--cycle;
p[0] = subpath(p[0],16,15.4+length(p[0]))--uncycle(p[1],0)--cycle;
p.delete(1);
filldraw(p,lightgrey);

// f
p = shift(w)*p;
filldraw(bezulate(p),lightgrey);
filldraw(shift(3w)*t1,lightgrey);
filldraw(shift(w)*q,lightgrey);


real x = min(p).x - 4.5w;
string l = "abcdef";
for(int i = 0; i < 6; ++i)
{
  label("("+substr(l,i,1)+")",(x,min(p).y),3S,fontsize(10pt));
  x += w;
}


Official Asymptote example – label3zoom

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

Figure 0109
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import three;

currentlight=Headlamp;
size(469.75499pt,0);

currentprojection=perspective(
camera=(160.119024441391,136.348802919248,253.822628496226),
up=(-0.188035408976828,0.910392236102215,-0.368549401594584),
target=(25.5462739598034,1.77605243766079,-9.93996244768584),
zoom=5.59734733413271,
angle=5.14449021168139,
viewportshift=(0.813449720559684,-0.604674743165144),
autoadjust=false);

draw(scale3(4)*extrude("$\displaystyle\int\limits_{-\infty}^{+\infty}\!\! e^{-\alpha x^2}\!\!=\sqrt{\frac{\pi}{\alpha}}$",2Z),
     material(blue,ambientpen=mediumgray));


Official Asymptote example – exp3

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

Figure 0059
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;

size(12cm,IgnoreAspect);
currentprojection=orthographic(1,-2,1);

real f(pair z) {return abs(exp(z));}

real Arg(triple v) {return degrees(exp((v.x,v.y)),warn=false);}

surface s=surface(f,(-2,-pi),(2,pi),20,Spline);

s.colors(palette(s.map(Arg),Wheel()));
draw(s,render(compression=Low,merge=true));

real xmin=point((-1,-1,-1)).x;
real xmax=point((1,1,1)).x;
draw((xmin,0,0)--(xmax,0,0),dashed);

xaxis3("$\mathop{\rm Re} z$",Bounds,InTicks);
yaxis3("$\mathop{\rm Im} z$",Bounds,InTicks(beginlabel=false));
zaxis3("$|\exp(z)|$",Bounds,InTicks);


Official Asymptote example – cos3

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

Figure 0037
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import graph3;
import palette;

size(12cm,IgnoreAspect);
currentprojection=orthographic(1,-2,1);

real f(pair z) {return abs(cos(z));}

real Arg(triple v) {return degrees(cos((v.x,v.y)),warn=false);}

surface s=surface(f,(-pi,-2),(pi,2),20,Spline);

s.colors(palette(s.map(Arg),Wheel()));
draw(s,render(compression=Low,merge=true));

real xmin=point((-1,-1,-1)).x;
real xmax=point((1,1,1)).x;
draw((xmin,0,0)--(xmax,0,0),dashed);

xaxis3("$\mathop{\rm Re} z$",Bounds,InTicks);
yaxis3("$\mathop{\rm Im} z$",Bounds,InTicks(beginlabel=false));
zaxis3("$|\cos(z)|$",Bounds,InTicks);





Official Asymptote example – clockarray

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

Figure 0026
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
int nx=3;
int ny=4;
real xmargin=1cm;
real ymargin=xmargin;

size(settings.paperwidth,settings.paperheight);

picture pic;
real width=settings.paperwidth/nx-xmargin;
real height=settings.paperheight/ny-ymargin;
if(width <= 0 || height <= 0) abort("margin too big");
size(pic,width,height);

pen p=linewidth(0.5mm);
draw(pic,unitcircle,p);

real h=0.08;
real m=0.05;

for(int hour=1; hour <= 12; ++hour) {
  pair z=dir((12-hour+3)*30);
  label(pic,string(hour),z,z);
  draw(pic,z--(1-h)*z,p);
}

for(int minutes=0; minutes < 60; ++minutes) {
  pair z=dir(6*minutes);
  draw(pic,z--(1-m)*z);
}

dot(pic,(0,0));

frame f=pic.fit();
pair size=size(f)+(xmargin,ymargin);

for(int i=0; i < nx; ++i)
  for(int j=0; j < ny; ++j)
    add(shift(realmult(size,(i,j)))*f);



Official Asymptote example – cards

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

Figure 0021
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
picture rect;

size(rect,0,2.5cm);

real x=1;
real y=1.25;

filldraw(rect,box((-x,-y)/2,(x,y)/2),lightolive);

label(rect,"1",(-x,y)*0.45,SE);
label(rect,"2",(x,y)*0.45,SW);
label(rect,"3",(-x,-y)*0.45,NE);
label(rect,"4",(x,-y)*0.45,NW);

frame rectf=rect.fit();
frame toplef=rectf;
frame toprig=xscale(-1)*rectf;
frame botlef=yscale(-1)*rectf;
frame botrig=xscale(-1)*yscale(-1)*rectf;

size(0,7.5cm);

add(toplef,(-x,y));
add(toprig,(x,y));
add(botlef,(-x,-y));
add(botrig,(x,-y));


Official Asymptote example – billboard

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

Figure 0014
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import three;

size(100);

currentprojection=perspective(1,-2,1);

draw(unitbox);

label("Billboard",X,red,Billboard);
label("Embedded",Y,blue,Embedded);

Mots-clefs :


Official Asymptote example – bigdiagonal

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

Figure 0013
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
size(0,100.5);
draw((0,0)--(2,1),Arrow);