%% colorsweep2.ldf
%% Created by Laurence D. Finston (LDF) Di 22. Aug 06:05:06 CEST 2023

%% * (1) Copyright and License.

%%%% Copyright (C) 2023 Laurence Finston

%%%% This file is free software; you can redistribute it and/or modify 
%%%% it under the terms of the GNU General Public License as published by 
%%%% the Free Software Foundation; either version 3 of the License, or 
%%%% (at your option) any later version.  

%%%% This file is distributed in the hope that it will be useful, 
%%%% but WITHOUT ANY WARRANTY; without even the implied warranty of 
%%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
%%%% GNU General Public License for more details.  

%%%% You should have received a copy of the GNU General Public License 
%%%% along with this file; if not, write to the Free Software 
%%%% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 

%%%% Please send bug reports to Laurence.Finston@gmx.de

%%%% The author can be contacted at: 

%%%% Laurence Finston 
%%%% Laurence.Finston@gmx.de

input "plainldf.lmc";

medium_pen := pencircle scaled (.333mm, .333mm, .333mm);

verbatim_tex "\magnification=1500\font\huge=cmbx12 scaled 4000"
  & "\font\Huge=cmbx12 scaled 6000"
  & "\font\Large=cmbx12 scaled 3000"
  & "\font\LargeA=cmbx12 scaled 3500"
  & "\font\LargeB=cmbx12 scaled 4000"
  & "\font\large=cmbx12 scaled 1600";

%verbatim_metapost "prologues := 3;outputtemplate := \"%j_%3c.eps\";dotlabeldiam:=2mm;";

verbatim_metapost   "outputformat:=\"png\";outputtemplate := \"%j_%3c.png\";"
                  & "outputformatoptions := \"format=rgb antialias=none\";";

%% * (1)

point p[];
point b[];
path q[];
rectangle r[];
transform t[];
picture v[];

triangle T[];

circle c[];

string s;

focus f;

set f with_position (0, 10, -40) with_direction (0, 10, 10) 
  with_distance 45;

numeric frame_wd;
numeric frame_ht;

% \special{papersize=400mm, 225mm} %% Frame size, proportion 16x9
% \hsize=400mm
% \vsize=225mm

%% (* (/ 300 16.0) 9) 168.75

frame_wd := 300mm;
frame_ht := 168.75mm;

rectangle frame;

frame := ((-.5frame_wd, -.5frame_ht), (.5frame_wd, -.5frame_ht),
          (.5frame_wd, .5frame_ht), (-.5frame_wd, .5frame_ht));

p10 := get_center frame;


%% * (1)

color_vector cv;
color c;

% cv += red;
% cv += green;
% cv += blue;
% cv += cyan_rgb;
% cv += magenta_rgb;
% cv += yellow_rgb;
% cv += orange_rgb;
% cv += violet_rgb;
% cv += red;
% cv += green;
% cv += blue;
% cv += cyan_rgb;
% cv += magenta_rgb;
% cv += yellow_rgb;
% cv += orange_rgb;
% cv += violet_rgb;
% cv += rose_pink_rgb;
% cv += spring_green_rgb;
% cv += light_blue_rgb;
% cv += red;
% cv += green;
% cv += blue;
% cv += cyan_rgb;
% cv += magenta_rgb;
% cv += yellow_rgb;
% cv += orange_rgb;
% cv += violet_rgb;
% cv += red;
% cv += green;
% cv += blue;
% cv += cyan_rgb;
% cv += magenta_rgb;
% cv += yellow_rgb;
% cv += orange_rgb;
% cv += violet_rgb;
% cv += rose_pink_rgb;
% cv += spring_green_rgb;
% cv += light_blue_rgb;


%% Red to green
j := 1;
k := 0;
for i = 1 upto 30:
  c := (j-i/30, k+i/30);
  cv += c;
endfor;

%% Green to blue
j := 1;
k := 0;
for i = 1 upto 30:
  c := (0, j-i/30, k+i/30);
  cv += c;
endfor;

%% Blue to yellow
j := 1;
k := 0;
for i = 1 upto 30:
  c := (k+i/30, k+i/30, j-i/30);
  cv += c;
endfor;

%% Yellow to orange
j := 1;
k := 0;
for i = 1 upto 30:
  c := (1, j-i/60, 0);
  cv += c;
endfor;

cv += red; % For insurance.  LDF 2023.08.23.
cv += red;
cv += red;
cv += red;
cv += red;
cv += red;
cv += red;




%% * (1)

pickup medium_pen;

pickup medium_pen;

dot_pen := pencircle scaled (2mm, 2mm, 2mm);

bool do_labels;
do_labels := false; % true; % 


color C[];

%% * (1)

for i = 0 upto 3:
  p[i] := get_point (i) frame;
endfor;

for i = 0 upto 3:
  p[i+4] := mediate(get_point (i) frame, get_point((i+1) mod 4) frame);
endfor;

%% * (1)

beginfig(1000);
  draw frame with_pen big_pen;
  
  s :=   "\vbox to 0pt{\vss\vskip1cm\hbox to 0pt{"
       & "\hss\vbox{\hbox to 300mm{\hfil{\huge Color Sweep Nr.~2}\hfil}\vskip1.5cm"
       & "\hbox to 300mm{\hfil{\Large By}\hfil}\vskip1cm"
       & "\hbox to 300mm{\hfil{\Large Laurence Finston}\hfil}\vskip2.5cm"
       & "\hbox to 300mm{\hfil{\large Copyright (C) 2023 Laurence Finston}\hfil}"
       & "}\hss}\vss}";

  label(s, p10);
endfig with_projection parallel_x_y;

beginfig(1001);
  draw frame with_pen big_pen;
  s := "{\LargeA Quilt Pattern Nr.~1}";
  label(s, p10);
endfig with_projection parallel_x_y;

beginfig(1002);
  draw frame with_pen big_pen;
  s :=   "\vbox to 0pt{\vss\hbox to 0pt{\hss\hbox to 300mm{\hfil{\LargeB The End}\hfil}\hss}\vss}";
  label(s, p10);
endfig with_projection parallel_x_y;

%% * (1)

point a[];

string s;

beginfig(0);
  %unfill frame;
  draw frame with_pen big_pen;

  if do_labels:
    dotlabel.bot("$p_0$", p0) shifted (0, -2);
    dotlabel.bot("$p_1$", p1) shifted (0, -2);
    dotlabel.top("$p_2$", p2) shifted (0, 2);
    dotlabel.top("$p_3$", p3) shifted (0, 2);
    dotlabel.bot("$p_4$", p4) shifted (0, -2);
    dotlabel.rt("$p_5$", p5) shifted (3, 0);;
    dotlabel.top("$p_6$", p6) shifted (0, 2);
    dotlabel.lft("$p_7$", p7) shifted (-2, 0);
  fi;
  
  for i = 0 upto 20:
    a[i] := mediate(p0, p1, i*1/20);
    s := "$\scriptstyle a_{" & decimal (i) & "}$";
    if do_labels:
      dotlabel.bot(s, a[i]);
    fi;

    a[i+31] := mediate(p3, p2, i*1/20);
    s := "$\scriptstyle a_{" & decimal (i+31) & "}$";
    if do_labels:
      label.top(s, a[i+31]) shifted (0, .25);
      drawdot a[i+31] with_pen pencircle scaled (2mm, 2mm, 2mm);
    fi;
  endfor;

  for i = 0 upto 9:
    a[i+21] := mediate(p0, p3, i*1/10);
    s := "$\scriptstyle a_{" & decimal (i+21) & "}$";

    if do_labels:
      dotlabel.lft(s, a[i+21]);
    fi;


    a[i+52] := mediate(p1, p2, i*1/10);
    s := "$\scriptstyle a_{" & decimal (i+52) & "}$";

    if do_labels:
      label.rt(s, a[i+52]) shifted (.25, 0);
      drawdot a[i+52] with_pen pencircle scaled (2mm, 2mm, 2mm);
    fi;
  endfor;

  if do_labels:
    label.bot("$o$", origin) shifted (-4pt, -2pt);
    drawdot origin with_pen dot_pen;
  fi;

  j := 8;
  for i = 0 step 2 until 18:
    draw a[2+i] -- a[23+i];
    p[j] := mediate(a[2+i], a[23+i]);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 0 step 2 until 6:
    draw a[54+i] -- a[43+i];
    p[j] := mediate(a[54+i], a[43+i]);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 0 step 2 until 6:
    draw a[18-i] -- a[54+i];
    p[j] := mediate(a[18-i], a[54+i]);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 0 step 2 until 10:
    draw a[10-i] -- a[51-i];
  endfor;

  for i = 0 step 2 until 6:
    draw a[23+i] -- a[39-i];
    p[j] := mediate(a[23+i], a[39-i]);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = .25 step .25 until .75:
    p[j] := mediate(a23, p26, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/3 step 1/3 until 2/3:
    p[j] := mediate(a25, p27, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  p[j] := mediate(a27, p28);
  s := "$\scriptstyle p_{" & decimal j & "}$";
  if do_labels:
    dotlabel.top(s, p[j]);
  fi;
  j += 1;

  p[j] := mediate(a35, p28);
  s := "$\scriptstyle p_{" & decimal j & "}$";
  if do_labels:
    dotlabel.top(s, p[j]);
  fi;
  j += 1;

  p[j] := mediate(p27, a37, 1/3);
  s := "$\scriptstyle p_{" & decimal j & "}$";
  if do_labels:
    dotlabel.top(s, p[j]);
  fi;
  j += 1;

  p[j] := mediate(p27, a37, 2/3);
  s := "$\scriptstyle p_{" & decimal j & "}$";
  if do_labels:
    dotlabel.top(s, p[j]);
  fi;
  j += 1;

  for i = .25 step .25 until .75:
    p[j] := mediate(p26, a39, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(p12, a41, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;


  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(a2, p13, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(p13, a43, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;


  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(a4, p14, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;


  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(p14, a45, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(a6, p15, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(p15, a47, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(a8, p16, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(p16, a49, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/5 step 1/5 until 4/5:
    p[j] := mediate(a10, p17, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/4 step 1/4 until 3/4:
    p[j] := mediate(a12, p25, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/4 step 1/4 until 3/4:
    p[j] := mediate(p25, a60, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/3 step 1/3 until 2/3:
    p[j] := mediate(a14, p24, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  for i = 1/3 step 1/3 until 2/3:
    p[j] := mediate(p24, a58, i);
    s := "$\scriptstyle p_{" & decimal j & "}$";
    if do_labels:
      dotlabel.top(s, p[j]);
    fi;
    j += 1;
  endfor;

  p[j] := mediate(a16, p23);
  s := "$\scriptstyle p_{" & decimal j & "}$";
  if do_labels:
    dotlabel.top(s, p[j]);
  fi;
  j += 1;

  p[j] := mediate(p23, a56);
  s := "$\scriptstyle p_{" & decimal j & "}$";
  if do_labels:
    dotlabel.top(s, p[j]);
  fi;
  j += 1;

  q0 := a31 -- a33 -- p29 -- cycle;
  b0 := mediate(a32, p29);
  if do_labels:
    label("$\scriptstyle q_0$", b0) with_color blue;
  fi;

  q10 := a0 -- a2 -- p8 -- cycle;
  b10 := mediate(a1, p8);
  if do_labels:
    label("$\scriptstyle q_{10}$", b10) with_color blue;
  fi;


  
  
  n := magnitude(a33 -a31);
  
  for i = 1 upto 9:
    q[i] := q0 shifted (i*n, 0);
    b[i] := b0 shifted (i*n, 0);
    s := "$\scriptstyle q_{" & decimal i & "}$";
    if do_labels:
      label(s, b[i]) with_color blue;
    fi;

    q[10+i] := q10 shifted (i*n, 0);
    b[10+i] := b10 shifted (i*n, 0);
    s := "$\scriptstyle q_{" & decimal (10+i) & "}$";
    if do_labels:
      label(s, b[10+i]) with_color blue;
    fi;
  endfor;

%% *** (3)

  q20 := a31 -- p29 -- a29 -- cycle;
  b20 := mediate(a30, p29);
  if do_labels:
    label("$\scriptstyle q_{20}$", b20) with_color blue;
  fi;

  q25 := a51 -- p21 -- a60 -- cycle;
  b25 := mediate(a61, p21);
  if do_labels:
    label("$\scriptstyle q_{25}$", b25) with_color blue;
  fi;
  

  n := magnitude(a29 - a31);
  
  for i = 1 upto 4:
    q[20+i] := q20 shifted (0, -i*n, 0);
    b[20+i] := b20 shifted (0, -i*n);
    s := "$\scriptstyle q_{" & decimal (20+i) & "}$";
    if do_labels:
      label(s, b[20+i]) with_color blue;
    fi;

    q[25+i] := q25 shifted (0, -i*n, 0);
    b[25+i] := b25 shifted (0, -i*n);
    s := "$\scriptstyle q_{" & decimal (25+i) & "}$";
    if do_labels:
      label(s, b[25+i]) with_color blue;
    fi;
  endfor;

  q30 := p29 -- p28 -- p36 -- a33 -- cycle;
  b30 := mediate(a33, p28);
  s := "$\scriptstyle q_{" & decimal 30 & "}$";
  if do_labels:
    label(s, b[30]) with_color blue;
  fi;
  
  n := magnitude(p36 - p29);
  
  for i = 1 upto 8:
    q[30+i] := q30 shifted (i*n, 0);
    b[30+i] := b30 shifted (i*n, 0);
    s := "$\scriptstyle q_{" & decimal (30+i) & "}$";
    if do_labels:
      label(s, b[30+i]) with_color blue;
    fi;
  endfor;

  q39 := q30 shifted by (a29 - p29);
  b39 := b30 shifted by (a29 - p29);
  s := "$\scriptstyle q_{" & decimal 39 & "}$";
  if do_labels:
    label(s, b[39]) with_color blue;
  fi;

  for i = 1 upto 9:
    q[39+i] := q39 shifted (i*n, 0);
    b[39+i] := b39 shifted (i*n, 0);
    s := "$\scriptstyle q_{" & decimal (39+i) & "}$";
    if do_labels:
      label(s, b[39+i]) with_color blue;
    fi;
  endfor;

  n := magnitude(p34-p28);
  
  for i = 0 upto 8:
    q[49+i] := q[30+i] shifted (0, -n);
    b[49+i] := b[30+i] shifted (0, -n);
    s := "$\scriptstyle q_{" & decimal (49+i) & "}$";
    if do_labels:
      label(s, b[49+i]) with_color blue;
    fi;
  endfor;

  for i = 0 upto 9:
    q[58+i] := q[39+i] shifted (0, -n);
    b[58+i] := b[39+i] shifted (0, -n);
    s := "$\scriptstyle q_{" & decimal (58+i) & "}$";
    if do_labels:
      label(s, b[58+i]) with_color blue;
    fi;
  endfor;

  
  for i = 0 upto 8:
    q[68+i] := q[30+i] shifted (0, -2n);
    b[68+i] := b[30+i] shifted (0, -2n);
    s := "$\scriptstyle q_{" & decimal (68+i) & "}$";
    if do_labels:
      label(s, b[68+i]) with_color blue;
    fi;
  endfor;

  for i = 0 upto 9:
    q[77+i] := q[39+i] shifted (0, -2n);
    b[77+i] := b[39+i] shifted (0, -2n);
    s := "$\scriptstyle q_{" & decimal (77+i) & "}$";
    if do_labels:
      label(s, b[77+i]) with_color blue;
    fi;
  endfor;
  
  for i = 0 upto 8:
    q[87+i] := q[30+i] shifted (0, -3n);
    b[87+i] := b[30+i] shifted (0, -3n);
    s := "$\scriptstyle q_{" & decimal (87+i) & "}$";
    if do_labels:
      label(s, b[87+i]) with_color blue;
    fi;
  endfor;
  
  for i = 0 upto 9:
    q[96+i] := q[39+i] shifted (0, -3n);
    b[96+i] := b[39+i] shifted (0, -3n);
    s := "$\scriptstyle q_{" & decimal (96+i) & "}$";
    if do_labels:
      label(s, b[96+i]) with_color blue;
    fi;
  endfor;

  for i = 0 upto 8:
    q[106+i] := q[30+i] shifted (0, -4n);
    b[106+i] := b[30+i] shifted (0, -4n);
    s := "$\scriptstyle q_{" & decimal (106+i) & "}$";
    if do_labels:
      label(s, b[106+i]) with_color blue;
    fi;
  endfor;

%% *** (3)  

%% ** (2)
  
  v0 := current_picture;

endfig with_projection parallel_x_y;

path_vector pv;

for i = 20 upto 24:
  pv += q[i];
endfor;

for i = 10 upto 19:
  pv += q[i];
endfor;

for i = 29 downto 25:
  pv += q[i];
endfor;

for i = 9 downto 0:
  pv += q[i];
endfor;

pv += q39;
pv += q58;
pv += q77;
pv += q96;

for i = 106 upto 114:
  pv += q[i];
endfor;

pv += q105;
pv += q86;
pv += q67;
pv += q48;

for i = 38 downto 30:
  pv += q[i];
endfor;


pv += q49;
pv += q68;
pv += q87;

for i = 97 upto 104:
  pv += q[i];
endfor;

pv += q95;
pv += q76;
pv += q57;


for i = 47 downto 40:
  pv += q[i];
endfor;

pv += q59;
pv += q78;

for i = 88 upto 94:
  pv += q[i];
endfor;

pv += q85;
pv += q66;

for i = 56 downto 50:
  pv += q[i];
endfor;

pv += q69;

for i = 79 upto 84:
  pv += q[i];
endfor;

pv += q75;

for i = 65 downto 60:
  pv += q[i];
endfor;

for i = 70 upto 74:
  pv += q[i];
endfor;


% message "pv:";
% show pv;
% pause;

n := length pv;
n -= 1;


message "n: " & decimal n;
%pause;

for i = 0 upto n:
  beginfig(i+1);
    current_picture := v0;
    message "Figure " & decimal (i+1);
    for j = i downto 0:
      % message "cv" & decimal i;
      % show cv[j];
      %pause;
      filldraw pv[j] with_fill_color cv[j] with_draw_color black;
    endfor;
  endfig with_projection parallel_x_y;
endfor;

%pause;

%% * (1)

bye;











%% ** (2) 

%% * (1) Emacs-Lisp code for use in indirect buffers when using the          
%%       GNU Emacs editor.  The local variable list is not evaluated when an 
%%       indirect buffer is visited, so it's necessary to evaluate the       
%%       following s-expression in order to use the facilities normally      
%%       accessed via the local variables list.                              
%%       LDF 2004.02.12.

%% (progn (metafont-mode) (outline-minor-mode t) (setq fill-column 80) (ignore '(  
%% )) (setq outline-regexp "%% [*\f]+"))

%% * (1) Local variables for Emacs.

%% Local Variables:
%% mode:Metapost
%% eval:(outline-minor-mode t)
%% eval:(read-abbrev-file abbrev-file-name)
%% outline-regexp:"%% [*\f]+"
%% End:
