Les Snippets

Connexion

fractale de mandelbrot

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 19/02/2008 22:39:17 et initié par coucou747 [Liste]
Vue : 3978
Catégorie(s) : Maths, Algorithme, Graphique
Langages dispo pour ce code :
- ObjectiveCaml
- Tcl



Langage : ObjectiveCaml
Date ajout : 19/02/2008
Posté par coucou747 [Liste]
(* to run : $ ocaml graphics.cma fractale.ml  *)
open Graphics;;
let dX = 400;;
let dY = 400;;
let echelle=100.;;
let maxI=125;; (*le nombre maximal d'iterations*)
(*fait "comme" une boucle for, mais en recursif et en tail-rec*)
let rec each from toend fonction =
    if from = toend then ()
    else (fonction from; each (from+1) toend fonction);;
open Complex;;
let c= {re=0.-.0.727; im=0.1888};; (*parametre*)
(*calcule le nombre d'iterations*)
let rec complexe2int n z =
    if (norm z) < 4. & n < maxI
        then complexe2int (n+1) (add (mul z z) c)
        else n
(*renvoie la couleur a partir du nombre complexe*)
let fonction_complexe_to_color z =
    let n = (complexe2int 0 z) in
    rgb (255*(maxI+1)/(n+1)) (255*(n+1)/(maxI+1)) 0;;
(*paint le point (x, y)*)
let paintPoint x y=
    let z= {re=(float_of_int (x-dX/2)) /. echelle; im=(float_of_int (y-dY/2)) /. echelle}
    in set_color ( fonction_complexe_to_color(z) ); plot x y;;
(*main-like*)
let () =
    let height, width = dX, dY in
        open_graph (Printf.sprintf " %ix%i" height width) ;
        each 0 dX (fun x -> each 0 dY (fun y -> paintPoint x y));
let rec main_loop () = main_loop () in main_loop ();;

Langage : Tcl
Date ajout : 03/08/2009
Posté par gersoo [Liste]
package require Tk
bind all <Escape> {exit}
set xmin -2.2; set xmax 0.8; set ymin -1.1; set ymax 1.1
set width 512; set height $width
set itermax 32
set lclr [list red orange yellow green lightgreen darkblue blue lightblue white black]
set N [llength $lclr]
set tag  1 
set tag1 1
set stop 1
canvas .c -width $width -height $height
button .bfin -text Démarrer -width 8 -command {Mandelbrot [expr {$width/2}]}
button .bstop -text Stopper -width 8 -command {set stop 1}
button .bquit -text Quitter -width 8 -bg darkgrey -command exit 
pack .c 
pack .bfin .bstop .bquit -side left -expand yes -fill x
proc Mandelbrot {a} {
 global stop lclr color N
 global ymin xmin ymax xmax width height
 global tag tag1 itermax
  set dx [expr {($xmax-$xmin)/$a}]
  set dy [expr {($ymax-$ymin)/$a}]
  set bwidth  [expr {$width/$a}]
  set bheight [expr {$height/$a}]
  set tag0 $tag1
  set stop 0
  for {set j 0} {$j < $a} {incr j} {
    if $stop break
    set y [expr {$ymin+$dy*$j}]
    for {set i 0} {$i < $a} {incr i} {
      set x [expr {$xmin+$dx*$i}]
      set iter 0; set color 0
      set zr 0; set zi 0
      while {$zr*$zr+$zi*$zi < 4} {
        if {[incr iter] > $itermax} {
          set color [expr {$N-1}]
          break
        }
        incr color
        set old [expr {$zr*$zr-$zi*$zi+$x}]
        set zi  [expr {2*$zr*$zi+$y}]
        set zr  $old
      }
      if {$tag <= $tag0} {.c delete $tag}
      incr tag 
      set tag1 [.c create rect [expr {$i*$bwidth}] [expr {$j*$bwidth}] \
               [expr {($i+1)*$bwidth}] [expr {($j+1)*$bheight}] \
         -fill [lindex $lclr [expr {$color % $N}]] -outline ""]
      update
    }
  }
  set stop 1
}


Snippets en rapport avec : Mandelbrot, Fractale, Mathematique, Complexe, Ensemble



Codes sources en rapport avec : Mandelbrot, Fractale, Mathematique, Complexe, Ensemble

{JAVA / J2EE} BIBLIOTHÉQUE DE FRACTALS
Cette application en Java permet de générer 10 fractals : mandelbrot, julia, triangle de sierpinki,...

{Javascript / DHTML} FRACTALE DE MANDELBROT
Petite application Javascript permettant de représenter la fractale de Mandelbrot et de zoomer sur c...

{JAVA / J2EE} MANDELBROT MULTI-PROCESSUS
J'espère que l'idée vous plaira, il s'agit de la fractale de Mandelbrot. Un grand nombre d'applets l...

{C / C++ / C++.NET} FRACTALES DE JULIA ET MANDELBROT EN SDL
-Déjà courants sur ce site, les algorithmes pour dessiner les fractales sont assez simple...mais com...

{Visual Basic, VB6, VB.NET, VB 2005} EXPLORATEUR FRACTALE MANDELBROT HAUTE DEFINITION
Explorateur de l'ensemble M de Mandelbrot avec fonctions de rendu avancé, ainsi que le rendu buddhab...

{C / C++ / C++.NET} FRACTALE DE MANDELBROT
C'est très joli ! Se déplacer : flècles directionnelles Zoomer : + (numpad) Dézoomer : - (idem) ...

{Visual Basic, VB6, VB.NET, VB 2005} FRACTALE
Un peit générateur de fractale assez simle en soit mais pas du tout fini.Libre à tous de le peaufine...

{JAVA / J2EE} FRACTALE DE MENDELBROT EN COULEURS
Ce programme reprend celui posté par benoit1 en y ajoutant un dégradé de couleurs. Le dégradé de cou...

{C / C++ / C++.NET} FRACTALE DE MANDELBROT ET JULIA [DJGPP]
Un programme qui dessine une fractale de Mandelbrot ou de Julia. Possibilité d'enregistrer une image...

{Delphi} FRACTALE ESPACE DE MANDELBROT
Un petit programme avec une interface très moyenne, mais on vit de belles courbes. Le moteur de ça e...