%% sinewaves6.ldf
%% Created by Laurence D. Finston (LDF) Sa 19. Aug 10:49:22 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=\magstep2\font\huge=cmbx12 scaled 4000"
             & "\font\Large=cmbx12 scaled 3000\font\large=cmbx12 scaled 1600";

bool do_png;
do_png := false; % true; % 

if do_png:
  verbatim_metapost   "outputformat:=\"png\";outputtemplate := \"%j_%3c.png\";"
                    & "outputformatoptions := \"format=rgb antialias=none\";";
else:
  verbatim_metapost "prologues := 3;outputtemplate := \"%j_%3c.eps\";dotlabeldiam:=2mm;";
fi;




%% * (1)

point p[];
path q[];
rectangle r[];
transform t[];

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

%% (* (/ 30.0 16) 9) 16.875


picture v[];

pen huge_pen;

huge_pen := pensquare scaled (2mm, 2mm, 2mm);


%% * (1)

pickup medium_pen;


sinewave s[][];

pickup medium_pen;

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

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

set s[0][0] with_amplitude 8 with_frequency 1 with_phase 0 with_increment .1
  with_period 8pi;


r0 := get_rectangle s[0][0] with_scaled (1, 1.025);


% message "r0:";
% show r0;
% pause;

p11 := get_center r0;


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


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

rectangle frame;

n := magnitude(p2 - p1);

frame_ht := n;

frame_wd := n * 16/9;

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

p10 := get_center frame;

shift frame by (p11 - p10);



%% * (1)

beginfig(300);
  draw frame with_pen big_square_pen;
  s := "\setbox0=\hbox{{\huge Sine Waves Nr.~6}}"
       &  "\vbox{\copy0\vskip2cm"
       & "\hbox to \wd0{\hss{\Large By}\hss}\vskip1cm"
       & "\hbox to \wd0{\hss{\Large Laurence Finston}\hss}\vskip2.5cm"
       & "\hbox to \wd0{\hss{\large Copyright (C) 2023 Laurence Finston}\hss}"
       & "}";
  label(s, p11);
  %dotlabel.top("$p_{10}$", p11);
endfig with_projection parallel_x_y;

beginfig(400);
  draw frame with_pen big_square_pen;
  s :=   "\hbox{\hfil{\huge The End}\hfil}";
  label(s, p11);
  %dotlabel.top("$p_{11}$", p11);
endfig with_projection parallel_x_y;

%% * (1)

for i = 0 upto 7:
  k := 0;
  for j = .5 step .5 until 8: % 16 sinewaves
    %message "k: " & decimal k;
    set s[i][k] with_amplitude j with_frequency 1 with_phase (-i*.25pi) with_increment .1
      with_period 8pi;
    k += 1;
  endfor;
endfor;

path Q;

for i = 0 upto 15:
  beginfig(i);
    if do_png:
      fill frame;
      unfill r0;
    fi;
    draw frame with_pen big_square_pen;
    draw r0 with_pen big_pen;
    for j = 0 upto i:
      n := i mod 8;
      draw s[n][j] with_pen big_pen;
    endfor;
endfig with_projection parallel_x_y;
endfor;

%% * (1) Descending

m := 0;
i := 14;
for j := 0 upto 13:
  beginfig(j+16);
    if do_png:
      fill frame;
      unfill r0;
    fi;
    draw frame with_pen big_square_pen;
    draw r0 with_pen big_pen;
    
    u := m mod 8;
    
    for k = i downto 0:
      n := i mod 8;
      draw s[u][k] with_pen big_pen;
    endfor;
  endfig with_projection parallel_x_y;
  i -= 1;
  m += 1;
endfor;

%% * (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:
