## Asymptote Generalities – fig0580

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
// 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);
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));

```

Étiquettes : , , , , ,

## Asymptote Generalities – fig0990

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(4cm,0);

//Return Circle AB diameter
path circle(pair A, pair B)
{
return shift(midpoint(A--B))*scale(abs(A-B)/2)*unitcircle;
}

pair A=(0,0), B=(1,0), C=(2,0);
path cleAB=circle(A,B);
path cleAC=circle(A,C);

for(real t=0; t<length(cleAB); t+=0.01)
fill(circle(point(cleAB,t),point(cleAC,t)));

```

Étiquettes : , , , , ,

## Asymptote Generalities – fig1020

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(4cm,0);

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

```

Étiquettes : , , ,

## Asymptote Generalities – fig1030

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(4cm,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);

```

Étiquettes : , , , ,

## Asymptote Generalities – fig1040

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(4cm,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);

```

Étiquettes : , , , , , , ,

## Asymptote Generalities – fig1240

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
//Translate from Troy Henderson Metapost code.
size(8cm);
draw(unitcircle, linewidth(bp));
pen p;
for (int t=-88; t <= 88; t += 2) {
if(t%5 == 0) {
p=linewidth(bp);
draw((0,1){dir (t-90)}..{dir (270-t)}(0,-1), linewidth(bp));
} else p=currentpen;
draw((Cos(t),Sin(t)){dir(180+t)}..{dir(180-t)}(-Cos(t),Sin(t)), p);
}

```

Étiquettes : , ,

## Asymptote Generalities – fig1360

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(0,0);

path cle=scale(2cm)*unitcircle;

draw(cle);

for(real i=0; i<=length(cle); i+=.2)
{
dot(point(cle,i));
draw((0,0)--point(cle,i),dotted);
}

```

Étiquettes : , , , , ,

## Asymptote Generalities – fig1370

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(0,0);

path cle=scale(2cm)*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);

```

Étiquettes : , , , , ,

## Asymptote Generalities – fig1380

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(0,0);

path cle=scale(2cm)*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);

```

Étiquettes : , , , , ,

## Asymptote Generalities – fig1400

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(0,0);

path cle=scale(2cm)*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);

```

Étiquettes : , , , ,

## Asymptote Generalities – fig1420

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
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);

```

Étiquettes : , , , ,

## Asymptote Generalities – fig1430

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
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);

```

Étiquettes : , , ,

## Asymptote Generalities – fig1480

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(0,0);

path p= (5mm,-5mm){right} .. (2cm,0);

for(int i=10; i<360; i+=10)
draw(rotate(i)*p);

draw(p,red+1mm);

```

Étiquettes : , , ,

## Asymptote Generalities – fig1490

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(4cm,0);

path p= (1,-1){right} .. (4,0);
pair O=(3,.25);

for(int i=10; i<360; i+=10)
draw(rotate(i,O)*p);

dot(O,blue);
draw(p,red+1mm);

```

Étiquettes : , , ,

## Asymptote Generalities – fig1540

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
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));

```

Étiquettes : , , ,

## Asymptote Generalities – fig1550

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
//Translate from http://zoonek.free.fr/LaTeX/Metapost/metapost.html
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]));
}

```

Étiquettes : , , , ,

## Asymptote Generalities – fig1560

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
//Translate from http://zoonek.free.fr/LaTeX/Metapost/metapost.html
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]);
}

draw(P[2] -- P[3] -- P[4] -- P[0] -- P[1] --
R[0] -- Q[0] -- R[4] -- Q[4] -- R[3]
-- Q[3] -- R[2] -- Q[2] --
S[2] -- S[3] -- S[4] -- S[0] -- S[1] --
Q[1] -- R[1] -- cycle,
linewidth(2bp));

```

Étiquettes : , ,

## Asymptote Generalities – fig1570

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
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];

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

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

P[6]=P[1];
for (int i=0; i<=4; ++i)
{
lightgrey,(0,0),abs(R[i]),
black,(0,0),abs(S[i]));
.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));

```

Étiquettes : , , ,

## Asymptote Generalities – fig1620

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
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);

```

Étiquettes : , , , ,

## Asymptote Generalities – fig1770

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

 (Compiled with Asymptote version 2.14svn-r5318)
```
size(6cm,0);

import math;

pair A=(0,0), B=(1,.5);
path cle=shift(1.75,2.5)*unitcircle;
pair pt, ptp;

pair project(pair pt, pair A, pair B)
{
return extension(pt,pt-dir(90+degrees(A-B,false)),A,B);
}

draw(A--B);
draw(cle);

for (real t=0; t<=4; t+=.01)
{
pt=point(cle,t);
ptp=project(pt,A,B);
dot(ptp, red);
draw(pt--ptp,dotted);

}

```

É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 – fig0110

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 7 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
/* Explanations HERE */
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)));

```

Étiquettes : , , , , ,

## Fractals with Asymptote – fig0120

Category: Asymptote,Examples 2D,FractalsPh. Ivaldi @ 8 h 53 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
/* Explanations HERE */
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)));

```

Étiquettes : , , , , ,

## Random walk in the space – fig0010

Category: Asymptote,Examples 3D,Random Walk (3D)Ph. Ivaldi @ 11 h 46 min

 (Compiled with Asymptote version 1.84svn-r4619)
```
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));

```

Étiquettes : , , ,

## Official Asymptote example – lines

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

int n=7;

size(200,0);

draw(unitcircle,red);
for (int i=0; i < n-1; ++i)
for (int j=i+1; j < n; ++j)
drawline(unityroot(n,i),unityroot(n,j),blue);

```

Étiquettes : , ,

## Official Asymptote example – star

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

size(100);
import math;

int n=5;
path p;

int i=0;
do {
p=p--unityroot(n,i);
i=(i+2) % n;
} while(i != 0);

filldraw(p--cycle,red+evenodd);

```

Étiquettes : , , , ,

## Various code with Asymptote – fig0100

Category: Asymptote,MiscellaneousPh. Ivaldi @ 21 h 11 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
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]);

```

Étiquettes : , ,

## Various code with Asymptote – fig0200

Category: Asymptote,MiscellaneousPh. Ivaldi @ 22 h 11 min

 (Compiled with Asymptote version 1.87svn-r4652)
```
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));
}

```

Étiquettes : , , ,