Apprendre Maple Fractales
 
  Page d'accueilPage d'accueil   RechercherRechercher   Forum de discussionForum de discussion   ContactContact   SommaireSommaire 
  Cours MapleCours Maple   Travaux dirigésTravaux dirigés   Thèmes d'activitésThèmes d'activités   MapletsMaplets 
Ecran MapleEcran Maple  TéléchargementTéléchargement  BibliographieBibliographie  LiensLiens  

 

Page d'accueil   Maplets   << Page précédente   Page suivante >>


Fractales
© Alain Le Stang - "Apprendre Maple" - 2004
Sélectionner Edit/Execute/Worksheet ou cliquer le bouton !!! pour exécuter ce Maplet.

 

 

> restart:
with(plots): with(plottools): with(StringTools): with(Maplets): with(Maplets[Elements]):

 
> nomFichier:='nomFichier': nouvGraphe:=NULL:
 
> Fractale1:=proc(n,M)
  local k,L,a,b,c,d,e,f,N;
  if n=0 then N:=op(M)
  else
         L:=Fractale1(n-1,M);
         N:=NULL:
         for k to nops(L)-1 do
               a:=evalf((2*L[k][1]+L[k+1][1])/3):b:=evalf((2*L[k][2]+L[k+1][2])/3):
               c:=evalf((L[k][1]+2*L[k+1][1])/3):d:=evalf((L[k][2]+2*L[k+1][2])/3):
               e:=evalf(1/2*(a-c-sqrt(3)*(b-d))+c):f:=evalf(-1/2*(-sqrt(3)*(a-c)-(b-d))+d):
               N:=N,L[k],[a,b],[e,f],[c,d];
               if k=nops(L)-1 then N:=N,L[k+1] end if;
         end do;
  end if;
  [N]
end proc:
 
> plot(Fractale1(1,[[0,0],[1,0],[0.5,evalf(sqrt(3)/2)],[0,0]]),scaling=constrained,axes=none);

 

[Plot]

> Fractale2:=proc(n,M)
  local k,L,a,b,c,d,e,f,N;
  if n=0 then N:=op(M)
  else
         L:=Fractale2(n-1,M);
         N:=NULL:
         for k to nops(L)-1 do
               a:=evalf((2*L[k][1]+L[k+1][1])/3):b:=evalf((2*L[k][2]+L[k+1][2])/3):
               c:=evalf((L[k][1]+2*L[k+1][1])/3):d:=evalf((L[k][2]+2*L[k+1][2])/3):
               e:=evalf(-1/2*(c-a+sqrt(3)*(d-b))+c):f:=evalf(-1/2*(sqrt(3)*(-c+a)+d-b)+d):
               N:=N,L[k],[a,b],[e,f],[c,d];
               if k=nops(L)-1 then N:=N,L[k+1] end if;
         end do;
  end if;
  [N]
end proc:
 
> plot(Fractale2(1,[[0,0],[1,0],[0.5,evalf(sqrt(3)/2)],[0,0]]),scaling=constrained,axes=none);

 

[Plot]

> Fractale3:=proc(n,M)
  local k,L,a,b,c,d,e,f,g,h,N;
  if n=0 then N:=op(M)
  else
         L:=Fractale3(n-1,M);
         N:=NULL:
         for k to nops(L)-1 do
               a:=evalf((2*L[k][1]+L[k+1][1])/3):b:=evalf((2*L[k][2]+L[k+1][2])/3):
               c:=evalf((L[k][1]+2*L[k+1][1])/3):d:=evalf((L[k][2]+2*L[k+1][2])/3):
               e:=evalf((2*L[k][1]-L[k][2]+L[k+1][1]+L[k+1][2]))/3:
               f:=evalf((L[k][1]+2*L[k][2]-L[k+1][1]+L[k+1][2]))/3:
               g:=e+(L[k+1][1]-L[k][1])/3: h:=f+(L[k+1][2]-L[k][2])/3:
               N:=N,L[k],[a,b],[e,f],[g,h],[c,d];
               if k=nops(L)-1 then N:=N,L[k+1] end if;
         end do;
  end if;
  [N]
end proc:
 
> plot(Fractale3(1,[[0,0],[1,0],[0.5,evalf(sqrt(3)/2)],[0,0]]),scaling=constrained,axes=none);
 

 

[Plot]

> Fractale4:=proc(n,M)
  local k,L,a,b,c,d,e,f,g,h,N;
  if n=0 then N:=op(M)
  else
         L:=Fractale4(n-1,M);
         N:=NULL:
         for k to nops(L)-1 do
               a:=evalf((2*L[k][1]+L[k+1][1])/3):b:=evalf((2*L[k][2]+L[k+1][2])/3):
               c:=evalf((L[k][1]+2*L[k+1][1])/3):d:=evalf((L[k][2]+2*L[k+1][2])/3):
               e:=evalf((2*L[k][1]+L[k][2]+L[k+1][1]-L[k+1][2]))/3:
               f:=evalf((-L[k][1]+2*L[k][2]+L[k+1][1]+L[k+1][2]))/3:
               g:=e+(L[k+1][1]-L[k][1])/3: h:=f+(L[k+1][2]-L[k][2])/3:
               N:=N,L[k],[a,b],[e,f],[g,h],[c,d];
               if k=nops(L)-1 then N:=N,L[k+1] end if;
         end do;
  end if;
  [N]
end proc:
 
> plot(Fractale4(1,[[0,0],[1,0],[0.5,evalf(sqrt(3)/2)],[0,0]]),scaling=constrained,axes=none);

 

[Plot]

> Fractale5:=proc(n,M)
  local k,L,a,b,c,d,e,f,g,h,N;
  if n=0 then N:=op(M)
  else
         L:=Fractale5(n-1,M);
         N:=NULL:
         for k to nops(L)-1 do
               a:=evalf((L[k][1]+2*L[k+1][1])/3):b:=evalf((L[k][2]+2*L[k+1][2])/3):
               c:=evalf(-b+L[k+1][1]+L[k+1][2]):d:=evalf(a-L[k+1][1]+L[k+1][2]):
               e:=2*L[k+1][1]-c: f:=2*L[k+1][2]-d:
               N:=N,L[k],[a,b],[c,d],[a,b],[e,f];
         end do;
  end if;
  [N]
end proc:
 
> plot(Fractale5(1,[[0,0],[1,0],[0.5,evalf(sqrt(3)/2)],[0,0]]),scaling=constrained,axes=none);

 

[Plot]

> fractale:=proc()
global nouvGraphe;
local alg,nb,f,boolC,r,g,b,L,M,couleur;
alg:=Maplets:-Tools:-Get('algo'('value')):
nb:=Ord(Maplets:-Tools:-Get('n'('value')))-48:
f:=Maplets:-Tools:-Get('fig'('value')):
boolC:=Maplets:-Tools:-Get('rndCol'('value')):
r:=Maplets:-Tools:-Get('rs'('value')):
g:=Maplets:-Tools:-Get('gs'('value')):
b:=Maplets:-Tools:-Get('bs'('value')):
L:=figure(f);
if alg="Fractale 1" then M:=Fractale1(convert(nb,float),L)
elif alg="Fractale 2" then M:=Fractale2(convert(nb,float),L)
elif alg="Fractale 3" then M:=Fractale3(convert(nb,float),L)
elif alg="Fractale 4" then M:=Fractale4(convert(nb,float),L)
else M:=Fractale5(convert(nb,float),L) end if:
if boolC=false then couleur:=COLOR(RGB,r/255,g/255,b/255):
 nouvGraphe:=plots[display](plot(M,color=couleur),scaling=constrained,axes=none)
else
 nouvGraphe:=plots[display](CouleurAleatoire(M),axes=none,scaling=constrained)   
end if:
end proc:

 


 

> CouleurAleatoire:=proc(L)
local k,h,A;
h:=rand(0..255): A:=NULL:
for k to nops(L)-1 do
 A:=A,line(L[k],L[k+1],color=COLOR(RGB,h()/255,h()/255,h()/255))
end do:
end proc:
 

 

> majEtiquetteCouleur:=proc()
local r,g,b;
r:=Maplets:-Tools:-Get('rs'('value')):
g:=Maplets:-Tools:-Get('gs'('value')):
b:=Maplets:-Tools:-Get('bs'('value')):
Maplets:-Tools:-Set('col'('background')=COLOR(RGB,r/255,g/255,b/255))
end proc:
 

 

> polygone_regulier:=proc(n::posint)
local k,x,y;
 for k from 0 to n do
   x[k]:=evalf(cos(k*2*Pi/n)):y[k]:=evalf(sin(k*2*Pi/n))
 end do;
 [seq([x[k],y[k]],k=0..n)]
end proc:
 

 

> figure:=proc(f)
local k,n,fg,hasard;
if f="Segment" then return [[-1,0],[1,0]]
elif f="Triangle équilatéral" then return polygone_regulier(3)
elif f="Carré" then return polygone_regulier(4)
elif f="Pentagone régulier" then return polygone_regulier(5)
elif f="Hexagone régulier" then  return polygone_regulier(6)
elif f="Octogone régulier" then return polygone_regulier(8)
else
randomize():
n:=rand(3..6):hasard:=rand(-100..100):fg:=NULL:
for k to n() do
 fg:=fg,[hasard()/100,hasard()/100]  
end do:
[fg]
end if:
end proc:

 

Procédures d'enregistrement du graphique sous format .gif :

> Enregistrer := proc()
global nomFichier,nouvGraphe;
if assigned( nomFichier ) then
  plotsetup( 'gif', 'plotoutput' = nomFichier );
  print( nouvGraphe );
  plotsetup( 'default' );
  nomFichier:='nomFichier'
else
  EnregSous();
end if;
end proc:
 

 

> EnregSous := proc()
global nomFichier;
local nnomFichier;
  try
    nnomFichier := Maplets:-Examples:-GetFile(
    'title' = "Enregistrer sous",
    'filefilter' = "*.gif",
    'approvecaption' = "Enregistrer"
     );
  catch:
    return;
  end try;
  if nnomFichier[-4..-1] = ".gif" then
    nomFichier := nnomFichier;
  else
    nomFichier := cat( nnomFichier, ".gif" );
  end if;
 Enregistrer();
end proc:
 

 

Maplet "Fractales":

> fractalesMaplet := Maplet( 'onstartup'=RunWindow(FenPrinc),
 Window[FenPrinc]('title' = "Fractales", 'menubar'='Menu', 'layout' = fractaleLayout,width=675, height=500),
 Window['FenApropos']('title' = "A propos", 'layout' = 'AproposLayout', 'width'=350, 'height'=250),
 MenuBar['Menu'](
 Menu("Fichier",
   MenuItem("Enregistrer", 'onclick'= 'A2' ),
   MenuSeparator(),
   MenuItem("Quitter", Shutdown())
 ),
 Menu("Aide",
   MenuItem("A propos", 'onclick'=RunWindow('FenApropos'))
 )
 ),
 BoxLayout[fractaleLayout](inset=0,
   BoxColumn['cadre'](border=true, inset=0, spacing=0, caption="Représentation:",  
     Plotter[PL]()
   ),
   BoxColumn(inset=0, spacing=0,
     BoxRow(inset=0,spacing=0,
       Label(" ")
     ),
     BoxRow(inset=0,spacing=0,
       "Type de fractale:"
     ),
     BoxRow(inset=0, spacing=0,
       DropDownBox[algo]("Fractale 1",["Fractale 1","Fractale 2","Fractale 3","Fractale 4","Fractale 5"])
     ),
     BoxRow(inset=0,spacing=0,
       Label(" ")
     ),  
     BoxRow(inset=0,spacing=0,
       "Figure de départ:"
     ),
     BoxRow(inset=0, spacing=0,
       DropDownBox[fig]("Segment",["Segment","Triangle équilatéral","Carré", "Pentagone régulier", "Hexagone régulier", "Octogone régulier","Aléatoire"])
     ),  
     BoxRow(inset=0,spacing=0,
       Label(" ")
     ),
     BoxRow(inset=0,spacing=0,
       "Nombre d'itérations:"
     ),
     BoxRow(inset=0, spacing=0,
       DropDownBox[n]("0",["0","1","2","3","4","5"])
     ),
     BoxRow(inset=0,spacing=0,
       Label(" ")
     ),
     BoxRow(inset=0, spacing=0,
       CheckBox[rndCol](false, caption="Couleurs aléatoires")
     ),
     BoxRow(inset=0, spacing=0,
       BoxColumn(inset=0, spacing=0,
         Label("    R",foreground=red),
         Slider[rs](filled=true, lower=0, majorticks=20, minorticks=5, orientation=vertical, snapticks=false,upper=255,value=0,onchange=Evaluate('function'="majEtiquetteCouleur"))
       ),
       BoxColumn(inset=0, spacing=0,
         Label("    V",foreground=green),
         Slider[gs](filled=true, lower=0, majorticks=20, minorticks=5, orientation=vertical, snapticks=false,upper=255,value=0,onchange=Evaluate('function'="majEtiquetteCouleur"))
       ),
       BoxColumn(inset=0, spacing=0,
         Label("    B",foreground=blue),
         Slider[bs](filled=true,lower=0,majorticks=20,minorticks=5,  orientation=vertical, snapticks=false,upper=255,value=0,onchange=Evaluate('function'="majEtiquetteCouleur"))
       )
     ),
     BoxRow(inset=0, spacing=0,
       Label['col']("                      ", 'background'=black )
     ),
     BoxRow(inset=0,spacing=0,
       Label(" ")
     ),
     [ Button[trace]("Tracer",'onclick'=A1),
       Button("Enregistrer",'onclick'=A2),
       Button("Quitter", CloseWindow(FenPrinc) ) ],
     BoxRow(inset=0,spacing=0,
       Label(" ")
     )
   )
 ),
BoxLayout['AproposLayout'](
BoxColumn('border'=true, 'inset'=0, 'spacing'=0,
  Label("Fractales",'font' = Font("default", bold, 24)),
  Label("© Alain Le Stang - ""Apprendre Maple"" - 2004"),
  Button("Fermer", CloseWindow('FenApropos'))
)
),

Action[A1](Evaluate(PL = 'fractale ()')),
Action[A2](Evaluate('function'="Enregistrer"))
):

 

> Display(fractalesMaplet);
 

 

haut de cette page


©  - Alain Le Stang - Navigation optimisée pour une résolution 1024 x 768.