%% sinewaves12.ldf
%% Created by Laurence D. Finston (LDF) Mo 21. Aug 23:45:54 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=\magstep3\font\Huge=cmbx12 scaled 6000"
             & "\font\huge=cmbx12 scaled 5000"
             & "\font\Large=cmbx12 scaled 4000\font\LargeA=cmbx12 scaled 3500\font\large=cmbx12 scaled 2500";

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

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

numeric frame_wd;
numeric frame_ht;

frame_ht := 25;
frame_wd := frame_ht * 16/9;

rectangle frame;

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

shift frame (.4frame_wd, 0);

point p[];

p0 := get_center frame;

sinewave s[];

pen huge_pen;

huge_pen := pencircle scaled (4mm, 4mm, 4mm);

%% * (1)

string s;

beginfig(1000);
  fill frame with_color black;
  s := "\setbox0=\hbox{{\huge Sine Waves Nr.~12}}"
       &  "\vbox{\vskip1cm\copy0\vskip2cm"
       & "\hbox to \wd0{\hss{\Large By}\hss}\vskip2cm"
       & "\hbox to \wd0{\hss{\Large Laurence Finston}\hss}\vskip2.5cm"
       & "\hbox to \wd0{\hss{\large Copyright (C) 2023 Laurence Finston}\hss}"
       & "}";

  label(s, p0) with_color white;
  
endfig with_projection parallel_x_y;

beginfig(1001);
  fill frame with_color black;
  s :=  "\hbox{{\LargeA Random Perturbations Nr.~1}}";
  label(s, p0) with_color white;
endfig with_projection parallel_x_y;

beginfig(1002);
  fill frame with_color black;
  s :=   "\hbox{\hfil{\Huge The End}\hfil}";
  label(s, p0) with_color white;
endfig with_projection parallel_x_y;



%% * (1)

amp_val := 8;
freq_val := .5;

period_val := 11pi;

m := 0;

color_vector cv;

cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;
cv += cyan;
cv += white;
cv += red;
cv += blue;
cv += yellow;
cv += orange;
cv += green;
cv += dark_green;
cv += violet;

%% * (1)

for i = 0 upto 300:
  beginfig(i);
    fill frame with_color black;

    n := -.25pi * i;
    
    set s0 with_amplitude amp_val with_frequency freq_val with_phase n with_increment 2
      with_period period_val;

    perturb s0 (.025, .4, 2);

    draw s0 with_pen huge_pen with_color cv[m];

    if (i > 0) and ((i mod 32) == 0):
      %message "i > 0 and i mod 32 is 0:  i == " & decimal i;
      m += 1;
      if m >= size cv:
	m := 0;
      fi;
      j := m+12;
      if j >= size cv:
	j := m-12;
      fi;
      k := m+8;
      if k >= size cv:
	k := m-8;
      fi;
      %pause;
    fi;
    
    if i > 100:
      set s1 with_amplitude amp_val+.5 with_frequency freq_val with_phase n-pi with_increment 2
	with_period period_val;

      draw s1 with_pen huge_pen with_color cv[j];
    fi;
     
    if i > 200:
      set s2 with_amplitude amp_val+1 with_frequency freq_val with_phase n-1.5pi with_increment 2
	with_period period_val;
      draw s2 with_pen huge_pen with_color cv[k];
    fi;

  endfig with_projection parallel_x_y;
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:
