% pifpafpropaganda.mp
% L. Nobre G.
% 2012

prologues := 1;
numeric index;
for index=1 upto 15:
beginfig(index);
  numeric u, siz, lena, lenb, lenc, anga, angb, angc, astep;
  numeric deltar, angf, angx;
  u = 7mm;
  siz = 11u;
  lena = 9u;
  lenb = 8u;
  lenc = 4u;
  deltar = 0.25u;
  angf = index/15;
  z1 = (-lenb,siz-lena);
  z2 = (lenb,siz-lena);
  path circa, circb;
  numeric auxa, auxb, auxc, lend;
  auxa = 2*(lena+2*lenc);
  auxb = 2*lena;
  circa = fullcircle scaled auxa shifted z1;
  circb = fullcircle scaled auxb shifted z2;
  z3 = circa intersectionpoint circb;
  anga = angle(z3-z1);
  angb = 180-angle(z3-z2);
  auxc = lena +-+ (lenb-lenc);
  angc = angle(lenb-lenc,auxc);
  show (anga,angc,angb);
  angx = angf[angc,anga];
  astep = (angc-anga)/15;
  z4 = z2+(lenc-lenb,auxc);
  z5 = z1+(lenb-lenc,auxc);
  z6 = z1+lena*dir(anga);
  z7 = 0.5[z6,z3];
  lend = siz-lena+auxc;
  z8 = z7+lend*dir(anga-90);
  pair q;
  q = whatever*(-y8,x8)+0.5z8;
  xpart q = 0;
  message "Length factor: " & decimal( (ypart q)/siz );
  numeric raya, rayb, rayc, angd, rayd;
  rayb = (siz-lena)/3;
  raya = rayb+deltar;
  rayc = raya+deltar;
  rayd = rayb-deltar;
  drawoptions( withcolor blue );
  z101 = (0,-raya);
  z102 = (0,raya);
  z103 = (lena,raya);
  z104 = (lena,-raya);
  path ad, a, b, c, d, ci, ax;
  ad = z101..z102---z103..z104---cycle;
  a = ad rotated angc shifted z1;
  d = ad rotated (180-angc) shifted z2;
  z201 = (0,-rayb);
  z202 = (0,rayb);
  z203 = (2lenb,rayb);
  z204 = (2lenb,-rayb);
  b = (z201..z202---z203..z204---cycle) shifted z1;
  angd = angle(z4);
  z301 = rayc*dir(270-angd);
  z302 = rayc*dir(angd-90);
  z303 = z4+rayc*dir(angd-90);
  z304 = z4+(0,rayc);
  z305 = z5+(0,rayc);
  z306 = z5+rayc*dir(270-angd);
  c = z301..z302---z303..z304---z305..z306---cycle;
  z401 = (0,rayc/sind(90-angd));
  z402 = z4+dir(180+0.5angd)*rayc/sind(0.5*angd); 
  ci = z401--z402--(-x402,y402)--cycle;
  unfill z1--z2--z4--z5--cycle;
  unfill c;
  draw ci;
  draw c;
  unfill b;
  draw b;
  unfill a;
  draw a;
  unfill d;
  draw d;
  ax = fullcircle scaled (2rayd);
  draw ax;
  draw ax shifted z1;
  draw ax shifted z2;
  draw ax shifted z4;
  draw ax shifted z5;
  picture tmp;
  tmp = currentpicture;
  currentpicture := nullpicture;
  drawoptions();
  %draw z1--z2--z4--z5--cycle;
  %draw z1--z2--z3--cycle;
  %draw z8--z7;
  %dotlabels.top(1,2,3,4,5,6,7,8);
  numeric i, diamc;
  pair parp, intp, pa, pb;
  diamc = 4*lenc;
  parp = z1+lena*dir(angx);
  circa := fullcircle scaled diamc shifted parp;
  intp = circa intersectionpoint circb;
  pa = 0.5[parp,intp];
  pb = pa+lend*unitvector((ypart (intp-parp),-xpart (intp-parp)));
  unfill z1--z2--intp--parp--cycle;
  unfill c rotated (angle(intp-parp)) shifted pb;
  draw ci rotated (angle(intp-parp)) shifted pb;
  draw c rotated (angle(intp-parp)) shifted pb;
  unfill b;
  draw b;
  unfill ad rotated angx shifted z1;
  draw ad rotated angx shifted z1;
  unfill ad rotated (angle(intp-z2)) shifted z2;
  draw ad rotated (angle(intp-z2)) shifted z2;
  draw ax shifted pb;
  draw ax shifted z1;
  draw ax shifted z2;
  draw ax shifted intp;
  draw ax shifted parp;  
  for i=angc step -astep until anga:
    parp := z1+lena*dir(i);
    circa := fullcircle scaled diamc shifted parp;
    intp := circa intersectionpoint circb;
    pa := 0.5[parp,intp];
    pb := lend*unitvector((ypart (intp-parp),-xpart (intp-parp)));
    %draw pa--(pa+pb);
    draw (-xpart (pa+pb),ypart (pa+pb)) withpen pencircle scaled 2pt;
    draw (pa+pb) withpen pencircle scaled 2pt;
  endfor;
  draw origin withpen pencircle scaled 3pt;
endfig;
endfor;

beginfig(0);
  draw tmp;
endfig;

end.