% General declarations;
pen thin; thin = pencircle scaled 0.4bp;
pen normal; normal = pencircle scaled 1bp;
pen thick; thick = pencircle scaled 2.5bp;
color yellow; yellow = (0.5,0.5,0);

% A centred string placed at specified point
vardef ctlabel( expr s, point) =
  picture pic; pic = s;
  draw pic shifted (point - (0.5(xpart lrcorner pic+xpart llcorner pic),0));
enddef;

beginfig(1);
  m := 5bp;
  pickup thin;
  drawoptions(withcolor blue);
  % Given points on a line l
  z.x = (1m,0); % Vector in the X-direction
  draw -4z.x--35z.x; % The base line
  z.a = 10z.x; z.b = 20z.x; % The two points
  % Helper point and line
  z.y = (1m,5m);
  z.p = 2z.y; % The helper point
  draw -0.5z.y--3z.y; % The helper line
  % Construction
  pickup normal;
  draw z.p--(z.p+30z.x); % The line through helper point parallel to base line
  draw z.a--(z.a+2.1z.y); % The line through the point parallel to the helper line
  z.q = z.a + whatever*z.y = z.p + whatever*z.x ; % The point of intersection 
  draw z.b--z.p; % The line joining the second point with the helper point
  draw z.q--z.q+1.03(z.b-z.p); % The line parallel to the above line
  z.r = whatever*z.x = z.q + whatever*(z.b-z.p); % = z.a + z.b
  % Marking
  pickup thick;
  drawoptions(withcolor red);
  drawdot origin; draw btex $0$ etex shifted (0,-12pt);
  drawdot z.a; draw btex $a$ etex shifted (z.a+(0,-12pt));
  drawdot z.b; draw btex $b$ etex shifted (z.b+(0,-12pt));
  drawdot z.p; draw btex $p_0$ etex shifted (z.p+(-12pt,0));
  drawdot z.q; draw btex $p_1$ etex shifted (z.q+(0,12pt));
  drawdot z.r; ctlabel(btex $a+b=p_2$ etex, z.r+(0,-12pt));
%  drawoptions(withcolor black);
%  ctlabel(btex Addition etex, 20z.x+(0,-20pt));
endfig;

beginfig(2);
  m := 5bp;
  pickup thin;
  drawoptions(withcolor blue);
  % Given points on a line l
  z.x = (1m,0); % Vector in the X-direction
  draw -4z.x--35z.x; % The base line
  z.1 = 5z.x; % The point 1 on the line
  z.a = 10z.x; z.b = 15z.x; % The two points
  % The helper stuff
  z.y = (1m,5m); % Y-vector
  z.p = z.y; % The helper point
  draw -0.5z.y--3z.y; % The helper line
  % The construction
  pickup normal;
  draw z.p--z.1; % The line joining the helper point with 1
  draw z.a--z.a+2.01(z.p-z.1); % The line parallel to the above through a
  z.q = whatever*z.y = z.a + whatever*(z.p-z.1); % The point of intersection
  draw z.p--z.b; % The line joining the helper point with the point b
  draw z.q--z.q+2.01(z.b-z.p); % The line parallel to the one above
  z.r = whatever*z.x = z.q + whatever*(z.b-z.p); % = z.(ab)
  % Marking
  pickup thick;
  drawoptions(withcolor red);
  drawdot origin; draw btex $0$ etex shifted (0,-12pt);
  drawdot z.1; draw btex $1$ etex shifted (z.1+(0,-12pt));
  drawdot z.a; draw btex $a$ etex shifted (z.a+(0,-12pt));
  drawdot z.b; draw btex $b$ etex shifted (z.b+(0,-12pt));
  drawdot z.p; draw btex $p_0$ etex shifted (z.p+(-12pt,0));
  drawdot z.q; draw btex $p_1$ etex shifted (z.q+(-12pt,0));
  drawdot z.r; ctlabel(btex $a\cdot b=p_2$ etex, z.r+(0,-12pt));
%  drawoptions(withcolor black);
%  ctlabel(btex Multiplication etex, 20z.x+(0,-20pt));
endfig;

beginfig(3);
  m := 5bp;
  pickup normal;
  drawoptions(withcolor blue);
  % The figure is rather minimal
  z.x = (1m,0);
  draw origin--40z.x;
  for k = 1 upto 5:
    z.a[k] = z.b - (2**(6-k) - 1)*z.x;
  endfor;
  z.c = 35z.x;
  z.b = 32z.x;
  % Marking
  pickup thick;
  drawoptions(withcolor red);
  for k = 1 upto 5:
    drawdot z.a[k];
  endfor;
  draw btex $A_1$ etex shifted (z.a[1]+(-3pt,-12pt));
  draw btex $A_2$ etex shifted (z.a[2]+(-3pt,-12pt));
  draw btex $A_3$ etex shifted (z.a[3]+(-3pt,-12pt));
  draw btex $\cdots$ etex shifted (z.a[4]+(-3pt,-12pt));
%  draw btex $A_5$ etex shifted (z.a[5]+(0,-12pt));
  drawdot z.c; draw btex $C$ etex shifted (z.c+(-3pt,-12pt));
  drawdot z.b; draw btex $B$ etex shifted (z.b+(-3pt,-12pt));
%  drawoptions(withcolor black);
%  ctlabel(btex Least Upper Bound etex, 20z.x+(0,-20pt));
  % Adjusht!
  z.ll = llcorner currentpicture - (0,5pt);
  z.lr = lrcorner currentpicture - (0,5pt);
  z.ul = ulcorner currentpicture + (0,5pt);
  z.ur = urcorner currentpicture + (0,5pt);
  %pickup pencircle scaled .001pt;
  %draw z.ll--z.lr--z.ur--z.ul--cycle;
  setbounds currentpicture to z.ll--z.lr--z.ur--z.ul--cycle;
endfig;

beginfig(4);
  m := 5bp;
  pickup normal;
  drawoptions(withcolor blue);
  % Circle
  draw fullcircle scaled 10m shifted (10m,0);
  % Ellipse
  draw fullcircle xscaled 8m yscaled 10m rotated 30 shifted (25m,0);
  % Parabola
  draw ((0,-4m)..controls (4m,6m) and (8m,6m)..(12m,-4m)) shifted (34m,0);
  % Hyperbola
  draw ((0,-4m)..controls (6m,6m) and (6m,6m)..(12m,-4m)) shifted (49m,0);
  % Labels
  drawoptions(withcolor .4white);
  ctlabel(btex Circle etex, (10m,-7m));
  ctlabel(btex Ellipse etex, (25m,-7m));
  ctlabel(btex Parabola etex, (40m,-7m));
  ctlabel(btex Hyperbola etex, (55m,-7m));
endfig;

beginfig(5);
  m := 5bp;
  pickup normal;
  drawoptions(withcolor blue);
  % Ellipse
  path p; p = fullcircle xscaled 15m yscaled 19m rotated -30 shifted (15m,12m);
  draw p;
  % Points on ellipse
  z.a = point 0 of p;
  z.b = point 1 of p;
  z.c = point 2 of p;
  z.d = point 3 of p;
  z.e = point 4 of p;
  drawoptions(withcolor red);
  draw z.a--1.1[z.a,z.b]; draw z.e--1.1[z.e,z.b];
  drawoptions(withcolor yellow);
  draw z.a--1.1[z.a,z.c]; draw z.e--1.1[z.e,z.c];
  drawoptions(withcolor green);
  draw z.a--1.1[z.a,z.d]; draw z.e--1.1[z.e,z.d];
  % Marking
  drawoptions(withcolor blue);
  pickup thick;
  drawdot z.a;
  drawdot z.b;
  drawdot z.c;
  drawdot z.d;
  drawdot z.e;
  % Caption
%  drawoptions(withcolor black);
%  ctlabel(btex Steiner's Construction etex, (15m,0m));
endfig;

beginfig(6);
  m := 5bp;
  drawoptions(withcolor blue);
  % Axis
  pickup thin;
  drawarrow (-3m,0)--(18m,0);
  drawarrow (0,-3m)--(0,20m);
  drawarrow ((-3m,0)--(18m,0)) shifted (25m,0);
  drawarrow ((0,-3m)--(0,20m)) shifted (25m,0);
  % Curve
  pickup normal;
  u := 0.1;
  path fun;
  fun = ((0,-2){(10,1)}...(10,3)...{(1,10)}(15,18))
       scaled m;
  draw fun;
  draw fun yscaled(-1) rotated 90 shifted (25m,0);
  % Labels
  %drawoptions(withcolor red);
  %ctlabel(btex A function etex, (15m,-2m));
  %ctlabel(btex It's inverse etex, (40m,-2m));
endfig;

beginfig(7);
  m := 5bp;
  drawoptions(withcolor blue);
  % Axis
  pickup thin;
  drawarrow (-3m,0)--(18m,0);
  drawarrow (0,-3m)--(0,20m);
  drawarrow ((-3m,0)--(18m,0)) shifted (25m,0);
  drawarrow ((0,-3m)--(0,20m)) shifted (25m,0);
  % Curve
  pickup normal;
  u := 0.1;
  path fun;
  fun = ((0,-2){(10,1)}...(10,3)...{(1,10)}(15,18))
       scaled m;
  draw fun;
  draw fun yscaled(-1) rotated 90 shifted (25m,0);
  % Labels
  %drawoptions(withcolor red);
  %ctlabel(btex A function etex, (15m,-2m));
  %ctlabel(btex It's inverse etex, (40m,-2m));
endfig;
end.
