Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
ENSEMBLES MANDELBROT-JULIA
Information sur la source
Description
Bon dans la serie snippets totalement inutiles je voudrais celui-là ;-) Donc comme c'est ecrit dans le titre, ce snippet permet de tracer l'ensemble de mandelbrot (et celui de julia qui en resulte) Vous devez commencer a avoir l'habitude, les calculs sont longs a s'effectuer , et plus vous choisirez une taille de fenetre importante ou un nombre d'iterations elevé , plus ce sera longs (plusieurs minutes) En double-cliquant sur un point de mandel, le calcul de l'ensemble de julia va s'effectuer avec les meme propriétés que celles utilisées pour dessiner l'ensemble de mandel Vous pouvez faire un zoom (bon ça n'est pas tout a fait au point) : pour cela faites un rectangle de selection et appuyez sur entrée J'ai prevu de faire ce code sur d'autres language, mais j'ai voulu commencer a le faire avec mirc, pour le fun avis au amateurs, ça peut toujours servir ;o)
Source
- dialog mj {
- title "Mandel & Julia"
- size -1 -1 101 127
- option dbu
- box "Taille fenetre", 1, 5 2 88 39
- text "Largeur :", 2, 13 13 31 8
- edit "300", 3, 49 11 39 11,center
- text "Hauteur :", 4, 13 28 31 8
- edit "200", 5, 49 26 39 11,center
- text "Nombre d'iterations :", 6, 11 92 52 8
- edit "10", 7, 68 90 20 11,center
- button "Lancer !", 8, 33 110 37 13
- box "Options", 9, 6 45 88 61
- text "Couleurs :", 10, 11 57 25 8
- check "", 13, 11 72 9 10
- text "Rafraichir la fenetre en temps réel", 14, 23 71 58 15
- combo 11, 42 55 46 33, size drop
- }
-
- on *:dialog:mj:*:*:{
- if ($devent == init) { didtok mj 11 44 Dégradé gris ,Jaune-Rouge }
- elseif ($devent == sclick && $did == 8) {
- set %ma_width $did(3) | set %ma_height $did(5) | set %ma_iter $did(7) | set %ma_n $iif($did(13).state,-r,-nr)
- set %ma_color $iif(gris isin $did(11),$($rgb(%c,%c,%c),0),$($rgb(255,$calc(255 - %c),0),0))
- set %ma_xmax 2 | set %ma_xmin -2 | set %ma_ymax 1.5 | set %ma_ymin -1.5
- mandel
- }
- elseif ($devent == close) { if (window(@mandel)) close -@ @man* | if ($window(@julia)) close -@ @jul* | if ($hget(color)) hfree $v1 | unset %ma_* }
- }
-
- alias -l mandel {
- window -pd +L @mandel -1 -1 %ma_width $calc(%ma_height + 21) | window -o @mandel
- var %i 1 | while (%i <= %ma_iter) { hadd -m color %i $int($calc((%i - 1)*256 /(%ma_iter - 1))) | inc %i }
- var %ticks $ticks | echo -a Calcul en cours...
- var %dx $calc((%ma_xmax - %ma_xmin) / %ma_width) , %dy $calc((%ma_ymax - %ma_ymin) / %ma_height)
- var %y %ma_ymin , %x %ma_xmin
- var %py 0 | while (%py <= %ma_height) {
- ;dll WhileFix.dll WhileFix
- var %px 0 | while (%px <= %ma_width) {
- var %zr 0 , %zi 0 , %i 1
- while ($calc((%zr)^2 + (%zi)^2) < 4 && %i <= %ma_iter) {
- var %temp %zr
- var %zr $calc((%zr)^2 - (%zi)^2 + %x)
- var %zi $calc(2 * %temp * %zi + %y)
- inc %i
- }
- var %c $iif($hget(color,$calc(%i - 1)),$v1,0)
- drawdot %ma_n @mandel $(%ma_color,2) 1 %px %py
- inc %x %dx
- inc %px
- }
- inc %y %dy
- var %x %ma_xmin
- inc %py
- }
- window -ph @man1 | dc @mandel @man1
- echo -a Ensemble de Mandelbrot calculé en $duration($calc(($ticks - %ticks) / 1000)) , double-cliquez sur un point pour calculer l'ensemble de julia à ces coordonnées
- }
-
- alias -l julia {
- window -pd +L @julia -1 -1 %ma_width $calc(%ma_height + 21) | window -o @julia
- var %ticks $ticks | echo -a Calcul en cours...
- var %dx $calc((%ma_xmax - %ma_xmin) / %ma_width) , %dy $calc((%ma_ymax - %ma_ymin) / %ma_height)
- var %y %ma_ymin , %x %ma_xmin
- var %py 0 | while (%py <= %ma_height) {
- ;dll WhileFix.dll WhileFix
- var %px 0 | while (%px <= %ma_width) {
- var %zr %x , %zi %y , %i 1
- while ($calc((%zr)^2 + (%zi)^2) < 4 && %i <= %ma_iter) {
- var %temp %zr
- var %zr $calc((%zr)^2 - (%zi)^2 + %ma_cx)
- var %zi $calc(2 * %temp * %zi + %ma_cy)
- inc %i
- }
- var %c $iif($hget(color,$calc(%i - 1)),$v1,0)
- drawdot %ma_n @julia $(%ma_color,2) 1 %px %py
- inc %x %dx
- inc %px
- }
- inc %y %dy
- var %x %ma_xmin
- inc %py
- }
- window -ph @jul1 | dc @julia @jul1
- echo -a Ensemble de Julia aux coordonnées %ma_cx + i * %ma_cy calculé en $duration($calc(($ticks - %ticks) / 1000))
- }
-
- menu @mandel {
- sclick { set %ma_bool $mouse.x $mouse.y }
- mouse { if (%ma_bool) { dc @man1 @mandel | drawrect -c @mandel 14 1 %ma_bool $calc($mouse.x - $gettok(%ma_bool,1,32)) $calc($mouse.y - $gettok(%ma_bool,2,32)) } }
- drop {
- if (%ma_bool != $mouse.x $mouse.y) {
- tokenize 32 %ma_bool
- if ($1 < $mouse.x && $2 < $mouse.y) { set %ma_xywh $1-2 $mouse.x $mouse.y } | elseif ($mouse.x > $1 && $mouse.y < $2) { set %ma_xywh $1 $mouse.y $mouse.x $2 }
- elseif ($1 > $mouse.x && $2 < $mouse.y) { set %ma_xywh $mouse.x $2 $1 $mouse.y } | else { set %ma_xywh $mouse.x $mouse.y $1-2 }
- }
- unset %ma_bool
- }
- dclick { $cx($mouse.x,$mouse.y) | julia }
- Enregistrer l'image:{ dc @man1 @mandel | sav @mandel }
- }
-
- menu @julia {
- sclick set %ma_bool $mouse.x $mouse.y
- mouse {
- if (%ma_bool) { dc @jul1 @julia | drawrect -c @julia 14 1 %ma_bool $calc($mouse.x - $gettok(%ma_bool,1,32)) $calc($mouse.y - $gettok(%ma_bool,2,32)) } }
- drop {
- if (%ma_bool != $mouse.x $mouse.y) {
- tokenize 32 %ma_bool
- if ($1 < $mouse.x && $2 < $mouse.y) { set %ma_xywh $1-2 $mouse.x $mouse.y } | elseif ($mouse.x > $1 && $mouse.y < $2) { set %ma_xywh $1 $mouse.y $mouse.x $2 }
- elseif ($1 > $mouse.x && $2 < $mouse.y) { set %ma_xywh $mouse.x $2 $1 $mouse.y } | else { set %ma_xywh $mouse.x $mouse.y $1-2 }
- }
- unset %ma_bool
- }
- Enregistrer l'image:{ dc @jul1 @julia | sav @julia }
- }
-
- alias -l s2c {
- var %limx $calc($abs(%ma_xmin) + $abs(%ma_xmax)) , %limy $calc($abs(%ma_ymin) + $abs(%ma_ymax))
- tokenize 32 $1
- set %ma_xmin $calc(%ma_xmin + ((%limx * $1) / %ma_width))
- set %ma_xmax $calc(%ma_xmin + ((%limx * $3) / %ma_width))
- set %ma_ymin $calc(%ma_ymin + ((%limy * $2) / %ma_height))
- set %ma_ymax $calc(%ma_ymin + ((%limy * $4) / %ma_height))
- }
-
- alias -l cx {
- var %limx $calc($abs(%ma_xmin) + $abs(%ma_xmax)) , %limy $calc($abs(%ma_ymin) + $abs(%ma_ymax))
- set %ma_cx $calc(%ma_xmin + ((%limx * $1) / %ma_width))
- set %ma_cy $calc(%ma_ymin + ((%limy * $2) / %ma_height))
- }
-
- alias m&j dialog $iif($dialog(mj),-v,-m) mj mj
- alias -l sav { var %img $+(",$$sfile($+($scriptdir,\*.bmp),Choissiez le répertoire et le nom de l'image qui va être sauvegardée,&Sauvegarder),") | drawsave $1 %img }
- alias -l dc { drawcopy $1 0 0 $window($1).w $window($1).h $2 0 0 }
- on *:keydown:@mandel:13:{ $s2c(%ma_xywh) | mandel }
- on *:keydown:@julia:13:{ $s2c(%ma_xywh) | julia }
- on *:close:@mandel: { hfree color | unset %ma_* | window -c @man1 | if ($window(@julia)) close -@ @jul* }
- on *:close:@julia:window -c @jul1
dialog mj {
title "Mandel & Julia"
size -1 -1 101 127
option dbu
box "Taille fenetre", 1, 5 2 88 39
text "Largeur :", 2, 13 13 31 8
edit "300", 3, 49 11 39 11,center
text "Hauteur :", 4, 13 28 31 8
edit "200", 5, 49 26 39 11,center
text "Nombre d'iterations :", 6, 11 92 52 8
edit "10", 7, 68 90 20 11,center
button "Lancer !", 8, 33 110 37 13
box "Options", 9, 6 45 88 61
text "Couleurs :", 10, 11 57 25 8
check "", 13, 11 72 9 10
text "Rafraichir la fenetre en temps réel", 14, 23 71 58 15
combo 11, 42 55 46 33, size drop
}
on *:dialog:mj:*:*:{
if ($devent == init) { didtok mj 11 44 Dégradé gris ,Jaune-Rouge }
elseif ($devent == sclick && $did == 8) {
set %ma_width $did(3) | set %ma_height $did(5) | set %ma_iter $did(7) | set %ma_n $iif($did(13).state,-r,-nr)
set %ma_color $iif(gris isin $did(11),$($rgb(%c,%c,%c),0),$($rgb(255,$calc(255 - %c),0),0))
set %ma_xmax 2 | set %ma_xmin -2 | set %ma_ymax 1.5 | set %ma_ymin -1.5
mandel
}
elseif ($devent == close) { if (window(@mandel)) close -@ @man* | if ($window(@julia)) close -@ @jul* | if ($hget(color)) hfree $v1 | unset %ma_* }
}
alias -l mandel {
window -pd +L @mandel -1 -1 %ma_width $calc(%ma_height + 21) | window -o @mandel
var %i 1 | while (%i <= %ma_iter) { hadd -m color %i $int($calc((%i - 1)*256 /(%ma_iter - 1))) | inc %i }
var %ticks $ticks | echo -a Calcul en cours...
var %dx $calc((%ma_xmax - %ma_xmin) / %ma_width) , %dy $calc((%ma_ymax - %ma_ymin) / %ma_height)
var %y %ma_ymin , %x %ma_xmin
var %py 0 | while (%py <= %ma_height) {
;dll WhileFix.dll WhileFix
var %px 0 | while (%px <= %ma_width) {
var %zr 0 , %zi 0 , %i 1
while ($calc((%zr)^2 + (%zi)^2) < 4 && %i <= %ma_iter) {
var %temp %zr
var %zr $calc((%zr)^2 - (%zi)^2 + %x)
var %zi $calc(2 * %temp * %zi + %y)
inc %i
}
var %c $iif($hget(color,$calc(%i - 1)),$v1,0)
drawdot %ma_n @mandel $(%ma_color,2) 1 %px %py
inc %x %dx
inc %px
}
inc %y %dy
var %x %ma_xmin
inc %py
}
window -ph @man1 | dc @mandel @man1
echo -a Ensemble de Mandelbrot calculé en $duration($calc(($ticks - %ticks) / 1000)) , double-cliquez sur un point pour calculer l'ensemble de julia à ces coordonnées
}
alias -l julia {
window -pd +L @julia -1 -1 %ma_width $calc(%ma_height + 21) | window -o @julia
var %ticks $ticks | echo -a Calcul en cours...
var %dx $calc((%ma_xmax - %ma_xmin) / %ma_width) , %dy $calc((%ma_ymax - %ma_ymin) / %ma_height)
var %y %ma_ymin , %x %ma_xmin
var %py 0 | while (%py <= %ma_height) {
;dll WhileFix.dll WhileFix
var %px 0 | while (%px <= %ma_width) {
var %zr %x , %zi %y , %i 1
while ($calc((%zr)^2 + (%zi)^2) < 4 && %i <= %ma_iter) {
var %temp %zr
var %zr $calc((%zr)^2 - (%zi)^2 + %ma_cx)
var %zi $calc(2 * %temp * %zi + %ma_cy)
inc %i
}
var %c $iif($hget(color,$calc(%i - 1)),$v1,0)
drawdot %ma_n @julia $(%ma_color,2) 1 %px %py
inc %x %dx
inc %px
}
inc %y %dy
var %x %ma_xmin
inc %py
}
window -ph @jul1 | dc @julia @jul1
echo -a Ensemble de Julia aux coordonnées %ma_cx + i * %ma_cy calculé en $duration($calc(($ticks - %ticks) / 1000))
}
menu @mandel {
sclick { set %ma_bool $mouse.x $mouse.y }
mouse { if (%ma_bool) { dc @man1 @mandel | drawrect -c @mandel 14 1 %ma_bool $calc($mouse.x - $gettok(%ma_bool,1,32)) $calc($mouse.y - $gettok(%ma_bool,2,32)) } }
drop {
if (%ma_bool != $mouse.x $mouse.y) {
tokenize 32 %ma_bool
if ($1 < $mouse.x && $2 < $mouse.y) { set %ma_xywh $1-2 $mouse.x $mouse.y } | elseif ($mouse.x > $1 && $mouse.y < $2) { set %ma_xywh $1 $mouse.y $mouse.x $2 }
elseif ($1 > $mouse.x && $2 < $mouse.y) { set %ma_xywh $mouse.x $2 $1 $mouse.y } | else { set %ma_xywh $mouse.x $mouse.y $1-2 }
}
unset %ma_bool
}
dclick { $cx($mouse.x,$mouse.y) | julia }
Enregistrer l'image:{ dc @man1 @mandel | sav @mandel }
}
menu @julia {
sclick set %ma_bool $mouse.x $mouse.y
mouse {
if (%ma_bool) { dc @jul1 @julia | drawrect -c @julia 14 1 %ma_bool $calc($mouse.x - $gettok(%ma_bool,1,32)) $calc($mouse.y - $gettok(%ma_bool,2,32)) } }
drop {
if (%ma_bool != $mouse.x $mouse.y) {
tokenize 32 %ma_bool
if ($1 < $mouse.x && $2 < $mouse.y) { set %ma_xywh $1-2 $mouse.x $mouse.y } | elseif ($mouse.x > $1 && $mouse.y < $2) { set %ma_xywh $1 $mouse.y $mouse.x $2 }
elseif ($1 > $mouse.x && $2 < $mouse.y) { set %ma_xywh $mouse.x $2 $1 $mouse.y } | else { set %ma_xywh $mouse.x $mouse.y $1-2 }
}
unset %ma_bool
}
Enregistrer l'image:{ dc @jul1 @julia | sav @julia }
}
alias -l s2c {
var %limx $calc($abs(%ma_xmin) + $abs(%ma_xmax)) , %limy $calc($abs(%ma_ymin) + $abs(%ma_ymax))
tokenize 32 $1
set %ma_xmin $calc(%ma_xmin + ((%limx * $1) / %ma_width))
set %ma_xmax $calc(%ma_xmin + ((%limx * $3) / %ma_width))
set %ma_ymin $calc(%ma_ymin + ((%limy * $2) / %ma_height))
set %ma_ymax $calc(%ma_ymin + ((%limy * $4) / %ma_height))
}
alias -l cx {
var %limx $calc($abs(%ma_xmin) + $abs(%ma_xmax)) , %limy $calc($abs(%ma_ymin) + $abs(%ma_ymax))
set %ma_cx $calc(%ma_xmin + ((%limx * $1) / %ma_width))
set %ma_cy $calc(%ma_ymin + ((%limy * $2) / %ma_height))
}
alias m&j dialog $iif($dialog(mj),-v,-m) mj mj
alias -l sav { var %img $+(",$$sfile($+($scriptdir,\*.bmp),Choissiez le répertoire et le nom de l'image qui va être sauvegardée,&Sauvegarder),") | drawsave $1 %img }
alias -l dc { drawcopy $1 0 0 $window($1).w $window($1).h $2 0 0 }
on *:keydown:@mandel:13:{ $s2c(%ma_xywh) | mandel }
on *:keydown:@julia:13:{ $s2c(%ma_xywh) | julia }
on *:close:@mandel: { hfree color | unset %ma_* | window -c @man1 | if ($window(@julia)) close -@ @jul* }
on *:close:@julia:window -c @jul1
Conclusion
/m&j pour l'utiliser
(il est vrai que j'aurai plus ne faire qu'un seul alias regroupant mendel et julia, mais pour la compréhension, c'est plus clair ainsi)
Historique
- 29 août 2005 18:49:32 :
- trompé de catégorie
Sources de la même categorie
Commentaires
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | | | 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 | |
|
|