Official Asymptote example – graphmarkers

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;

size(200,100,IgnoreAspect);

markroutine marks() {
return new void(picture pic=currentpicture, frame f, path g) {
path p=scale(1mm)*unitcircle;
for(int i=0; i <= length(g); ++i) {
pair z=point(g,i);
frame f;
if(i % 4 == 0) {
fill(f,p);
} else {
if(z.y > 50) {
pic.add(new void(frame F, transform t) {
path q=shift(t*z)*p;
unfill(F,q);
draw(F,q);
});
} else {
draw(f,p);
}
}
}
};
}

pair[] f={(5,5),(40,20),(55,51),(90,30)};

draw(graph(f),marker(marks()));

scale(true);

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



Mots-clefs : ,

Official Asymptote example – generalaxis3

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

import graph3;

size(0,100);

path3 g=yscale3(2)*unitcircle3;
currentprojection=perspective(10,10,10);

axis(Label("C",position=0,align=15X),g,InTicks(endlabel=false,8,end=false),
ticklocate(0,360,new real(real v) {
path3 h=O--max(abs(max(g)),abs(min(g)))*dir(90,v);
return intersect(g,h)[0];},
new triple(real t) {return cross(dir(g,t),Z);}));



Mots-clefs : ,

Official Asymptote example – generalaxis

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

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

import graph;
size(0,100);

path g=ellipse((0,0),1,2);

scale(true);

axis(Label("C",align=10W),g,LeftTicks(endlabel=false,8,end=false),
ticklocate(0,360,new real(real v) {
path h=(0,0)--max(abs(max(g)),abs(min(g)))*dir(v);
return intersect(g,h)[0];}));



Mots-clefs : ,

Official Asymptote example – gamma3

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

 (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 X=4.5;
real M=abs(gamma((X,0)));

pair Gamma(pair z)
{
return (z.x > 0 || z != floor(z.x)) ? gamma(z) : M;
}

real f(pair z) {return min(abs(Gamma(z)),M);}

surface s=surface(f,(-2.1,-2),(X,2),70,Spline);

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

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("$|\Gamma(z)|$",Bounds,InTicks);



Mots-clefs : , , , ,

Official Asymptote example – gamma

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

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

import graph;
size(300,IgnoreAspect);

bool3 branch(real x)
{
static int lastsign=0;
if(x <= 0 && x == floor(x)) return false;
int sign=sgn(gamma(x));
bool b=lastsign == 0 || sign == lastsign;
lastsign=sign;
return b ? true : default;
}

draw(graph(gamma,-4,4,n=2000,branch),red);

scale(false);
xlimits(-4,4);
ylimits(-6,6);
crop();

xaxis("$x$",RightTicks(NoZero));
yaxis(LeftTicks(NoZero));

label("$\Gamma(x)$",(1,2),red);



Mots-clefs : ,

Official Asymptote example – galleon

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

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

import obj;

size(15cm);
currentprojection=orthographic(0,2,5,up=Y);

// A compressed version of the required data file may be obtained from:
// http://www.cs.technion.ac.il/~irit/data/Viewpoint/galleon.obj.gz

pen[] surfacepen={darkred,brown,darkred+orange,heavyred,heavyred,darkred+orange,
palegreen+blue+lightgrey,darkred,darkred,yellow,darkred,white,
white,white,white,white,white};
surfacepen.cyclic=true;

draw(obj("galleon.obj",verbose=false,surfacepen));



Mots-clefs : , ,

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

settings.tex="pdflatex";

// PostScript Calculator routine to convert from [0,1]x[0,1] to RG:
string redgreen="0";

// PostScript Calculator routine to convert from [0,1]x[0,1] to HS to RGB:
string hsv="0.5 sub exch 0.5 sub exch
2 copy 2 copy 0 eq exch 0 eq and { pop pop 0.0 } {atan 360.0 div}
ifelse dup 360 eq { pop 0.0 }{} ifelse 3 1 roll dup mul exch dup mul add
sqrt 2.5 mul 0.25 sub 1 1 index 1.0
eq { 3 1 roll pop pop dup dup } { 3 -1 roll 6.0 mul dup 4 1 roll floor dup
5 1 roll 3 index sub neg 1.0 3 index sub 2 index mul 6 1 roll dup 3 index
mul neg 1.0 add 2 index mul 7 1 roll neg 1.0 add 2 index mul neg 1.0 add 1
index mul 7 2 roll pop pop dup 0 eq { pop exch pop } { dup 1 eq { pop exch
4 1 roll exch pop } { dup 2 eq { pop 4 1 roll pop } { dup 3 eq { pop exch 4
2 roll pop } { dup 4 eq { pop exch pop 3 -1 roll } { pop 3 1 roll exch pop
} ifelse } ifelse } ifelse } ifelse } ifelse } ifelse cvr 3 1 roll cvr 3 1
roll cvr 3 1 roll";

path p=unitcircle;
layer();
draw(p);

path g=shift(2*dir(-45))*p;
layer();
draw(g);



Mots-clefs :

Official Asymptote example – fractaltree

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

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

size(200);

path ltrans(path p,int d)
{
path a=rotate(65)*scale(0.4)*p;
return shift(point(p,(1/d)*length(p))-point(a,0))*a;
}
path rtrans(path p, int d)
{
path a=reflect(point(p,0),point(p,length(p)))*rotate(65)*scale(0.35)*p;
return shift(point(p,(1/d)*length(p))-point(a,0))*a;
}

void drawtree(int depth, path branch)
{
if(depth == 0) return;
real breakp=(1/depth)*length(branch);
draw(subpath(branch,0,breakp),deepgreen);
drawtree(depth-1,subpath(branch,breakp,length(branch)));
drawtree(depth-1,ltrans(branch,depth));
drawtree(depth-1,rtrans(branch,depth));
return;
}

path start=(0,0)..controls (-1/10,1/3) and (-1/20,2/3)..(1/20,1);
drawtree(6,start);



Mots-clefs : ,

Official Asymptote example – flowchartdemo

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

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

size(0,300);

import flowchart;

block block1=rectangle(Label("Example",magenta),
pack(Label("Start:",heavygreen),"",Label("$A:=0$",blue),
"$B:=1$"),(-0.5,3),palegreen,paleblue,red);
block block2=diamond(Label("Choice?",blue),(0,2),palegreen,red);
block block3=roundrectangle("Do something",(-1,1));
block block4=bevel("Don't do something",(1,1));
block block5=circle("End",(0,0));

draw(block1);
draw(block2);
draw(block3);
draw(block4);
draw(block5);

add(new void(picture pic, transform t) {
blockconnector operator --=blockconnector(pic,t);
//    draw(pic,block1.right(t)--block2.top(t));
block1--Right--Down--Arrow--block2;
block2--Label("Yes",0.5,NW)--Left--Down--Arrow--block3;
block2--Right--Label("No",0.5,NE)--Down--Arrow--block4;
block4--Down--Left--Arrow--block5;
block3--Down--Right--Arrow--block5;
});



Mots-clefs :

Official Asymptote example – flow

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 graph;
defaultpen(1.0);

size(0,150,IgnoreAspect);

real arrowsize=4mm;
real arrowlength=2arrowsize;

typedef path vector(real);

// Return a vector interpolated linearly between a and b.
vector vector(pair a, pair b) {
return new path(real x) {
return (0,0)--arrowlength*interp(a,b,x);
};
}

real f(real x) {return 1/x;}

real epsilon=0.5;
path g=graph(f,epsilon,1/epsilon);

int n=3;
draw(g);
xaxis("$x$");
yaxis("$y$");