Animation : Tracés de courbes de Lissajous

Voici une petite animation illustrant quelques courbes de Lissajous en fonction des fréquences entières pour le cosinus et le sinus.

animation
Chargement...

lissajous.mp

%@ Maxime Chupin
%@ 3 octobre 2018
 
prologues := 3;
outputtemplate := "svg/%j-%c.svg";
outputformat := "svg";
 
input mpcolornames
  input TEX
 
picture UnBeauPoint;
UnBeauPoint := image(
  fill fullcircle scaled 10pt;
fill fullcircle scaled 8pt withcolor red+green;
);
vardef pointe expr p = draw UnBeauPoint shifted p; enddef;
 
% unité
u:=1cm;
%rayon des cercles
r:=3u;
% séparations entre les cercles
sep := 7u;
 
% nombre de cercles
n := 4;
% points sur les cercles
pair pointCercle[][];
% points des lissajous
pair lissajous[][];
path Lissajous[][];
 
% couleur
color lis[];
 
lis[1]:=LightSalmon1;
lis[2]:=PaleVioletRed2;
lis[3]:=SteelBlue3;
lis[4]:=OliveDrab3;
 
for i:=1 upto n:
  for j:=1 upto n:
    for k:=0 upto 365:
      if k=0:
        Lissajous[i][j]:= r*(cosd(i*k),sind(j*k));
      else:
        Lissajous[i][j]:= Lissajous[i][j]--r*(cosd(i*k),sind(j*k));
      fi;
    endfor;
    Lissajous[i][j] := Lissajous[i][j] shifted (i*sep,-j*sep);
  endfor;
endfor;
 
% les verticales
path verti[];
% les horizontales
path hori[];
 
% le fond
picture fond;
fond = image(
    for k:= 1 upto n:
    draw fullcircle scaled 2r shifted ((k)*sep,0)  withcolor lis[k] withpen pencircle scaled 2pt;
    draw fullcircle scaled 2r shifted (0,-(k)*sep) withcolor lis[k] withpen pencircle scaled 2pt;
    draw TEX(decimal k) scaled 10 shifted ((k)*sep-0.12sep,-0.15sep);
    draw TEX(decimal k) scaled 10 shifted (-0.12sep,-(k)*sep-0.15sep);
    for j:=1 upto n:
      if (k=3) and (j=2):
        draw Lissajous[k][j] withpen pencircle scaled 2pt withcolor Red2;
      else:
        draw Lissajous[k][j] withpen pencircle scaled 2pt ;
      fi;
    endfor;
  endfor;
  );
 
% les différentes images
for j:= 0 upto 359:
  beginfig(j);
    draw fond;
    for k:=1 upto n:
      pointCercle[k][0] := r*(cosd((k)*j),sind((k)*j)) shifted ((k)*sep,0);
      pointCercle[0][k] := r*(cosd((k)*j),sind((k)*j)) shifted (0,-(k)*sep);
      verti[k] := 12[pointCercle[k][0],(xpart pointCercle[k][0], -12u)]-- 12[(xpart pointCercle[k][0], -12u),pointCercle[k][0]];
      hori[k] := 12[pointCercle[0][k],(12u,ypart pointCercle[0][k])]-- 12[(12u,ypart pointCercle[0][k]),pointCercle[0][k]];
      draw verti[k] if(k=3): withcolor Red2 fi;
      draw hori[k] if(k=2): withcolor Red2 fi;
      pointe pointCercle[k][0];
      pointe pointCercle[0][k];
    endfor;
    for k:= 1 upto n:
      for i := 1 upto n:
        lissajous[k][i] := verti[k] intersectionpoint hori[i];
        pointe lissajous[k][i];
      endfor;
    endfor;
    clip currentpicture to (-1.1r,1.1r)--(n*sep+2.1r,r)--(n*sep+2.1r,-n*sep-2r)--(-1.1r,-n*sep-2.1r)--cycle;
  endfig;
endfor;
end.
 

Table des matières