vardef TEX primary s =
write "verbatimtex" to "mptextmp.mp";
write "\documentclass[12pt]{article}" to "mptextmp.mp";
write "\usepackage[T1]{fontenc}" to "mptextmp.mp";
write "\usepackage{amsmath,amssymb}" to "mptextmp.mp";
write "\begin{document}" to "mptextmp.mp";
write "etex" to "mptextmp.mp";
write "btex "&s&" etex" to "mptextmp.mp";
write EOF to "mptextmp.mp";
scantokens "input mptextmp"
enddef;
vardef longueur(expr p) =
save l,i;
numeric l;
l:=0;
for i=0 step .01 until length(p):
l:=l+abs( (point i of p) - (point(i+.01) of p) );
endfor;
l % Pas de point-virgule
enddef;
vardef milieu(expr p) =
save l,i,tot,A,B;
numeric l,tot,i;
pair A,B;
tot := longueur(p);
l:=0;
B := point 0 of p;
for i:=0 step .01 until length(p):
A := B;
B := point i of p;
l := l+abs(B-A);
exitif l > 1/2 tot;
endfor;
show l; show tot;
1/2[A,B]
enddef;
vardef milieu_time(expr p) =
save l,i,tot,A,B,t;
numeric l,tot,i,t;
pair A,B;
tot := longueur(p);
l:=0;
B := point 0 of p;
for i:=0 step .01 until length(p):
t:=i;
A := B;
B := point i of p;
l := l+abs(B-A);
exitif l > 1/2 tot;
endfor;
t
enddef;
beginfig(1)
pair A, B, C;
A:=(0,0); B:=(1cm,0); C:=(0,1cm);
draw A--B--C;
endfig;
beginfig(21)
pair A, B, C;
A:=(0,0); B:=(1cm,0); C:=(0,1cm);
fill A--B--C--cycle withcolor .8 white;
draw A--B--C--cycle;
endfig;
beginfig(22)
pair A, B, C;
A:=(0,0); B:=(1cm,0); C:=(0,1cm);
fill A--B--C--cycle withcolor .8 white;
draw A--B--C--cycle withpen pencircle scaled 2bp;
endfig;
beginfig(23)
pair A, B, C;
A:=(0,0); B:=(1cm,0); C:=(0,1cm);
draw A--B--C--cycle withpen pencircle scaled 2bp;
fill A--B--C--cycle withcolor .8 white;
endfig;
beginfig(24)
pair A, B, C, D;
A:=(0,0); B:=(1cm,0);
C:=(1cm,1cm); D:=(0,1cm);
fill A--C--B--D--cycle withcolor .8white;
endfig;
beginfig(25)
pair A, B, C, D;
A:=(0,0); B:=(1cm,0);
C:=(1cm,1cm); D:=(0,1cm);
path p;
p := A--C--B--D--cycle;
fill p withcolor .8white;
draw p;
endfig;
beginfig(26)
pair A, B, C, D;
A:=(-1.5cm,-1.5cm); B:=(1.5cm,-1.5cm);
C:=(1.5cm,1.5cm); D:=(-1.5cm,1.5cm);
fill A--C--B--D--cycle withcolor .8white;
draw (-1.5cm,0)--(1.5cm,0);
draw (0,-1.5cm)--(0,1.5cm);
drawarrow (0,0)--(1cm,0)
withpen pencircle scaled 2bp;
drawarrow (0,0)--(0,1cm)
withpen pencircle scaled 2bp;
endfig;
beginfig(27)
pair A;
A := (0,0);
draw A withpen pencircle scaled 4bp;
label.top(btex Au dessus etex, A);
label.bot(btex En dessous etex, A);
label.rt (btex � droite etex, A);
label.lft(btex � gauche etex, A);
endfig;
beginfig(28)
pair A;
A := (0,0);
draw A withpen pencircle scaled 4bp;
label.ulft(btex En haut � gauche etex, A);
label.urt (btex En haut � droite etex, A);
label.llft(btex En bas � gauche etex, A);
label.lrt (btex En bas � droite etex, A);
endfig;
beginfig(61)
pair A, B, C, D;
A = (0,0);
D = (2u,0);
B = (-u,2u);
C = (3u,3u);
draw A withpen pencircle scaled 4bp;
draw B withpen pencircle scaled 4bp;
draw C withpen pencircle scaled 4bp;
draw D withpen pencircle scaled 4bp;
draw A .. controls B and C .. D;
endfig;
beginfig(68)
pair A,B,C,D;
xpart A = ypart A = ypart B = xpart C = 0;
xpart B = ypart C = xpart D = ypart D = 2cm;
draw A--B--C--D--cycle withpen pencircle scaled 2bp;
endfig;
beginfig(69)
pair A,B,C,D,M;
numeric lambda, mu;
A=(0,0); B=(2cm,3cm);
C=(1cm,0); D=(-1cm,2cm);
M = lambda [A,B];
M = mu [C,D];
draw A--B;
draw C--D;
draw M withpen pencircle scaled 4bp;
endfig;
beginfig(70)
pair A,B,C,D,M;
A=(0,0); B=(2cm,3cm);
C=(1cm,0); D=(-1cm,2cm);
M = whatever [A,B];
M = whatever [C,D];
draw A--B;
draw C--D;
draw M withpen pencircle scaled 4bp;
endfig;
beginfig(71)
pair A,B,C,AA,BB,CC,G;
A=(0,0); B=(3cm,0); C=(1cm,2cm);
AA = 1/2 [B,C];
BB = 1/2 [C,A];
CC = 1/2 [A,B];
G = whatever [A,AA];
G = whatever [B,BB];
draw A--B--C--cycle;
draw A--AA dashed withdots;
draw B--BB dashed withdots;
draw C--CC dashed withdots;
draw G withpen pencircle scaled 4bp;
endfig;
beginfig(72)
path p;
p := fullcircle scaled 5mm;
draw p;
draw p shifted (1mm,2mm);
draw p shifted 2(1mm,2mm);
draw p shifted 3(1mm,2mm);
draw p shifted 4(1mm,2mm);
draw p shifted 5(1mm,2mm);
endfig;
beginfig(73)
path p;
p := (5mm,-5mm) {right} .. (2cm,0);
draw p;
draw p rotated 10;
draw p rotated 20;
draw p rotated 30;
draw p rotated 40;
draw p rotated 50;
draw p rotated 60;
draw p rotated 70;
draw p rotated 80;
draw p rotated 90;
endfig;
beginfig(74)
path p;
p := fullcircle scaled 5mm;
draw p;
draw p xscaled 2;
draw p xscaled 3;
draw p xscaled 4;
endfig;
beginfig(75)
pair A,B,C,D,E;
A := (1cm,0);
B := A rotated 72;
C := B rotated 72;
D := C rotated 72;
E := D rotated 72;
draw A--B--C--D--E--cycle;
endfig;
beginfig(76)
pair A,B,C,D,E;
A := (1cm,0);
B := A rotated 72;
C := B rotated 72;
D := C rotated 72;
E := D rotated 72;
draw A--C--E--B--D--cycle;
endfig;
beginfig(77)
pair A,B,C,D,E;
A := (1cm,0);
B := A rotated 72;
C := B rotated 72;
D := C rotated 72;
E := D rotated 72;
pair AA, BB, CC, DD, EE;
AA = whatever [A, C];
AA = whatever [B, D];
BB = whatever [B, D];
BB = whatever [C, E];
CC = whatever [C, E];
CC = whatever [D, A];
DD = whatever [D, A];
DD = whatever [E, B];
EE = whatever [E, B];
EE = whatever [A, C];
fill A--C--E--B--D--cycle withcolor .8white;
fill AA--BB--CC--DD--EE--cycle withcolor white;
draw A--C--E--B--D--cycle;
endfig;
beginfig(78)
path p;
p := (0,0) -- (1cm,0);
drawarrow p withpen pencircle scaled 2bp;
drawarrow p zscaled (1,2);
endfig;
beginfig(79)
u:=1cm;
path p; p := (0,0) -- (u,0);
pair A; A := (u,-u);
numeric a; a := 90;
drawarrow p withpen pencircle scaled 1bp;
drawarrow p rotatedaround( A, a );
drawarrow p shifted -A rotated a shifted A
withpen pencircle scaled 1bp dashed withdots;
endfig;
beginfig(80)
path p; p := (0,0) -- (u,0);
pair A; A := (u,-u);
numeric a; a := 90;
drawarrow p withpen pencircle scaled 1bp;
draw A withpen pencircle scaled 4bp;
label ulft ( btex $A$ etex, A );
draw (0,0) withpen pencircle scaled 4bp;
label bot ( btex $O$ etex, (0,0) );
for i=0 upto 10:
drawarrow p shifted -(i*A/10) withcolor red;
endfor;
for i=0 upto 10:
drawarrow p shifted -A rotated (i*a/10) withcolor green;
endfor;
for i=0 upto 10:
drawarrow p shifted -A rotated a shifted (i*A/10) withcolor blue;
endfor;
endfig;
beginfig(81)
pair A,B,C,AA,BB,CC,H;
A=(0,0); B=(3cm,0); C=(1cm,2cm);
AA - A = whatever * (B-C) rotated 90;
AA = whatever [B,C];
BB - B = whatever * (A-C) rotated 90;
BB = whatever [A,C];
CC - C = whatever * (A-B) rotated 90;
CC = whatever [A,B];
H = whatever [A,AA];
H = whatever [B,BB];
draw A--B--C--cycle;
draw A--AA;
draw B--BB;
draw C--CC;
draw H withpen pencircle scaled 4bp;
endfig;
beginfig(82)
pair A,B,C,H;
A=(0,0); B=(3cm,0); C=(1cm,2cm);
H - A = whatever * (B-C) rotated 90;
H - B = whatever * (A-C) rotated 90;
draw A--B--C--cycle;
draw H withpen pencircle scaled 4bp;
endfig;
beginfig(83)
pair A,B,C,O;
A=(0,0); B=(3cm,0); C=(1cm,2cm);
O - 1/2[B,C] = whatever * (B-C) rotated 90;
O - 1/2[A,B] = whatever * (A-B) rotated 90;
draw A--B--C--cycle;
draw O withpen pencircle scaled 4bp;
draw fullcircle scaled 2abs(O-A) shifted O;
endfig;
beginfig(84)
pair A,B,C,D;
u:=2cm;
A=(0,0); B=(u,0); C=(u,u); D=(0,u);
transform T;
A transformed T = 1/5[A,B];
B transformed T = 1/5[B,C];
C transformed T = 1/5[C,D];
path p;
p = A--B--C--D--cycle;
draw p;
draw p transformed T;
transform T;
A transformed T = 1/5[A,B];
B transformed T = 1/5[B,C];
C transformed T = 1/5[C,D];
path p;
p = A--B--C--D--cycle;
for i=0 upto 100:
draw p;
p:= p transformed T;
endfor;
endfig;
beginfig(86)
u:=1cm;
pair A,B,C,D,E;
A := (0,u);
B := A rotated 72;
C := B rotated 72;
D := C rotated 72;
E := D rotated 72;
transform T;
A transformed T = 1/5[A,B];
B transformed T = 1/5[B,C];
C transformed T = 1/5[C,D];
path p;
p := A--B--C--D--E--cycle;
draw p;
p := p transformed T; draw p;
p := p transformed T; draw p;
p := p transformed T; draw p;
endfig;
beginfig(87)
u:=3mm;
fill fullcircle scaled 2u withcolor .8white;
fill fullcircle scaled u shifted (u*dir30)
withcolor .8white;
fill fullcircle scaled u shifted (u*dir150)
withcolor .8white;
endfig;
beginfig(88)
u:=3mm;
transform T;
(0,0) transformed T = (0,0);
(1,0) transformed T = (1,1);
(0,1) transformed T = (1,0);
fill fullcircle scaled 2u transformed T withcolor .8white;
fill fullcircle scaled u shifted (u*dir30) transformed T
withcolor .8white;
fill fullcircle scaled u shifted (u*dir150) transformed T
withcolor .8white;
endfig;
beginfig(89)
u:=3mm;
transform T;
xpart T = ypart T = 0;
xxpart T = 1;
yxpart T = 2;
xypart T = 3;
yypart T = 4;
fill fullcircle scaled 2u transformed T withcolor .8white;
fill fullcircle scaled u shifted (u*dir30) transformed T
withcolor .8white;
fill fullcircle scaled u shifted (u*dir150) transformed T
withcolor .8white;
endfig;
beginfig(90)
draw fullcircle scaled 1cm;
draw fullcircle scaled 5mm shifted (1cm*dir45);
draw fullcircle scaled 5mm shifted (1cm*dir135);
picture mypicture;
mypicture := currentpicture;
currentpicture := nullpicture;
draw mypicture;
draw mypicture shifted (1mm,1mm);
draw mypicture shifted (2mm,2mm);
endfig;
beginfig(101)
pair A,B;
A:=(1cm,2cm); B:=(2cm,1cm);
numeric alpha;
alpha = angle(A) - angle(B);
drawarrow origin--A;
drawarrow origin--B;
drawarrow (origin--A) rotated -1/3 alpha;
drawarrow (origin--A) rotated -2/3 alpha;
drawarrow (origin--A) rotated -alpha;
endfig;
beginfig(102)
pair A,B,C;
A=(0,0); B=(3cm,0); C=(1cm,2cm);
draw A--B--C--cycle;
label.llft(TEX decimal(angle(C-A)-angle(B-A)), A);
label.lrt(TEX decimal(angle(A-B)-angle(C-B)), B);
label.urt(TEX decimal(angle(B-C)-angle(A-C)), C);
endfig;
beginfig(103)
pair A,AA,B,BB,C,CC,O,H;
A=(0,0); B=(3cm,0); C=(1cm,2cm);
AA = 1/2[B,C];
BB = 1/2[A,C];
CC = 1/2[A,B];
O - 1/2[BB,CC] = whatever * (BB-CC) rotated 90;
O - 1/2[AA,BB] = whatever * (AA-BB) rotated 90;
draw A--B--C--cycle;
draw AA withpen pencircle scaled 4bp;
draw BB withpen pencircle scaled 4bp;
draw CC withpen pencircle scaled 4bp;
draw fullcircle scaled 2abs(O-AA) shifted O;
% Il faut aussi tracer les hauteurs
pair AA,BB,CC;
AA - A = whatever * (B-C) rotated 90;
AA = whatever [B,C];
BB - B = whatever * (A-C) rotated 90;
BB = whatever [A,C];
CC - C = whatever * (A-B) rotated 90;
CC = whatever [A,B];
draw A--AA; draw B--BB; draw C--CC;
draw AA withpen pencircle scaled 4bp;
draw BB withpen pencircle scaled 4bp;
draw CC withpen pencircle scaled 4bp;
% Il passe aussi par le milieu de HA, HB, HC
H = whatever [A,AA];
H = whatever [B,BB];
draw 1/2 [A,H] withpen pencircle scaled 4bp;
draw 1/2 [B,H] withpen pencircle scaled 4bp;
draw 1/2 [C,H] withpen pencircle scaled 4bp;
endfig;
beginfig(104)
pair A,B,C,M,h;
u:=2cm;
A=(0,0); B=(2u,-.5u); C=(u,u);
draw A--B--C--cycle;
(M-A) = whatever * (
(A-C) rotated 1/2( angle(B-A) - angle(C-A)) );
(M-B) = whatever * (
(B-A) rotated 1/2( angle(C-B) - angle(A-B)) );
draw M--A; draw M--B; draw M--C;
M-h = whatever * (B-C) rotated 90;
h = whatever[B,C];
draw fullcircle scaled 2 abs(M-h) shifted M;
endfig;
beginfig(105)
path p;
p = (0,0){up} .. (2cm,0){down};
draw p;
draw point 0 of p withpen pencircle scaled 4bp;
draw point .5 of p withpen pencircle scaled 4bp;
draw point 1 of p withpen pencircle scaled 4bp;
endfig;
beginfig(106)
path p;
p = (0,0){up} .. (2cm,0){down};
draw p;
pair A;
A := point 0 of p;
B := A + 1cm*unitvector(direction 0 of p);
drawarrow A--B withpen pencircle scaled 1bp;
A := point .5 of p;
B := A + 1cm*unitvector(direction .5 of p);
drawarrow A--B withpen pencircle scaled 1bp;
A := point 1 of p;
B := A + 1cm*unitvector(direction 1 of p);
drawarrow A--B withpen pencircle scaled 1bp;
endfig;
beginfig(107)
u:=5mm;
path p;
p = (0,0) {curl 0} .. (u,2u) .. (2u,1.5u)
.. (3u,2u) .. {curl 0} (4u,0);
draw subpath(0,1) of p withcolor red;
draw subpath(1,2) of p withcolor green;
draw subpath(2,3) of p withcolor blue;
draw subpath(3,3.5) of p dashed evenly;
draw subpath(3.5,4) of p dashed withdots;
endfig;
beginfig(108)
u:=1cm;
path p,q;
p := (0,0){up} .. (u,2u){up};
q := (u,0){up} .. (0,2u){up};
draw p;
draw subpath(0,.4) of q withpen pencircle scaled 1bp;
draw subpath(.6,1) of q withpen pencircle scaled 1bp;
endfig;
beginfig(109)
u:=1cm;
path a,b,c,d;
a = (-u,-.2u){up} .. tension 1.2 .. (u,-.2u){down};
b = a rotated 90;
c = b rotated 90;
d = c rotated 90;
fill buildcycle(a,b,c,d) withcolor .8white;
draw a; draw b; draw c; draw d;
endfig;
beginfig(110)
u:=1cm;
path c[];
c[1] := fullcircle scaled u;
c[2] := c[1] shifted (0,.5u);
draw c[1] dashed evenly;
draw c[2] dashed evenly;
draw buildcycle(c[1],c[2]) withpen pencircle scaled 1bp;
endfig;
beginfig(111)
path a,b,c;
a = fullcircle scaled 2u shifted (.5u,0);
b = a rotated (360/3);
c = b rotated (360/3);
fill a withcolor red;
fill b withcolor green;
fill c withcolor blue;
fill buildcycle(a,b) withcolor red + green;
fill buildcycle(b,c) withcolor green + blue;
fill buildcycle(c,a) withcolor blue + red;
fill buildcycle(a,b,c) withcolor white;
draw a; draw b; draw c;
endfig;
beginfig(112)
def compute_curve(suffix f)(expr xmin, xmax, xinc) =
( (xmin,f(xmin))
for x=xmin+xinc step xinc until xmax:
.. (x,f(x))
endfor )
enddef;
vardef f(expr x) = x**2 + 1 enddef;
vardef g(expr x) = 2 - (x-1)**2 enddef;
path p, q;
p := compute_curve(f, -1, 1.5, .1) scaled 1cm;
q := compute_curve(g, -.5, 2, .1) scaled 1cm;
fill buildcycle(p,reverse q) withcolor red+green;
draw p withpen pencircle scaled 1bp;
draw q withpen pencircle scaled 1bp;
draw (-1cm,0) -- (2cm,0);
draw (0,g(-.5)*1cm) -- (0,f(1.5)*1cm);
endfig;
beginfig(113)
path p, q;
p = (0,0){up} .. (2cm,0){up};
q = (0,1cm){dir -60}..(1cm,-1cm)..{dir 60}(2cm,1cm);
draw p; draw q;
draw p intersectionpoint q withpen pencircle scaled 4bp;
endfig;
beginfig(114)
path p, q;
p = (0,0){up} .. (2cm,0){up};
q = (0,1cm){dir -60}..(1cm,-1cm)..{dir 60}(2cm,1cm);
draw p; draw q;
numeric a,b;
(a,whatever) = p intersectiontimes q;
draw point a of p withpen pencircle scaled 4bp;
endfig;
beginfig(115)
pair A,B;
path p;
A = (0,1cm);
B = A rotated 120;
p = A{dir 0} .. tension 2 .. B{dir 120};
numeric a;
(a,whatever) = p intersectiontimes (p rotated 120);
draw subpath(0,a-.02) of p;
draw subpath(a+.02,1) of p;
draw subpath(0,a-.02) of p rotated 120;
draw subpath(a+.02,1) of p rotated 120;
draw subpath(0,a-.02) of p rotated -120;
draw subpath(a+.02,1) of p rotated -120;
endfig;
beginfig(116)
u:=2cm;
pair A[], B[], C[], D[], E[];
path p[];
A[0] = u*up;
for i=1 upto 10:
A[i] := A[i-1] rotated 72;
endfor;
for i=0 upto 4:
p[i] := A[i]--A[i+1];
draw p[i];
draw (point 1 of p[i]) --
( (point 1 of p[i]) + 4mm*unitvector(direction 1 of p[i]));
draw (point 0 of p[i]) --
( (point 0 of p[i]) - 4mm*unitvector(direction 0 of p[i]));
endfor
A = u*up;
p := (-.2)[ A, A rotated 72 ] -- (1.2)[ A, A rotated 72 ];
for i=0 upto 5:
draw p rotated 72i;
endfor;
B := 1/2[ A, A rotated 72 ];
C := .8*B;
p := B --- C .. (C rotated (2*72)){right};
% On allonge le chemin p
p := ( (point 0 of p) - 4mm*unitvector(direction 0 of p))
--
(point 0 of p)
& p &
(point 2 of p)
--
( (point 2 of p) + 4mm*unitvector(direction 2 of p));
E = p intersectionpoint (p rotated 72);
q := p cutbefore fullcircle scaled -2mm shifted E;
r := p cutafter fullcircle scaled 2mm shifted E;
for i=0 upto 4:
draw q rotated 72i;
draw r rotated 72i;
draw A rotated 72i withpen pencircle scaled 4bp;
draw B rotated 72i withpen pencircle scaled 4bp;
draw C rotated 72i withpen pencircle scaled 4bp;
endfor;
endfig;
beginfig(118)
for i=0 step 1 until 3:
draw 1cm*right rotated (i*90)
withpen pencircle scaled 4bp;
endfor;
endfig;
beginfig(119)
draw for i=0 step 1 until 3:
1cm*right rotated (i*90) --
endfor cycle;
endfig;
beginfig(120)
n:=5;
draw for i=0 step 1 until n-1:
1cm*up rotated (i*360/n) --
endfor cycle;
endfig;
beginfig(121)
n:=7;
draw for i=0 step 1 until n-1:
1cm*up rotated (i*360/n) --
endfor cycle;
endfig;
beginfig(122)
path p;
p = (0,0) .. (-1cm,2cm) .. (2cm,1cm) .. (1cm,0);
draw p;
n:=10;
for i=0 step 1 until n:
draw point (i/n*length(p)) of p
withpen pencircle scaled 4bp;
endfor;
endfig;
beginfig(123)
path p;
p = (0,0) .. (-1cm,2cm) .. (2cm,1cm) .. (1cm,0);
draw p;
n:=10;
for i=0 step length(p)/n until length(p):
drawarrow (point i of p) --
1cm * unitvector(direction i of p)
shifted point i of p;
endfor;
endfig;
beginfig(124)
u:=1cm;
draw (-2u,0)--(2u,0);
draw (0,-2u)--(0,2u);
for i=-2u step u until 2u:
draw (i,u/20)--(i,-u/20);
draw (u/20,i)--(-u/20,i);
endfor;
endfig;
beginfig(125)
u:=1cm;
draw (-2u,0)--(2u,0);
draw (0,-2u)--(0,2u);
for i=-2u step u until 2u:
draw (i,u/10)--(i,-u/10);
draw (u/10,i)--(-u/10,i);
endfor;
for i=-2u step u/5 until 2u:
draw (i,u/20)--(i,-u/20);
draw (u/20,i)--(-u/20,i);
endfor;
endfig;
beginfig(126)
u:=1cm;
draw (-2u,0)--(2u,0);
draw (0,-2u)--(0,2u);
for i=-2u step u until 2u:
draw (i,2u)--(i,-2u);
draw (2u,i)--(-2u,i);
endfor;
endfig;
beginfig(127)
u:=1cm;
draw (-2u,0)--(2u,0);
draw (0,-2u)--(0,2u);
for i=-2u step u until 2u:
draw (i,2u)--(i,-2u);
draw (2u,i)--(-2u,i);
endfor;
for i=-2u step u/5 until 2u:
draw (i,2u)--(i,-2u) withpen pencircle scaled .2bp;
draw (2u,i)--(-2u,i) withpen pencircle scaled .2bp;
endfor;
endfig;
beginfig(128)
u := 5mm;
% vardef est n�cessaire pour pouvoir passer f en argument
vardef f(expr x) = x**2 -.1 enddef;
def axes(expr xmin,xmax,ymin,ymax) =
draw ( (xmin,0) -- (xmax,0) ) scaled u;
draw ( (0,ymin) -- (0,ymax) ) scaled u;
enddef;
def courbe(suffix f)(expr xmin, xmax, M) =
draw ( ( xmin, f(xmin) )
for i=1 upto M:
-- ( xmin + (i/M)*(xmax - xmin), f( xmin + (i/M)*(xmax - xmin) ))
endfor ) scaled u;
enddef;
vardef newton(suffix f)(expr y, h, M) =
save x,t;
numeric x,t; x:=y;
for i=1 upto M:
t := x - f(x)/( (f(x+h) - f(x))/h );
draw ( (x,f(x)) -- (t,0) -- (t,f(t)) ) scaled u;
x := t;
endfor;
enddef;
axes(-.5,2,-.5,4);
courbe(f,-.5,2, 100);
newton(f, 2, .01, 10);
endfig;
beginfig(129)
transform T;
u:=1cm;
z0=(0,0); z1=(2u,0); z3 = z1 rotated 90; z2 = z1+z3;
z0 transformed T = .1[z0,z1];
z1 transformed T = .1[z1,z2];
z2 transformed T = .1[z2,z3];
path p;
p = z0--z1--z2--z3--cycle;
fill p withcolor .8*white;
fill p transformed T withcolor white;
endfig;
beginfig(130)
transform T;
u:=1cm;
z0=(0,0); z1=(2u,0); z3 = z1 rotated 90; z2 = z1+z3;
z0 transformed T = .1[z0,z1];
z1 transformed T = .1[z1,z2];
z2 transformed T = .1[z2,z3];
path p;
p = z0--z1--z2--z3--cycle;
for i=0 upto 100:
fill p withcolor .8*white;
p := p transformed T;
fill p withcolor white;
p := p transformed T;
endfor;
endfig;
beginfig(131)
transform T;
u:=1cm;
z1=(0,2u);
n := 5;
for i=1 upto n-1:
z[i+1] = z1 rotated (360*i/n);
endfor;
z1 transformed T = .1[z1,z2];
z2 transformed T = .1[z2,z3];
z3 transformed T = .1[z3,z4];
path p;
p = for i=1 upto n: z[i] -- endfor cycle;
for i=0 upto 100:
fill p withcolor .8*white;
p := p transformed T;
fill p withcolor white;
p := p transformed T;
endfor;
endfig;
beginfig(132)
u:=1cm;
pair A[];
numeric n; n:=7;
A[0] = (u,0);
for i=1 upto n-1:
A[i] = A[0] rotated (360/n*i);
endfor;
for i=0 upto n-1:
draw A[i] withpen pencircle scaled 4bp;
for j=0 upto n-1:
if i<>j: draw A[i]--A[j] fi;
endfor;
endfor;
endfig;
beginfig(133)
u:=2cm;
numeric n,m; n:=4; m:=5;
pair A[], B[];
for i=1 upto n-1: A[i+1]-A[i] = (0,.2u); endfor;
for j=1 upto m-1: B[j+1]-B[j] = (0,.2u); endfor;
(0,0) for i=1 upto n: + A[i] endfor = (0,0);
(0,0) for j=1 upto m: + B[j] endfor = (4u,0);
for i=1 upto n:
draw A[i] withpen pencircle scaled 4bp;
endfor;
for j=1 upto m:
draw B[j] withpen pencircle scaled 4bp;
endfor;
for i=1 upto n:
for j=1 upto m:
draw A[i]--B[j];
endfor;
endfor;
endfig;
beginfig(134)
u:=1cm;
numeric n,m; n:=3; m:=3;
pair A[], B[];
for i=1 upto n-1: A[i+1]-A[i] = (.5u,0); endfor;
for j=1 upto m-1: B[j+1]-B[j] = (.5u,0); endfor;
(0,0) for i=1 upto n: + A[i] endfor = (0,0);
(0,0) for j=1 upto m: + B[j] endfor = (0,4u);
for i=1 upto n:
draw A[i] withpen pencircle scaled 4bp;
endfor;
for j=1 upto m:
draw B[j] withpen pencircle scaled 4bp;
endfor;
for i=1 upto n:
for j=1 upto m:
draw A[i]--B[j];
endfor;
endfor;
endfig;
beginfig(135)
pair A[], B[];
numeric n; n:=6;
for i=0 upto n-1:
A[i] = 1cm * right rotated (i*360/n);
B[i] = 2cm * right rotated (i*360/n);
endfor;
A[n] = A[0]; B[n] = B[0];
for i=0 upto n-1:
draw A[i] -- A[i+1] -- B[i+1] -- B[i];
draw A[i] withpen pencircle scaled 4bp;
draw B[i] withpen pencircle scaled 4bp;
endfor;
endfig;
beginfig(136)
numeric n; n:=5;
pair O,A,B,C,D;
O = (0,0);
A = 1cm*up;
B = 2cm*up rotatedabout(A,30);
C = 2cm*up;
D = 2cm*up rotatedabout(A,-30);
for i=0 upto n-1:
draw (O--A--C) rotated (i*360/n);
draw (B--A--D) rotated (i*360/n);
draw A rotated (i*360/n) withpen pencircle scaled 4bp;
draw B rotated (i*360/n) withpen pencircle scaled 4bp;
draw C rotated (i*360/n) withpen pencircle scaled 4bp;
draw D rotated (i*360/n) withpen pencircle scaled 4bp;
endfor;
draw O withpen pencircle scaled 4bp;
endfig;
beginfig(137)
path p; u:=1cm;
p = fullcircle xscaled -u yscaled 3u;
draw p;
for i=2 step .5 until 6:
draw (point 2 of p){down} .. (point i of p);
endfor;
endfig;
beginfig(138)
pair P[], Q[], R[], S[];
u:=.5cm;
for i=0 upto 4:
P[i] = u* down rotated (i*360/5);
endfor;
P[5] = P[0];
for i=0 upto 4:
Q[i] = 3*( 1/2[ P[i], P[i+1] ] );
endfor;
Q[5] = Q[0];
for i=0 upto 4:
R[i] = 1/3( Q[i] + Q[i+1] + P[i+1] );
endfor;
R[5] = R[0];
for i=0 upto 5:
S[i] = 1.5*Q[i];
endfor;
for i=0 upto 4:
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];
endfor;
endfig;
beginfig(139)
pair P[], Q[], R[], S[];
u:=.5cm;
for i=0 upto 4:
P[i] = u* down rotated (i*360/5);
endfor;
P[5] = P[0];
for i=0 upto 4:
Q[i] = 3*( 1/2[ P[i], P[i+1] ] );
endfor;
Q[5] = Q[0];
for i=0 upto 4:
R[i] = 1/3( Q[i] + Q[i+1] + P[i+1] );
endfor;
R[5] = R[0];
for i=0 upto 5:
S[i] = 1.5*Q[i];
endfor;
for i=0 upto 4:
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];
endfor;
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
withpen pencircle scaled 2bp;
endfig;
beginfig(140)
for i=1 step -.01 until 0:
fill fullcircle scaled (i*2cm) withcolor i*white;
endfor;
draw fullcircle scaled 2cm withpen pencircle scaled 2bp;
endfig;
beginfig(141)
u:=5mm;
path p;
p = (0,0) .. (-1,1) .. (2,0) .. (0,-3) .. cycle;
p := p shifted (-1,0);
for i=1 step -.01 until 0:
fill p scaled (i*u) withcolor i*white;
endfor;
draw p scaled u withpen pencircle scaled 2bp;
endfig;
beginfig(142)
z0 = (50,50);
z1 = z0 rotated 90;
z2 = z1 rotated 90;
z3 = z2 rotated 90;
path carre;
carre = z0--z1--z2--z3--cycle;
s := .01;
path rect;
z4 = s [z2,z3]; z5 = s [z1,z0];
rect = z1--z2--z4--z5--cycle;
for i=0 step s until 1:
fill rect shifted (i*(z0-z1)) withcolor i*white;
endfor;
draw carre withpen pencircle scaled 2bp;
endfig;
beginfig(143)
z0 = (50,50);
z1 = z0 rotated 90;
z2 = z1 rotated 90;
z3 = z2 rotated 90;
path carre;
carre = z0--z1--z2--z3--cycle;
s := .01;
for i=1 step -s until s:
fill carre scaled i withcolor i*white;
endfor;
endfig;
beginfig(144)
u:=1cm;
vardef degrade(expr p,q,M,N) =
save a,b;
numeric a,b;
a := length(p);
b := length(q);
for i=0 upto M:
draw (i/M) [ point 0 of p, point 0 of q ]
for j=1 upto N:
.. (i/M) [ point (j/N*a) of p, point (j/N*b) of q ]
endfor;
endfor;
enddef;
degrade(
(-.1u,-.1u) .. (.1u,.1u) .. cycle,
(-u,-u) -- (u,-u) -- (u,u) -- (-u,u) -- cycle,
10,
100);
endfig;
beginfig(145)
u:=1cm;
def couleur(expr c) = c*white enddef;
vardef degrade(expr p,q,M,N) =
save a,b;
numeric a,b;
a := length(p);
b := length(q);
for i=0 upto M:
draw (i/M) [ point 0 of p, point 0 of q ]
for j=1 upto N:
.. (i/M) [ point (j/N*a) of p, point (j/N*b) of q ]
endfor
withcolor couleur(i/M);
endfor;
enddef;
degrade(
(-.5u,-.5u) .. (.5u,.5u) .. cycle,
(-u,-u) -- (u,-u) -- (u,u) -- (-u,u) -- cycle,
255,
100);
endfig;
beginfig(146)
def degrade(expr p, q, N) =
begingroup
save n, m, M;
numeric n, m, M;
n := length(p);
m := length(q);
M := n*m; % Il faudrait prendre le ppcm
for i=0 upto N:
draw
(i/N)[ point 0 of p, point 0 of q ]
{ (i/N)[ direction 0 of p, direction 0 of q ] }
for j=1 upto M-1:
..
{ (i/N) [ direction 1 of subpath((j-1)*n/M,j*n/M) of p,
direction 1 of subpath((j-1)*m/M,j*m/M) of q ] }
(i/N)[ point (j*n/M) of p, point (j*m/M) of q ]
{ (i/N) [ direction 0 of subpath(j*n/M,(j+1)*n/M) of p,
direction 0 of subpath(j*m/M,(j+1)*m/M) of q ] }
endfor
..
{ (i/N)[ direction n of p, direction m of q ] }
(i/N)[ point n of p, point m of q ]
;
endfor;
endgroup;
enddef;
numeric u;
u := 2cm;
path p, q;
p := fullcircle scaled u;
q := (-u,-u)--(u,-u)--(u,u)--(-u,u)--cycle;
degrade(p,q,10);
endfig;
beginfig(147)
draw for i=0 step 10 until 360:
2cm* (sind(2*i), cosd(3*i)) ..
endfor cycle;
endfig;
beginfig(148)
for i=0 step .1 until 360:
col := i/360;
draw 2cm* (sind(2*i), cosd(3*i))
withpen pencircle scaled 2bp
withcolor
if col>.5: (2*(1-col)) [red, blue]
else: (1-2col) [blue, red]
fi;
endfor;
endfig;
beginfig(149)
def couleur(expr x) =
if x>.5: (2*(1-x)) [red, blue];
else: (1-2x) [blue, red]
fi
enddef;
for i=0 step .1 until 360:
draw 2cm* (sind(2*i), cosd(3*i))
withpen pencircle scaled 2bp
withcolor couleur(i/360);
endfor;
endfig;
beginfig(150)
for i=0 step 1 until 360:
pair P;
P = 2cm* (sind(2*i), cosd(3*i));
fill fullcircle scaled 4mm shifted P withcolor white;
draw fullcircle scaled 4mm shifted P;
endfor;
endfig;
beginfig(151)
for i=0 step 1 until 360:
pair P;
P = 2cm* (sind(2*i), cosd(3*i));
fill fullcircle scaled 4mm shifted P withcolor white;
draw fullcircle scaled 4mm shifted P;
endfor;
picture p;
p:=nullpicture;
for i=-180 step 1 until 180:
pair P;
P = 2cm* (sind(2*i), cosd(3*i));
addto p contour fullcircle scaled 4mm shifted P withcolor white;
addto p doublepath fullcircle scaled 4mm shifted P
withpen pencircle scaled .5bp;
endfor;
clip p to (.5cm,2.5cm) -- (.5cm,1.5cm)--
(-.5cm,1.5cm) -- (-.5cm,2.5cm)--cycle;
draw p;
endfig;
beginfig(152)
u:=5mm;
vardef project(expr x,y,z) =
x*(-1,-1) + y*(1,0) + z*(0,1)
enddef;
vardef f(expr x,y) = sind(x/u*180)*sind(y/u*180)*u enddef;
numeric m,M;
m:=-2u; M:=2u;
for i=m step .1u until M:
path p;
p =
for j=m step .1u until M:
project(i,j,f(i,j)) --
endfor
project(i,M,f(i,M));
fill (project(i,m,f(i,m)) - (0,3u)) -- p --
(project(i,M,f(i,M)) - (0,3u)) -- cycle
withcolor white;
draw (project(i,m,f(i,m)) - (0,3u)) -- p --
(project(i,M,f(i,M)) - (0,3u)) -- cycle;
draw p;
endfor;
endfig;
beginfig(153)
vardef project(expr x,y,z) =
x*(-1,-1) + y*(1,0) + z*(0,1)
enddef;
vardef f(expr x,y) = sind(x/u*180)*sind(y/u*180)*u enddef;
m:=-2u; M:=2u; inc:=.1u;
for i=m step inc until M:
for j=m step inc until M:
path p;
p = project(i,j,f(i,j)) --
project(i,j+inc,f(i,j+inc)) --
project(i+inc,j+inc,f(i+inc,j+inc)) --
project(i+inc,j,f(i+inc,j)) --
cycle;
fill p withcolor white;
draw p;
endfor
endfor;
endfig;
beginfig(154)
vardef project(expr x,y,z) =
x*(-1,-1) + y*(1,0) + z*(0,1)
enddef;
vardef f(expr x,y) = sind(x/u*180)*sind(y/u*180)*u enddef;
numeric m,M,inc,couleur;
m:=-2u; M:=2u; inc:=.1u;
for i=m step inc until M:
for j=m step inc until M:
path p;
p = project(i,j,f(i,j)) --
project(i,j+inc,f(i,j+inc)) --
project(i+inc,j+inc,f(i+inc,j+inc)) --
project(i+inc,j,f(i+inc,j)) --
cycle;
dfdx := (f(i,j) - f(i+inc,j))/inc;
dfdy := (f(i,j) - f(i,j+inc))/inc;
couleur := 1/sqrt( dfdx**2 + dfdy**2 + 1);
fill p withcolor couleur*(red+green);
endfor
endfor;
endfig;
beginfig(155)
vardef f(expr x,y) = sind(x/u*180)*sind(y/u*180)*u enddef;
boolean dessine_fil_de_fer; dessine_fil_de_fer := false;
color dessine_couleur; dessine_couleur := red+green;
vardef dessine(suffix f)(expr xmin, xmax, xinc, ymin, ymax, yinc) =
save i,j,p,dfdx,dfdy,project;
vardef project(expr x,y,z) =
x*(-1,-1) + y*(1,0) + z*(0,1)
enddef;
for i=m step inc until M:
for j=m step inc until M:
path p;
p = project(i,j,f(i,j)) --
project(i,j+inc,f(i,j+inc)) --
project(i+inc,j+inc,f(i+inc,j+inc)) --
project(i+inc,j,f(i+inc,j)) --
cycle;
dfdx := (f(i,j) - f(i+inc,j))/inc;
dfdy := (f(i,j) - f(i,j+inc))/inc;
couleur := 1/sqrt( dfdx**2 + dfdy**2 + 1);
fill p withcolor couleur*dessine_couleur;
if dessine_fil_de_fer: draw p fi;
endfor
endfor;
enddef;
% Il faudrait pouvoir choisir diff�rents
% types d'� �clairage �.
vardef f(expr x,y) = sind(x/u*180)*sind(y/u*180)*u enddef;
dessine(f,-2u,2u,.1u, -2u,2u,.1u);
endfig;
beginfig(156)
vardef random_path (expr n) =
save i, A ; numeric i; pair A[];
for i=0 upto n:
A[i] = (uniformdeviate(2u), uniformdeviate(2u));
endfor;
A[0]
for i=1 upto n:
.. A[i]
endfor
enddef;
vardef intersections(expr p,q) =
save a,b,N,i,j;
numeric N,i,j;
N:=10;
for i=0 step length(p)/N until length(p):
for j=0 step length(q)/N until length(p):
numeric a,b;
pair A;
(a,b) = (subpath(i,i+length(p)/N) of p)
intersectiontimes
(subpath(j,j+length(q)/N) of q);
if a <> -1:
A = point a of subpath(i,i+length(p)/N) of p;
show A;
draw A withpen pencircle scaled 4bp;
fi;
endfor;
endfor;
enddef;
path p,q;
p:=random_path(4);
q:=random_path(4);
draw p withcolor red;
draw q withcolor blue;
intersections(p,q);
endfig;
beginfig(157)
vardef auto_intersections(expr p) =
save a,b,N,i,j;
numeric N,i,j;
N:=100;
for i=0 step length(p)/N until length(p):
for j=i+2*length(p)/N
step length(p)/N
until length(p):
numeric a,b;
pair A;
(a,b) = (subpath(i,i+length(p)/N) of p)
intersectiontimes
(subpath(j,j+length(p)/N) of p);
if a <> -1:
A = point a of subpath(i,i+length(p)/N) of p;
show A;
draw A withpen pencircle scaled 4bp;
fi;
endfor;
endfor;
enddef;
u:=2cm;
path p,q;
p:=random_path(12);
draw p;
auto_intersections(p);
endfig;
beginfig(158)
path p;
p := (0,0){up} .. (1cm,1cm) .. (1cm,0);
draw p;
draw point 1/2length(p) of p
withpen pencircle scaled 4bp withcolor red;
draw point (arctime (1/2 arclength(p)) of p) of p
withpen pencircle scaled 4bp;
endfig;
beginfig(159)
vardef milieu(expr p) =
save l,i,tot,A,B;
numeric l,tot,i;
pair A,B;
tot := longueur(p);
l:=0;
B := point 0 of p;
for i:=0 step .01 until length(p):
A := B;
B := point i of p;
l := l+abs(B-A);
exitif l > 1/2 tot;
endfor;
1/2[A,B]
enddef;
path p;
p := (0,0){up} .. (1cm,1cm) .. (1cm,0);
draw p;
draw point 1/2length(p) of p withpen pencircle scaled 4bp withcolor red;
draw milieu(p) withpen pencircle scaled 4bp;
endfig;
beginfig(160)
vardef milieu_time(expr p) =
save l,i,tot,A,B,t;
numeric l,tot,i,t;
pair A,B;
tot := longueur(p);
l:=0;
B := point 0 of p;
for i:=0 step .01 until length(p):
t:=i;
A := B;
B := point i of p;
l := l+abs(B-A);
exitif l > 1/2 tot;
endfor;
t % Pas de point-virgule
enddef;
save arrowhead;
vardef arrowhead expr p =
save A,u; pair A,u;
A := milieu(p);
u := unitvector(direction milieu_time(p) of p);
A -- (A - ahlength*u rotated 15) --
(A - ahlength*u rotated -15) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(161)
save arrowhead;
vardef arrowhead expr p =
save A,B,u; pair A,B,u;
A := milieu(p);
B := p intersectionpoint
(fullcircle scaled ahlength shifted A);
u := unitvector(direction milieu_time(p) of p);
A -- (A - ahlength*u rotated 30) -- B --
(A - ahlength*u rotated -30) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(162)
save arrowhead;
vardef arrowhead expr p =
save A,u; pair A,u;
A := milieu(p);
u := unitvector(direction milieu_time(p) of p);
A -- (A - ahlength*u rotated 30) -- A --
(A - ahlength*u rotated -30) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(163)
save arrowhead;
vardef arrowhead expr p =
save A,u,a,b; pair A,u; path a,b;
A := milieu(p);
u := unitvector(direction milieu_time(p) of p);
a := A{-u} .. (A - ahlength*u rotated 30);
b := A{-u} .. (A - ahlength*u rotated -30);
( a & reverse(a) & b & reverse(b) ) --cycle
enddef;
pair A[];
for i=0 step length(p)/100 until length(p):
pair M,N;
M = point i of p;
N-M = whatever * direction i of p;
N-z0 = whatever * direction i of p rotated 90;
A[i] := N;
endfor;
draw for i=0 step length(p)/100 until length(p):
A[i] ..
endfor cycle;
endfig;
beginfig(170)
vardef cardiodide(expr p, O) =
save i,M,N;
numeric i;
for i=0 step length(p)/100 until length(p):
hide(
pair M,N;
M = point i of p;
N-M = whatever * direction i of p;
N-O = whatever * direction i of p rotated 90;
)
N ..
endfor cycle
enddef;
path p;
p = fullcircle scaled 2cm;
z0 = (-1cm,0);
draw p;
draw z0 withpen pencircle scaled 2pt;
draw cardiodide(p,z0);
endfig;
beginfig(171)
vardef cardiodide(expr p, O) =
save i,M,N;
numeric i;
for i=0 step length(p)/100 until length(p):
hide(
pair M,N;
M = point i of p;
N-M = whatever * direction i of p;
N-O = whatever * direction i of p rotated 90;
)
N ..
endfor cycle
enddef;
path p;
p = fullcircle scaled 2cm;
z0 = (-1cm,0);
pickup pencircle scaled 1pt
draw p;
draw z0 withpen pencircle scaled 3pt;
draw cardiodide(p,z0);
pickup pencircle scaled .4pt
pair M,N;
i:=1.5;
M = point i of p;
N-M = whatever * direction i of p;
N-z0 = whatever * direction i of p rotated 90;
draw z0--N;
draw (-1/2)[N,M]--(3/2)[N,M];
draw N withpen pencircle scaled 3pt;
draw M withpen pencircle scaled 3pt;
endfig;
beginfig(172)
path p;
p := (-1cm,0) .. (1cm,-1cm) .. (8mm,0)
.. (1cm,1cm) .. (-1cm,1cm) .. cycle;
z0 = (-2cm,0);
draw p withpen pencircle scaled 1bp;
draw z0 withpen pencircle scaled 3pt;
draw cardiodide(p,z0);
endfig;
beginfig(173)
vardef inversion (expr O,k,M) =
if pair M:
(O + k*unitvector(M-O)/abs(M-O))
elseif path M:
for i=0 step length(M)/100 until length(M):
inversion(O,k,point i of M) ..
endfor
cycle
fi
enddef;
u:=4cm;
path p[],A,B;
z0 = (5u,0) rotated 10;
A = fullcircle scaled 2u;
B = A scaled 3;
draw inversion( z0, 2 (u**2), A )
withpen pencircle scaled 1pt;
draw inversion( z0, 2 (u**2), B )
withpen pencircle scaled 1pt;
p0 = fullcircle scaled 2u shifted (2u,0);
for i=0 upto 5:
if i<>0:
p[i] = p[i-1] rotated (360/6);
fi;
draw inversion( z0, 2 (u**2), p[i] );
endfor;
endfig;
beginfig(174)
def curve(expr p,i,q,j,t) =
point i of p {direction i of p} ..
tension t ..
point j of q {direction j of q}
enddef;
u:=3mm;
path c[], l[];
sphere_with_holes(5);
endfig;
beginfig(175)
def curve(expr p,i,q,j,t) =
point i of p {direction i of p} ..
tension t ..
point j of q {direction j of q}
enddef;
vardef sphere_with_holes (expr n) =
save i;
c[0] = fullcircle xscaled u yscaled 2u
shifted (4u,0) rotated (360/(2n)) ;
for i=1 upto n-1:
c[i] = c[i-1] rotated (360/n);
endfor;
l[0] = curve(c[0], 2, c[1], -2, 1);
for i=1 upto n-1:
l[i] = l[i-1] rotated (360/n);
endfor;
fill for i=0 upto n-1:
( reverse subpath(2,6) of c[i] ) &
l[i] &
endfor
% To turn it into a cycle (ugly)
point length(l[n-1]) of l[n-1] -- cycle
withcolor .8white;
for i=0 upto n-1:
draw c[i]; draw l[i];
endfor;
enddef;
draw M1--M2--M3--cycle;
endfig;
beginfig(180)
save arrowhead;
vardef arrowhead expr p =
save A,u; pair A,u;
A := point length(p) of p;
u := unitvector(direction length(p) of p);
A -- (A - ahlength*u rotated 15) --
(A - ahlength*u rotated -15) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(181)
save arrowhead;
vardef arrowhead expr p =
save A,B,u; pair A,B,u;
A := point length(p) of p;
B := p intersectionpoint
(fullcircle scaled ahlength shifted A);
u := unitvector(direction length(p) of p);
A -- (A - ahlength*u rotated 30) -- B --
(A - ahlength*u rotated -30) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(182)
save arrowhead;
vardef arrowhead expr p =
save A,u; pair A,u;
A := point length(p) of p;
u := unitvector(direction length(p) of p);
A -- (A - ahlength*u rotated 30) -- A --
(A - ahlength*u rotated -30) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(183)
save arrowhead;
vardef arrowhead expr p =
save A,u,a,b; pair A,u; path a,b;
A := point length(p) of p;
u := unitvector(direction length(p) of p);
a := A{-u} .. (A - ahlength*u rotated 30);
b := A{-u} .. (A - ahlength*u rotated -30);
( a & reverse(a) & b & reverse(b) ) --cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(184)
save arrowhead;
vardef arrowhead expr p =
save A,u; pair A,u;
A := point 1/2length(p) of p;
u := unitvector(direction 1/2length(p) of p);
A -- (A - ahlength*u rotated 15) --
(A - ahlength*u rotated -15) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(185)
save arrowhead;
vardef arrowhead expr p =
save A,B,u; pair A,B,u;
A := point 1/2length(p) of p;
B := p intersectionpoint
(fullcircle scaled ahlength shifted A);
u := unitvector(direction 1/2length(p) of p);
A -- (A - ahlength*u rotated 30) -- B --
(A - ahlength*u rotated -30) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(186)
save arrowhead;
vardef arrowhead expr p =
save A,u; pair A,u;
A := point 1/2length(p) of p;
u := unitvector(direction 1/2length(p) of p);
A -- (A - ahlength*u rotated 30) -- A --
(A - ahlength*u rotated -30) -- cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(187)
save arrowhead;
vardef arrowhead expr p =
save A,u,a,b; pair A,u; path a,b;
A := point 1/2length(p) of p;
u := unitvector(direction 1/2length(p) of p);
a := A{-u} .. (A - ahlength*u rotated 30);
b := A{-u} .. (A - ahlength*u rotated -30);
( a & reverse(a) & b & reverse(b) ) --cycle
enddef;
def _finwhitearr text t =
draw _apth t;
fill arrowhead _apth t withcolor white;
draw arrowhead _apth t
enddef;
u:=1cm;
drawwhitearrow (0,0) .. (-u,u) .. (u,u);
endfig;
beginfig(189)
def draw_white_arrow expr p = _apth:=p; _fin_white_arr enddef;
def _fin_white_arr text t =
draw _apth t;
fill arrowhead _apth withcolor white;
draw arrowhead _apth t
enddef;
def draw_middle_arrow expr p = _apth:=p; _fin_middle_arr enddef;
def _fin_middle_arr text t =
draw _apth t;
filldraw arrowhead_middle _apth t
enddef;
vardef arrowhead_middle expr p =
save A,u; pair A,u;
A := point (arctime (.5arclength p) of p) of p;
u := unitvector(direction (arctime (.5arclength p) of p) of p);
A -- (A - ahlength*u rotated (.5ahangle) ) --
(A - ahlength*u rotated (-.5ahangle) ) -- cycle
enddef;
def draw_middle_white_arrow expr p = _apth:=p; _fin_middle_white_arr enddef;
let draw_white_middle_arrow = draw_middle_white_arrow;
def _fin_middle_white_arr text t =
draw _apth t;
fill arrowhead_middle _apth t withcolor white;
draw arrowhead_middle _apth t
enddef;
def draw_other_arrow expr p = _apth:=p; _fin_other_arr enddef;
def _fin_other_arr text t =
draw _apth t;
draw arrowhead_other _apth t
enddef;
vardef arrowhead_other expr p =
save A,u,a,b; pair A,u; path a,b;
A := point (length p) of p;
u := unitvector(direction (length p) of p);
a := A{-u} .. (A - ahlength*u rotated 30);
b := A{-u} .. (A - ahlength*u rotated -30);
( a & reverse(a) & b & reverse(b) ) --cycle
enddef;
def draw_other_middle_arrow expr p = _apth:=p; _fin_other_middle_arr enddef;
let draw_middle_other_arrow = draw_other_middle_arrow;
def _fin_other_middle_arr text t =
draw _apth t;
draw arrowhead_other_middle _apth t
enddef;
vardef arrowhead_other_middle expr p =
save A,u,a,b; pair A,u; path a,b;
A := point (arctime (.5arclength p) of p) of p;
u := unitvector(direction (arctime (.5arclength p) of p) of p);
a := A{-u} .. (A - ahlength*u rotated 30);
b := A{-u} .. (A - ahlength*u rotated -30);
( a & reverse(a) & b & reverse(b) ) --cycle
enddef;
path p;
p := halfcircle scaled 2cm;
p := (0,0) .. (3cm,1cm) .. (-1cm,3cm);
p := p scaled .3;
draw_middle_arrow p;
draw_white_arrow p scaled 1.3 withpen pencircle scaled 1bp;
draw_white_middle_arrow p scaled 1.6;
draw_other_middle_arrow p scaled 1.8 withpen pencircle scaled 1bp;
draw_other_arrow p scaled 2 withpen pencircle scaled 1bp;
endfig;
beginfig(190)
vardef mylabel(expr pic, p, t) =
save A; pair A;
A = point t of p +
8bp * unitvector(direction t of p) rotated 90;
label(pic, A);
enddef;
path p; u:=1cm;
p = (0,0)..(-u,u)..(u,u);
draw p;
for i=0 step .2 until length(p):
draw point i of p withpen pencircle scaled 4bp;
mylabel(btex $A$ etex,p,i);
endfor;
endfig;
beginfig(191)
vardef mylabel(expr pic, p, t) =
save A; pair A;
A = point t of p +
8bp * unitvector(direction t of p) rotated 90;
label(pic, A);
enddef;
path p; u:=1cm;
p = (0,0)..(-u,u)..(u,u);
draw p;
for i=0 step .2 until length(p):
draw point i of p withpen pencircle scaled 4bp;
mylabel(TEX decimal(i),p,i);
endfor;
endfig;
beginfig(192)
vardef mylabel(expr pic, p, t) =
save A,a; pair A; numeric a;
a := angle(direction t of p rotated 90);
show(a);
a := a + 45/2;
if a>180: a := a - 360 fi;
save ll, lr, ul, ur;
pair ul,ur,ll,lr;
ll := llcorner pic;
lr := lrcorner pic;
ul := ulcorner pic;
ur := urcorner pic;
A = point t of p +
8bp * unitvector(direction t of p) rotated 90;
label(pic shifted ll, A +
if (a >= 0) and (a <= 45): 1/2(ur-ul)
elseif (a >= 45) and (a <= 90): 1/2(ur-ul) + 1/2(ur-lr)
elseif (a >= 90) and (a <= 135): 1/2(ur-lr)
elseif (a >= 135) and (a <= 180): 1/2(ll-lr) + 1/2(ur-lr)
elseif (a >= -180) and (a <= -135): 1/2(ll-lr)
elseif (a >= -135) and (a <= -90): 1/2(ll-ul) + 1/2(ll-lr)
elseif (a >= -90) and (a <= -45): 1/2(ll-ul)
elseif (a >= -45) and (a <= 0): 1/2(ll-ul) - 1/2(ll-lr)
else: hide(show "BUG") (0,0)
fi);
draw A withpen pencircle scaled 2bp withcolor red;
enddef;
path p; u:=1cm;
p = (0,0)..(-u,u)..(u,u);
p := reverse fullcircle scaled 2u;
draw p;
for i=0 step length(p)/10 until length(p):
draw point i of p withpen pencircle scaled 4bp;
mylabel(TEX decimal(i),p,i);
endfor;
endfig;
beginfig(193)
n:=8;
u:=5mm;
for i=0 upto n-1:
for j=0 upto n-1:
if odd(i+j):
fill (0,0)--(u,0)--(u,u)--(0,u)--cycle
shifted (i*u,j*u) withcolor .8white;
fi;
endfor;
endfor;
for i=0 upto n:
draw (0,i*u)--(n*u,i*u);
draw (i*u,0)--(i*u,n*u);
endfor;
endfig;
beginfig(194)
n:=8;
u:=5mm;
for i=0 upto n-1:
for j=0 upto n-1:
if odd(i+j):
for k=0 step u/5 until u:
draw ( (k,0)--(u,u-k) )
shifted (i*u,j*u);
draw ( (0,k)--(u-k,u) )
shifted (i*u,j*u);
endfor;
fi;
endfor;
endfor;
for i=0 upto n:
draw (0,i*u)--(n*u,i*u);
draw (i*u,0)--(i*u,n*u);
endfor;
endfig;
beginfig(195)
n:=8;
u:=5mm;
for i=0 upto n-1:
for j=0 upto n-1:
if odd(i+j):
for k=0 step u/5 until 4/5 u:
if odd(k*5/u):
fill ( (k,0)--(u,u-k)--(u,u-k-u/5)--
(k+u/5,0)--cycle )
shifted (i*u,j*u) withcolor .8white;
else:
fill ( (0,k)--(u-k,u)--(u-k-u/5,u)--
(0,k+u/5)--cycle )
shifted (i*u,j*u) withcolor .8white;
fi;
endfor;
fi;
endfor;
endfor;
for i=0 upto n:
draw (0,i*u)--(n*u,i*u);
draw (i*u,0)--(i*u,n*u);
endfor;
endfig;
beginfig(196)
vardef trace (suffix f)(expr a,b,inc) =
save i; numeric i;
for i=a step inc until b:
(i*1cm, f(i)*1cm) ..
endfor (b*1cm, f(b)*1cm)
enddef;
vardef axes =
save p; picture p;
p:=nullpicture;
addto p doublepath (-infinity,0)--(infinity,0) withpen currentpen;
addto p doublepath (0,-infinity)--(0,infinity) withpen currentpen;
clip p to bbox currentpicture;
draw p;
enddef;
vardef trace_rectangles_left (suffix f)(expr a,b,inc) =
save i; numeric i;
for i=a step inc until b-inc:
path p;
p = (i,0)--(i+inc,0)--(i+inc,f(i))--(i,f(i))--cycle;
p := p scaled 1cm;
fill p withcolor .8*white;
draw p;
endfor;
enddef;
vardef f(expr x) = 2 ** x enddef;
trace_rectangles_left(f,-2,2,.5);
draw trace(f, -2,2,.1);
axes;
endfig;
beginfig(197)
vardef trace_trapezes (suffix f)(expr a,b,inc) =
save i; numeric i;
for i=a step inc until b-inc:
path p;
p = (i,0)--(i+inc,0)--(i+inc,f(i+inc))--(i,f(i))--cycle;
p := p scaled 1cm;
fill p withcolor .8*white;
draw p;
endfor;
enddef;
vardef f(expr x) = 4 - x**2 enddef;
trace_trapezes(f,-2,2,.5);
draw trace(f, -2,2,.1);
axes;
endfig;
beginfig(198)
vardef trace_rectangles_right (suffix f)(expr a,b,inc) =
save i; numeric i;
for i=a step inc until b-inc:
path p;
p = (i,0)--(i+inc,0)--(i+inc,f(i+inc))--(i,f(i+inc))--cycle;
p := p scaled 1cm;
fill p withcolor .8*white;
draw p;
endfor;
enddef;
trace_rectangles_right(f,-2,2,.5);
draw trace(f, -2,2,.1);
axes;
endfig;
beginfig(199)
vardef maxf(suffix f)(expr a,b) =
save m,i; numeric m,i;
m:=f(a);
for i=a step (b-a)/100 until b:
if m<f(i): m:=f(i); fi;
endfor;
m
enddef;
vardef trace_rectangles_max (suffix f)(expr a,b,inc) =
save i; numeric i;
for i=a step inc until b-inc:
path p; numeric m;
m:=maxf(f,i,i+inc);
p = (i,0)--(i+inc,0)--(i+inc,m)--(i,m)--cycle;
p := p scaled 1cm;
fill p withcolor .8*white;
draw p;
endfor;
enddef;
vardef f(expr x) = 4 - x**2 enddef;
trace_rectangles_max(f,-2,2,.5);
draw trace(f, -2,2,.1);
axes;
endfig;
beginfig(200)
vardef minf(suffix f)(expr a,b) =
save m,i; numeric m,i;
m:=f(a);
for i=a step (b-a)/100 until b:
if m>f(i): m:=f(i); fi;
endfor;
m
enddef;
vardef trace_rectangles_min (suffix f)(expr a,b,inc) =
save i; numeric i;
for i=a step inc until b-inc:
path p; numeric m;
m:=minf(f,i,i+inc);
p = (i,0)--(i+inc,0)--(i+inc,m)--(i,m)--cycle;
p := p scaled 1cm;
fill p withcolor .8*white;
draw p;
endfor;
enddef;
pair A[];
n:=10;
for i=0 upto n:
A[i] = 1cm*(normaldeviate, normaldeviate);
draw A[i] withpen pencircle scaled 4bp;
endfor;
draw barycentre(A[0] for i=1 upto 10: ,A[i] endfor)
withpen pencircle scaled 4bp withcolor red;
endfig;
beginfig(222)
vardef barycentre(text t) =
save a, i, n, G, X;
pair G,X; numeric n,i;
G := origin; n:=0; i:=0;
for a=t:
show("i = "& decimal(i));
show a;
if odd(i):
show("odd");
n:=n+a;
G:= G + a*X;
else:
show("even");
X:=a;
fi;
i:=i+1;
endfor;
G/n
enddef;
pair A[];
n:=10;
for i=0 upto n:
A[i] = 1cm*(normaldeviate, normaldeviate);
draw A[i] withpen pencircle scaled 4bp;
endfor;
draw barycentre(A[0],0 for i=1 upto 10: ,A[i],i endfor)
withpen pencircle scaled 4bp withcolor red;
endfig;
beginfig(223)
numeric n;
n:=10;
path p;
p := for i=0 upto n-1:
((1cm + 3mm*normaldeviate,0) rotated (i*360/n)) ..
endfor cycle;
for i=0 step 2mm until 3cm:
draw fullcircle scaled i;
endfor;
clip currentpicture to p;
draw p;
endfig;
beginfig(224)
u := 5mm;
draw (-2u,0) -- (2u,0);
draw (0,-u) -- (0,4u);
draw (-2u,4u) for i=-1.9 step .1 until 2.01: .. (i*u, i*i*u) endfor
withpen pencircle scaled 1bp;
draw bbox currentpicture withpen pensquare scaled 2bp withcolor .8white;
draw bbox currentpicture withpen pensquare scaled 2bp withcolor .8white;
endfig;
beginfig(225)
path p;
p := (0,0) -- (2cm,0);
def doit (suffix p)(expr t) =
begingroup
interim linecap := t;
draw p withpen pencircle scaled 5mm withcolor .8white;
endgroup;
draw point 0 of p withpen pencircle scaled 4bp;
draw point 1 of p withpen pencircle scaled 4bp;
p := p shifted (0,-7mm)
enddef;
doit(p,rounded);
doit(p,butt);
doit(p,squared);
endfig;
beginfig(226)
path p;
p := (0,0) -- (1cm,5mm) -- (2cm,0);
def doit (suffix p)(expr t) =
begingroup
interim linejoin := t;
draw p withpen pencircle scaled 5mm withcolor .8white;
endgroup;
draw point 0 of p withpen pencircle scaled 4bp;
draw point 1 of p withpen pencircle scaled 4bp;
draw point 2 of p withpen pencircle scaled 4bp;
p := p shifted (0,-7mm)
enddef;
doit(p,rounded);
doit(p,mitered);
doit(p,beveled);
endfig;
beginfig(227)
path p;
p := (0,0) -- (2cm,0);
vardef doit (suffix p)(expr t) =
interim linecap := t;
draw p withpen pencircle scaled 5mm withcolor .8white;
draw point 0 of p withpen pencircle scaled 4bp;
draw point 1 of p withpen pencircle scaled 4bp;
draw point 2 of p withpen pencircle scaled 4bp;
p := p shifted (0,-7mm)
enddef;
doit(p,rounded);
doit(p,butt);
doit(p,squared);
endfig;
beginfig(231)
path p;
p =
(0,u)
for i=.1 step .1 until 10:
hide( pair A; A = (i*u, (sind (i*180/3.14))/i *u);
draw A withpen pencircle scaled 2pt )
.. A
endfor;
draw p;
endfig;
beginfig(232)
vardef inversion (expr O,k,M) =
if pair M:
(O + k*unitvector(M-O)/abs(M-O))
elseif path M:
for i=0 step length(M)/10 until length(M):
hide(
draw O--inversion(O,k,point i of M)--(point i of M);
draw inversion(O,k,point i of M) withpen pencircle scaled 2pt;
draw point i of M withpen pencircle scaled 2pt withcolor red;
draw O withpen pencircle scaled 2pt;
)
inversion(O,k,point i of M) ..
endfor
cycle
fi
enddef;
endfig;
beginfig(242)
circleit.a(btex Essai etex);
a.c = (0,0);
a.dx = a.dy;
drawboxed(a);
endfig;
beginfig(243)
circleit.a(btex Essai etex);
a.c = (0,0);
a.dx = a.dy;
drawunboxed(a);
for i=0 step 10 until 360:
draw (0,0) -- 1cm*right rotated i cutbefore bpath.a;
endfor;
endfig;
beginfig(244)
circleit.a(btex D�but etex);
a.c = (0,0);
a.dx = a.dy;
circleit.b(btex Fin etex);
b.c = (2cm,0);
b.dx = b.dy;
drawboxed(a,b);
drawarrow a.c {dir 45} .. b.c {dir -45}
cutbefore bpath.a cutafter bpath.b;
drawarrow b.c {dir -135} .. a.c {dir 135}
cutbefore bpath.b cutafter bpath.a;
endfig;
beginfig(245)
circleit.a(btex D�but etex);
a.c = (0,0);
a.dx = a.dy;
circleit.b(btex Fin etex);
b.c = (2cm,0);
b.dx = b.dy;
drawunboxed(a,b);
drawarrow a.c {dir 45} .. b.c {dir -45}
cutbefore bpath.a cutafter bpath.b;
drawarrow b.c {dir -135} .. a.c {dir 135}
cutbefore bpath.b cutafter bpath.a;
endfig;
beginfig(246)
boxjoin(
a.dx = a.dy;
b.dx = b.dy;
a.e + (5mm,0) = b.w;
);
circleit.a(btex D�but etex);
a.c = (0,0);
circleit.b(btex Fin etex);
drawboxed(a,b);
drawarrow a.c {dir 45} .. b.c {dir -45}
cutbefore bpath.a cutafter bpath.b;
drawarrow b.c {dir -135} .. a.c {dir 135}
cutbefore bpath.b cutafter bpath.a;
endfig;
beginfig(247)
% Toujours mettre la commande boxjoin au d�but.
boxjoin(a.e = b.w);
boxit.a(btex A etex);
boxit.b(btex B etex);
boxit.c(btex C etex);
boxit.d(btex D etex);
drawboxed(a,b,c,d);
endfig;
beginfig(248)
boxjoin(a.e = b.w);
boxit.a(btex a etex);
boxit.b(btex b etex);
boxit.c(btex c etex);
boxit.d(btex d etex);
drawboxed(a,b,c,d);
endfig;
beginfig(249)
boxjoin(a.se = b.sw; a.ne = b.nw);
boxit.a(btex a etex);
boxit.b(btex b etex);
boxit.c(btex c etex);
boxit.d(btex d etex);
drawboxed(a,b,c,d);
endfig;
beginfig(250)
boxjoin(a.se = b.sw; a.ne = b.nw);
boxit.a1(btex a etex);
boxit.a2(btex b etex);
boxit.a3(btex c etex);
boxit.a4(btex d etex);
drawboxed(a1,a2,a3,a4);
endfig;
beginfig(251)
draw (0,0) -- (5cm,0) withcolor red;
draw btex a etex ;
draw btex b etex shifted (1cm,0);
draw btex c etex shifted (2cm,0);
draw btex d etex shifted (3cm,0);
draw btex e etex shifted (4cm,0);
endfig;
beginfig(252)
draw (0,0) -- (5cm,0) withcolor red;
boxjoin(b.c - a.c = (1cm,0));
boxit a (btex a etex);
boxit b (btex b etex);
boxit c (btex c etex);
boxit d (btex d etex);
boxit e (btex e etex);
drawunboxed(a,b,c,d,e);
endfig;
beginfig(253)
vardef boxTEX expr s =
save p,h,l;
picture p;
numeric h,l;
p := TEX(s);
h := max(ypart ulcorner(p), abs(ypart llcorner(p)));
l := xpart lrcorner(p);
setbounds p to (0,-h)--(l,-h)--(l,h)--(0,h)--cycle;
p
enddef;
draw (0,0) -- (5cm,0) withcolor red;
boxjoin(b.c - a.c = (1cm,0));
boxit a (boxTEX "a");
boxit b (boxTEX "b");
boxit c (boxTEX "c");
boxit d (boxTEX "d");
boxit e (boxTEX "e");
drawunboxed(a,b,c,d,e);
endfig;
beginfig(254)
draw (0,0) -- (5cm,0) withcolor red;
boxjoin(b.c - a.c = (1cm,0));
boxit a (boxTEX "a");
boxit b (boxTEX "b");
boxit c (boxTEX "c");
boxit d (boxTEX "d");
boxit e (boxTEX "e");
drawboxed(a,b,c,d,e);
endfig;
beginfig(255)
let OLD_beginbox_ = beginbox_;
def beginbox_(expr pp,sp)(suffix $)(text t) =
_n_ := str $;
generic_declare(pair) _n.off, _n.c;
generic_declare(string) pproc_._n, sproc_._n;
generic_declare(picture) pic_._n;
pproc_$:=pp; sproc_$:=sp;
pic_$ = nullpicture;
for _p_=t:
pic_$:=
if picture _p_: _p_
else: _p_ infont defaultfont scaled defaultscale
fi;
endfor
$c = $off + (.5[xpart llcorner pic_$, xpart urcorner pic_$], 0)
enddef;
draw (0,0) -- (5cm,0) withcolor red;
boxjoin(b.c - a.c = (1cm,0));
boxit a (btex a etex);
boxit b (btex b etex);
boxit c (btex c etex);
boxit d (btex d etex);
boxit e (btex e etex);
drawunboxed(a,b,c,d,e);
endfig;
beginfig(256)
draw (0,0) -- (5cm,0) withcolor red;
boxjoin(b.c - a.c = (1cm,0));
boxit a (btex a etex);
boxit b (btex b etex);
boxit c (btex c etex);
boxit d (btex d etex);
boxit e (btex e etex);
drawboxed(a,b,c,d,e);
endfig;
beginfig(257)
let OLD_boxit = boxit;
let OLD_sizebox_ = sizebox_;
let OLD_clearb_ = clearb_;
draw (0,0) -- (5cm,0) withcolor red;
boxjoin(b.c - a.c = (1cm,0); ypart( b.ne - a.ne ) = 0; ypart( b.se - a.se ) = 0;);
boxit a (btex a etex);
boxit b (btex b etex);
boxit c (btex c etex);
boxit d (btex d etex);
boxit e (btex e etex);
drawboxed(a,b,c,d,e);
endfig;
beginfig(260)
draw (0,0) -- (5cm,0) withcolor red;
picture p;
numeric h;
p := btex b etex;
h = ypart ( ulcorner p - llcorner p );
boxjoin(
b.c - a.c = (1cm,0);
ypart( b.ne - a.ne ) = 0;
ypart( a.ne - a.se ) = h+2defaultdy;
);
boxit a (btex a etex);
boxit b (btex b etex);
boxit c (btex c etex);
boxit d (btex d etex);
boxit e (btex e etex);
drawboxed(a,b,c,d,e);
endfig;
beginfig(261)
% Les lignes suivantes n'ont pas l'effet escompt�...
let beginbox_ = OLD_beginbox_;
let boxit = OLD_boxit;
let sizebox_ = OLD_sizebox_;
let clearb_ = OLD_clearb_;
% On recopie donc les d�finitions initiales des macros que l'on a modifi�es...
extra_beginfig := "";
extra_endfig := "";
input boxes;
% Et on regarde sur un exemple si �a marche...
draw (0,0) -- (5cm,0) withcolor red;
boxjoin(b.c - a.c = (1cm,0));
boxit a (btex a etex);
boxit b (btex b etex);
boxit c (btex c etex);
boxit d (btex d etex);
boxit e (btex e etex);
drawboxed(a,b,c,d,e);
endfig;
beginfig(262)
boxit.a1(btex $a$ etex);
boxit.b1(btex etex);
boxit.a2(btex $b$ etex);
boxit.b2(btex etex);
boxit.a3(btex $c$ etex);
boxit.b3(btex etex);
boxit.a4(btex $d$ etex);
boxit.b4(btex etex);
for i=1 upto 4:
% Les boites a[i] et b[i] sont coll�es
a[i].e = b[i].w;
% Il y a un peu d'espace entre b[i] et a[i+1]
b[i].e + (5mm,0) = a[i+1].w;
% La hauteur des boites est la m�me
a[i].n - a[i].s = a[i+1].n - a[i+1].s = b[i].n - b[i].s ;
% Les b[i] ne sont pas tr�s larges
b[i].e - b[i].w = (2mm,0);
endfor;
drawboxed(a1,b1,a2,b2,a3,b3,a4,b4);
for i=1 upto 3:
drawarrow b[i].c {up} .. a[i+1].c {down}
cutafter bpath.a[i+1];
endfor;
endfig;
beginfig(263)
boxit.a(btex A etex);
boxit.b(btex B etex);
boxit.c(btex C etex);
boxit.d(btex D etex);
boxit.e(btex E etex);
endfig;
beginfig(269)
def begindiag =
begingroup;
save _diag_x, _diag_x_max, _diag_y, _diag_y_max, _diag;
numeric _diag_x, _diag_x_max, _diag_y, _diag_y_max;
string _diag[][];
% Num�ro de ligne et de colonne courrants
_diag_x = -1; _diag_y = 0;
% Num�ro de ligne et de colonne maximaux
_diag_x_max = _diag_y_max = 0;
save _diag_ar_n, _diag_ar_source, _diag_ar_but, _diag_ar_up, _diag_ar_down;
% Nombre de fl�ches
numeric _diag_ar_n; _diag_ar_n=-1;
% Source et but de la fl�che
pair _diag_ar_source[], _diag_ar_but[];
% Ce qu'il faut �crire au dessus ou au dessous
string _diag_ar_up[], _diag_ar_down[];
save _diag_ar_curved, _diag_ar_shape, _diag_ar_color, _diag_ar_width;
% � courbure � (c'est une distance)
numeric _diag_ar_curved[];
% Forme de la fl�che
string _diag_ar_shape[];
% Couleur, �paisseur, pointill�s
color _diag_ar_color[];
numeric _diag_ar_width[];
picture _diag_ar_dashed[];
enddef;
vardef diag_arrow_head (expr p, t) =
save A,B,C,u; pair A,B,C,u;
B := point t of p;
u := -unitvector(direction t of p);
A := B + ahlength*u rotated(-ahangle);
C := B + ahlength*u rotated(+ahangle);
A .. {-u} B {u} .. C
enddef;
vardef diag_arrow_bar (expr p, t) =
save A,B,C,u; pair A,B,C,u;
B := point t of p;
u := unitvector(direction t of p);
A := B + ahlength*sind(ahangle)*u rotated(90);
C := B + ahlength*sind(ahangle)*u rotated(-90);
A .. B .. C
enddef;
%% Les fl�ches
def diag_draw_arrow_default(suffix a,b)(expr curved, w, col, dash) =
p = a.c ..
(1/2 [a.c,b.c] + curved*unitvector(b.c-a.c) rotated 90)
.. b.c;
pp := p cutbefore bpath.a cutafter bpath.b;
draw pp
withcolor col withpen pencircle scaled w dashed dash;
draw diag_arrow_head (pp, length(pp))
withcolor col withpen pencircle scaled w;
enddef;
def diag_draw_arrow_middle(suffix a,b)(expr curved, w, col, dash) =
p = a.c ..
(1/2 [a.c,b.c] + curved*unitvector(b.c-a.c) rotated 90)
.. b.c;
pp := p cutbefore bpath.a cutafter bpath.b;
draw pp
withcolor col withpen pencircle scaled w dashed dash;
draw diag_arrow_head(p,1)
withcolor col withpen pencircle scaled w;
enddef;
def diag_draw_arrow_epi(suffix a,b)(expr curved, w, col, dash) =
p = a.c ..
(1/2 [a.c,b.c] + curved*unitvector(b.c-a.c) rotated 90)
.. b.c;
pp := p cutbefore bpath.a cutafter bpath.b;
draw pp
withcolor col withpen pencircle scaled w dashed dash;
draw diag_arrow_head (pp, length(pp))
withcolor col withpen pencircle scaled w;
path ppp;
ppp := pp cutafter (fullcircle scaled 1mm shifted point length(pp) of pp);
draw diag_arrow_head(ppp, length(ppp))
withcolor col withpen pencircle scaled w;
enddef;
def diag_draw_arrow_mono(suffix a,b)(expr curved, w, col, dash) =
p = a.c ..
(1/2 [a.c,b.c] + curved*unitvector(b.c-a.c) rotated 90)
.. b.c;
pp := p cutbefore bpath.a cutafter bpath.b;
path ppp;
ppp := pp cutbefore (fullcircle scaled 1mm shifted point 0 of pp);
draw ppp
withcolor col withpen pencircle scaled w dashed dash;
draw diag_arrow_head (pp, length(pp))
withcolor col withpen pencircle scaled w;
draw diag_arrow_head(ppp, 0)
withcolor col withpen pencircle scaled w;
enddef;
vardef diag_draw_arrow_inj(suffix a,b)(expr curved, w, col, dash) =
p = a.c ..
(1/2 [a.c,b.c] + curved*unitvector(b.c-a.c) rotated 90)
.. b.c;
pp := p cutbefore bpath.a cutafter bpath.b;
path ppp;
ppp := pp cutbefore (fullcircle scaled 1mm shifted point 0 of pp);
draw ppp
withcolor col withpen pencircle scaled w dashed dash;
draw diag_arrow_head (pp, length(pp))
withcolor col withpen pencircle scaled w;
save u,A,B,C;
pair u,A,B,C;
A := point 0 of ppp;
u := unitvector(direction 0 of ppp);
B := A + ahlength*(-u) rotated (-ahangle);
C := A + 2 ahlength*sind(ahangle)*u rotated 90;
draw C {-u} .. B .. A {u}
withcolor col withpen pencircle scaled w dashed dash;
enddef;
def diag_draw_arrow_mapsto(suffix a,b)(expr curved, w, col, dash) =
p = a.c ..
(1/2 [a.c,b.c] + curved*unitvector(b.c-a.c) rotated 90)
.. b.c;
pp := p cutbefore bpath.a cutafter bpath.b;
draw pp
withcolor col withpen pencircle scaled w dashed dash;
draw diag_arrow_head (pp, length(pp))
withcolor col withpen pencircle scaled w;
draw diag_arrow_bar (pp, 0)
withcolor col withpen pencircle scaled w;
enddef;
def diag_draw_arrow_half_dotted(suffix a,b)(expr curved, w, col, dash) =
p = a.c ..
(1/2 [a.c,b.c] + curved*unitvector(b.c-a.c) rotated 90)
.. b.c;
pp := p cutbefore bpath.a cutafter bpath.b;
draw subpath(0,1) of pp
withcolor col withpen pencircle scaled w dashed withsmalldots;
draw subpath(1,2) of pp
withcolor col withpen pencircle scaled w;
draw diag_arrow_head (pp, length(pp))
withcolor col withpen pencircle scaled w;
enddef;
%% Fin des fl�ches
def color_to_string (expr a) =
"("&
decimal(redpart a)
&","&
decimal(greenpart a)
&","&
decimal(bluepart a)
&")"
enddef;
def enddiag =
save i,j,k,l,mm,a,A,p,b;
for i=0 upto _diag_x_max:
for j=0 upto _diag_y_max:
if known _diag[i][j]:
circleit.a[i][j]( _diag[i][j] );
a[i][j].dx = a[i][j].dy;
a[i][j].c = 1cm * (i,-j);
drawunboxed( a[i][j] );
fi;
endfor;
endfor;
for m=0 upto _diag_ar_n:
% V�rifier que le but existe
i := xpart _diag_ar_source[m];
j := ypart _diag_ar_source[m];
k := xpart _diag_ar_but[m];
l := ypart _diag_ar_but[m];
% On trace la fl�che. Le chemin est mis dans la variable p.
path p,pp;
if unknown _diag_ar_shape[m]: _diag_ar_shape[m] := "default" fi;
if unknown _diag_ar_color[m]: _diag_ar_color[m] := black fi;
if unknown _diag_ar_width[m]: _diag_ar_width[m] := .5bp fi;
if unknown _diag_ar_curved[m]: _diag_ar_curved[m] := 0 fi;
if unknown _diag_ar_dashed[m]: _diag_ar_dashed[m] := notdashed fi;
% On ne peut PAS utiliser m dans une cha�ne ce caract�res que l'on donne
% � scantokens, car m est une variable de boucle. C'est vraiment sp�cial,
% une variable de boucle.
mm := m;
scantokens(
"diag_draw_arrow_"& _diag_ar_shape[m]
&"("
&"a[i][j], a[k][l],_diag_ar_curved[mm],_diag_ar_width[mm],"
&"_diag_ar_color[mm],_diag_ar_dashed[mm]"
&");"
);
% On �crit des choses au dessus ou au dessous des fl�ches
pair A;
A = point 1/2 length(p) of p;
if known _diag_ar_up[m]:
boxit.b[m](_diag_ar_up[m]);
b[m].c = A + 4bp*unitvector(direction 1/2 length(p) of p rotated 90);
drawunboxed(b[m]);
fi;
if known _diag_ar_down[m]:
boxit.c[m](_diag_ar_down[m]);
c[m].c = A + 4bp*unitvector(direction 1/2 length(p) of p rotated -90);
drawunboxed(c[m]);
fi;
endfor;
endgroup;
enddef;
endfig;
beginfig(283)
interim linecap := squared;
interim linejoin := mitered;
draw begingraph(3cm,2cm)
path p;
gdata("data1",
v,
augment.p(v1,v2);
);
gdraw p withpen pencircle scaled 2bp;
gdraw p withpen pencircle scaled 1bp withcolor .8white;
endgraph;
endfig;
beginfig(284)
draw begingraph(3cm,2cm)
gdata("data1",
v,
path p;
augment p (v1,0);
augment p (v1,v2);
gdraw p;
);
endgraph;
endfig;
beginfig(285)
draw begingraph(3cm,2cm)
gdata("data1",
v,
path p;
augment p (v1,0);
augment p (v1,v2);
gdraw p withpen pencircle scaled 4bp;
);
endgraph;
endfig;
beginfig(286)
interim linecap:=2;
draw begingraph(3cm,2cm)
gdata("data1",
v,
path p;
augment p (v1,0);
augment p (v1,v2);
gdraw p withpen pencircle scaled 4bp;
);
endgraph;
endfig;
beginfig(287)
draw begingraph(3cm,2cm)
gdata("data1", v,
path p;
augment p (v1,0);
augment p (v1,v2);
augment p (v1 Sadd "1",v2);
augment p (v1 Sadd "1",0);
gdraw p--cycle;
);
endgraph;
endfig;
beginfig(288)
draw begingraph(3cm,2cm)
gdata("data1", v,
path p;
augment p (v1,0);
augment p (v1,v2);
augment p (v1 Sadd "1",v2);
augment p (v1 Sadd "1",0);
gfill p--cycle withcolor .8white;
gdraw p--cycle;
);
endgraph;
endfig;
beginfig(289)
draw begingraph(3cm,2cm)
gdata("data1", v,
% Le dessus
path p;
augment p (v1,v2);
augment p (v1 Sadd "1",v2);
augment p (v1 Sadd "1.5", v2 Sadd "10");
augment p (v1 Sadd ".5", v2 Sadd "10");
gfill p--cycle withcolor white;
gdraw p--cycle;
% Le c�t�
path p;
augment p (v1 Sadd "1",0);
augment p (v1 Sadd "1",v2);
augment p (v1 Sadd "1.5", v2 Sadd "10");
augment p (v1 Sadd "1.5", "10");
gfill p--cycle withcolor .5white;
gdraw p--cycle;
% Le devant
path p;
augment p (v1,0);
augment p (v1,v2);
augment p (v1 Sadd "1",v2);
augment p (v1 Sadd "1",0);
gfill p--cycle withcolor .8white;
gdraw p--cycle;
);
endgraph;
endfig;
beginfig(290)
draw begingraph(3cm,2cm)
path p,q;
gdata("data1", v,
augment.p(v1,v2);
);
q:= (xpart point 0 of p, 0) -- p --
(xpart point length(p) of p, 0) -- cycle;
gfill q withcolor .8white;
gdraw p withpen pencircle scaled 2bp;
endgraph;
endfig;
beginfig(291)
draw begingraph(3cm,2cm)
gdata("data1",
v,
path p;
augment p ("0", i);
augment p (v2, i);
augment p (v2, i Sadd ".5");
augment p (0, i Sadd ".5");
gfill p--cycle withcolor .8white;
gdraw p--cycle;
);
autogrid(otick.bot,);
endgraph;
endfig;
beginfig(292)
draw begingraph(3cm,2cm)
gdraw "data1";
glabel.bot(btex Abscisse etex, OUT);
glabel.lft(btex Ordonn�e etex, OUT);
endgraph;
endfig;
beginfig(300)
vardef TEX primary s =
write "verbatimtex" to "mptextmp.mp";
write "\documentclass[12pt]{article}" to "mptextmp.mp";
write "\usepackage[T1]{fontenc}" to "mptextmp.mp";
write "\usepackage{amsmath,amssymb}" to "mptextmp.mp";
write "\begin{document}" to "mptextmp.mp";
write "etex" to "mptextmp.mp";
write "btex "&s&" etex" to "mptextmp.mp";
write EOF to "mptextmp.mp";
scantokens "input mptextmp"
enddef;
vardef mylabel(expr pic, p, t) =
save A; pair A;
A = point t of p +
8bp * unitvector(direction t of p) rotated 90;
label(pic, A);
enddef;
path p; u:=1cm;
p = (0,0)..(-u,u)..(u,u);
draw p;
for i=0 step .2 until length(p):
draw point i of p withpen pencircle scaled 4bp;
mylabel(TEX("$"&decimal(round(5*i))&"$"),p,i);
endfor;
endfig;
beginfig(301)
path p;
p := subpath(1,3) of fullcircle scaled 2cm;
interim linejoin := mitered;
interim linecap := butt;
interim ahangle := 30;
drawarrow p withpen pencircle scaled 2bp;
endfig;
beginfig(304)
path p;
p := (0,0) -- (2cm,0);
def doit (suffix p)(expr t) =
begingroup
interim linecap := t;
draw p withpen pencircle scaled 5mm withcolor .8white;
endgroup;
draw point 0 of p withpen pencircle scaled 4bp;
draw point 1 of p withpen pencircle scaled 4bp;
p := p shifted (0,-7mm)
enddef;
doit(p,rounded);
doit(p,butt);
doit(p,squared);
endfig;
beginfig(305)
path p;
p := (0,0) -- (1cm,5mm) -- (2cm,0);
def doit (suffix p)(expr t) =
begingroup
interim linejoin := t;
draw p withpen pencircle scaled 5mm withcolor .8white;
endgroup;
draw point 0 of p withpen pencircle scaled 4bp;
draw point 1 of p withpen pencircle scaled 4bp;
draw point 2 of p withpen pencircle scaled 4bp;
p := p shifted (0,-7mm)
enddef;
doit(p,rounded);
doit(p,mitered);
doit(p,beveled);