Pour le troisième trimestre, on va bosser(j'ai forcé la main à plusieurs collègues

Pour la présentation, on a visionné un extrait de film ("Fractales à la recherche de la dimension cachée").
J'ai fait quelques exemples en Purebasic (Julia, Mandelbrot, arbres).
L'objectif pour les élèves est de créer une œuvre d'art avec les fractales en utilisant la version démo de Purebasic.
Comme il n'y a pas beaucoup de séances, on va leur mâcher un peu le travail.
Ma question est donc la suivante, y a-t-il quelqu'un qui s'est déjà intéressé au "coloriage" des fractales ?
Sur la toile, on voit de super trucs, quelqu'un s'est-il penché sur le problème ?
Je commence les recherches de mon côté, je vous tiendrai au courant.
D'ailleurs, à la fin de la séquence, si ça a donné quelque chose d'intéressant, je posterai des trucs(images, arbres artificiels créés,..etc)
En attendant voici mon mini-explorateur de fractales (code pour débutants, pas de structures, pas de tableaux, peu de mots-clés...etc) :

(la vitesse d'exécution est correcte mais il est conseillé de désactiver le débogueur pour gagner du temps)
Code : Tout sélectionner
; Utilitaire pour les fractales
;Auteur Huitbit
;Avril 2015
;PureBasic 5.24 LTS (Windows - x64)
;***********************************
;- Constantes
Enumeration
#PANEL_MAIN
#CANV_EXPLO_MANDEL
#TEXT_MODE_EMPLOI_EXPLORATEUR
#VALEUR_CONSTANTE_JULIA
#CANV_MANDEL
#CANV_JULIA
#IMG_EXPLO_MANDEL
#IMG_EXPLO_JULIA
#IMG_MANDEL
#IMG_JULIA
#CANV_MANDEL_BTN_SAUVER
#CANV_MANDEL_BTN_RAZ
#CANV_MANDEL_TEXT_Z
#CANV_MANDEL_TEXT_Z_ZOOM
#CANV_JULIA_BTN_SAUVER
#CANV_JULIA_BTN_RAZ
#CANV_JULIA_TEXT_Z
#CANV_JULIA_TEXT_Z_ZOOM
EndEnumeration
;- dimensions écran
;{
ExamineDesktops()
Define.l Lwindow = DesktopWidth(0) * 4 / 5
Define.l Hwindow = DesktopHeight(0) * 4 / 5
;}
IDmandel.l = 0
iterMaxMandel.l = 80
zoomMandel.f = 1
minXMandel.f = -2
maxXMandel.f = 0.6
minYMandel.f = -1.3
maxYMandel.f = 1.3
IDjulia.l = 0
iterMaxJulia.l = 80
zoomJulia.f = 1
minXJulia.f = -2
maxXJulia.f = 2
minYJulia.f = -2
maxYJulia.f = 2
;valeurs initiales des constantes pour l'ensemble de Julia
a.f = -0.772691322542185
b.f = 0.124281466072787
l.l
h.l
x.f
xTemp.f = 0
y.f
zModuleCarre .f
couleur.l
Cx.f
Cy.f
Macro dessinerMandelbrot(IDimage, l, h, minX, maxX, minY, maxY)
If CreateImage(IDimage, l, h) And StartDrawing(ImageOutput(IDimage))
For i = 0 To l
For j = 0 To h
For iter = 0 To iterMaxMandel
couleur = 0
x = minX + (maxX - minX) * i / l
y = minY + (maxY - minY) * j / h
Cx = x
Cy = y
zModuleCarre = x * x + y * y
While zModuleCarre < 4 And couleur < iterMaxMandel
xTemp = x
x = x * x - y * y + Cx
y = 2 * xTemp * y + Cy
zModuleCarre = x * x + y * y
couleur = couleur + 1
Wend ; zModuleCarre < 4 And couleur < iterMax
If zModuleCarre >= 4 Or couleur >= iterMaxMandel
Break
EndIf ; zModuleCarre >= 4 Or couleur >= iterMax
Next iter
col = couleur * 255 / iterMaxMandel
If col <> 0
Box(i, h - j, 1, 1, RGB(col, col, 0))
EndIf
Next j
Next i
StopDrawing()
EndIf ; CreateImage(IDimage, l, h) And StartDrawing(ImageOutput(IDimage))
EndMacro
Macro dessinerJulia(IDimage, Cx, Cy, l, h, minX, maxX, minY, maxY)
If CreateImage(IDimage, l, h) And StartDrawing(ImageOutput(IDimage))
For i = 0 To l
For j = 0 To h
For iter = 0 To iterMaxJulia
couleur = 0
x = minX + (maxX - minX) * i / l
y = minY + (maxY - minY) * j / h
zModuleCarre = x * x + y * y
While zModuleCarre < 4 And couleur < iterMaxJulia
xTemp = x
x = x * x - y * y + Cx
y = 2 * xTemp * y + Cy
zModuleCarre = x * x + y * y
couleur = couleur + 1
Wend ; zModuleCarre < 4 And couleur < iterMax
If zModuleCarre >= 4 Or couleur >= iterMaxJulia
Break
EndIf ; zModuleCarre >= 4 Or couleur >= iterMax
Next iter
col = couleur * 255 / iterMaxJulia
If col <> 0
Box(i, h - j, 1, 1, RGB(col, col, col))
EndIf
Next j
Next i
StopDrawing()
EndIf ; CreateImage(IDimage, l, h) And StartDrawing(ImageOutput(IDimage))
EndMacro
;- PROGRAMME PRINCIPAL
If OpenWindow(0, 0, 0, Lwindow, Hwindow, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
UsePNGImageEncoder()
;- création des images
;{
dessinerMandelbrot(#IMG_MANDEL, Hwindow, Hwindow, minXMandel, maxXMandel, minYMandel, maxYMandel)
dessinerJulia(#IMG_JULIA, a, b, Hwindow, Hwindow, minXJulia, maxXJulia, minYJulia, maxYJulia)
CopyImage(#IMG_JULIA, #IMG_EXPLO_JULIA)
ResizeImage(#IMG_EXPLO_JULIA, Lwindow * 0.50, Lwindow * 0.50)
;}
PanelGadget(#PANEL_MAIN, 0, 0, Lwindow, Hwindow)
LoadFont(0, "Arial", 11, #PB_Font_Bold)
SetGadgetFont(#PB_Default, FontID(0))
;- création des onglets
;{
; onglet : explorateur
AddGadgetItem(#PANEL_MAIN, -1, "Explorateur")
ImageGadget(#IMG_EXPLO_JULIA, 0, 0, Lwindow * 0.50, Lwindow * 0.50, ImageID(#IMG_EXPLO_JULIA))
CanvasGadget(#CANV_EXPLO_MANDEL, Lwindow * 0.50, 0, Lwindow * 0.50, Lwindow * 0.50)
modeEmploi.s = "Cliquez sur l'ensemble de Mandelbrot(à droite) pour voir l'ensemble de Julia correspondant."
modeEmploi = modeEmploi + Chr(13) + Chr(13) + "Sélectionnez l'onglet de votre choix pour zoomer sur la fractale."
modeEmploi = modeEmploi + Chr(13) + "Un fois l'onglet choisi, chaque clic entraînera un agrandissement de l'image."
TextGadget(#TEXT_MODE_EMPLOI_EXPLORATEUR, 0, Lwindow * 0.50, Lwindow, Hwindow / 10, modeEmploi)
TextGadget(#VALEUR_CONSTANTE_JULIA, 0, Lwindow * 0.50 + Hwindow / 10, Lwindow, Hwindow / 10, "Valeur de la constante : z = " + StrF(a, 5) + " + " + StrF(b, 5) + "i")
; onglet Mandelbrot
AddGadgetItem(#PANEL_MAIN, -1, "Mandelbrot")
CanvasGadget(#CANV_MANDEL, 0, 0, Hwindow, Hwindow, #PB_Canvas_Border)
ButtonGadget(#CANV_MANDEL_BTN_SAUVER, Hwindow, 0,(Lwindow - Hwindow) * 0.9, Hwindow / 10, "SAUVEGARDER")
ButtonGadget(#CANV_MANDEL_BTN_RAZ, Hwindow, Hwindow / 10 * 1.1,(Lwindow - Hwindow) * 0.9, Hwindow / 10, "REINITIALISER")
expressionZmandel.s = "z0 EN ATTENTE ..."
TextGadget(#CANV_MANDEL_TEXT_Z, Hwindow, Hwindow / 10 * 2.2,(Lwindow - Hwindow) * 0.9, Hwindow / 20, expressionZmandel, #PB_Text_Border | #PB_Text_Center)
; onglet Julia
AddGadgetItem(#PANEL_MAIN, -1, "Julia")
CanvasGadget(#CANV_JULIA, 0, 0, Hwindow, Hwindow, #PB_Canvas_Border)
ButtonGadget(#CANV_JULIA_BTN_SAUVER, Hwindow, 0,(Lwindow - Hwindow) * 0.9, Hwindow / 10, "SAUVEGARDER")
ButtonGadget(#CANV_JULIA_BTN_RAZ, Hwindow, Hwindow / 10 * 1.1,(Lwindow - Hwindow) * 0.9, Hwindow / 10, "REINITIALISER")
expressionZjulia.s = "z = " + StrF(a, 5) + " + " + StrF(b, 5) + "i"
TextGadget(#CANV_JULIA_TEXT_Z, Hwindow, Hwindow / 10 * 2.2,(Lwindow - Hwindow) * 0.9, Hwindow / 20, expressionZjulia, #PB_Text_Border | #PB_Text_Center)
expressionZjuliaZoom.s = "z0 EN ATTENTE ..."
TextGadget(#CANV_JULIA_TEXT_Z_ZOOM, Hwindow, Hwindow / 10 * 2.2 + Hwindow / 20,(Lwindow - Hwindow) * 0.9, Hwindow / 20, expressionZjuliaZoom, #PB_Text_Border | #PB_Text_Center)
CloseGadgetList()
;}
; Affichage des images
StartDrawing(CanvasOutput(#CANV_EXPLO_MANDEL))
DrawImage(ImageID(#IMG_MANDEL), 0, 0, Lwindow * 0.5, Lwindow * 0.5)
StopDrawing()
StartDrawing(CanvasOutput(#CANV_MANDEL))
DrawImage(ImageID(#IMG_MANDEL), 0, 0)
StopDrawing()
StartDrawing(CanvasOutput(#CANV_JULIA))
DrawImage(ImageID(#IMG_JULIA), 0, 0)
StopDrawing()
;- BOUCLE PRINCIPALE
Repeat
Event = WaitWindowEvent() ; Attend qu'un nouvel évènement se produise
; la valeur de retour Event nous renseigne sur l'évènement produit
If Event = #PB_Event_Gadget
;- gestion : explorateur
;{
If EventGadget() = #CANV_EXPLO_MANDEL
iterMaxMandel = 80
zoomMandel = 1
minXMandel = -2
maxXMandel = 0.6
minYMandel = -1.3
maxYMandel = 1.3
iterMaxJulia = 80
zoomJulia = 1
minXJulia.f = -2
maxXJulia = 2
minYJulia = -2
maxYJulia = 2
SetGadgetText(#CANV_JULIA_TEXT_Z_ZOOM, "EN ATTENTE...")
SetGadgetAttribute(#CANV_EXPLO_MANDEL, #PB_Canvas_Cursor, #PB_Cursor_Hand)
If EventType() = #PB_EventType_LeftClick
xCurseur = GetGadgetAttribute(#CANV_EXPLO_MANDEL, #PB_Canvas_MouseX)
yCurseur = GetGadgetAttribute(#CANV_EXPLO_MANDEL, #PB_Canvas_MouseY)
; dessinerMandelbrot(#IMG_MANDEL, Hwindow, Hwindow, -2, 0.6, -1.2, 1.2)
; mise à l'échelle et changement de sens de l'axe y
CxNew.f = 2 * (maxXMandel - minXMandel) * (xCurseur - (Lwindow * 0.5) / 2) / Lwindow + (maxXMandel - (maxXMandel - minXMandel) / 2)
CyNew.f = 2 * (maxYMandel - minYMandel) * ((Lwindow * 0.5) / 2 - yCurseur) / Lwindow + (maxYMandel - (maxYMandel - minYMandel) / 2)
If StartDrawing(CanvasOutput(#CANV_EXPLO_MANDEL))
Circle(xCurseur, yCurseur, 1, RGB(255, 92, 92))
StopDrawing()
EndIf ; StartDrawing(CanvasOutput(#CANV_EXPLO_MANDEL))
a = CxNew
b = CyNew
dessinerJulia(#IMG_JULIA, CxNew, CyNew, Hwindow, Hwindow, minXJulia, maxXJulia, minYJulia, maxYJulia)
CopyImage(#IMG_JULIA, #IMG_EXPLO_JULIA)
ResizeImage(#IMG_EXPLO_JULIA, Lwindow * 0.50, Lwindow * 0.50)
SetGadgetState(#IMG_EXPLO_JULIA, ImageID(#IMG_EXPLO_JULIA))
SetGadgetText(#CANV_JULIA_TEXT_Z, "z = " + StrF(a, 5) + " + " + StrF(b, 5) + "i")
SetGadgetText(#VALEUR_CONSTANTE_JULIA, "Valeur de la constante : z = " + StrF(a, 5) + " + " + StrF(b, 5) + "i")
If StartDrawing(CanvasOutput(#CANV_JULIA))
DrawImage(ImageID(#IMG_JULIA), 0, 0)
StopDrawing()
EndIf ; StartDrawing(CanvasOutput(#CANV_JULIA))
EndIf
EndIf ; EventGadget() = #CANV_EXPLO_MANDEL
;}
;- gestion : onglet Mandelbrot
;{
If EventGadget() = #CANV_MANDEL
SetGadgetAttribute(#CANV_MANDEL, #PB_Canvas_Cursor, #PB_Cursor_Cross)
If EventType() = #PB_EventType_LeftClick
zoomMandel = zoomMandel * 0.5
iterMaxMandel = iterMaxMandel * 1.2
xCurseur = GetGadgetAttribute(#CANV_MANDEL, #PB_Canvas_MouseX)
yCurseur = GetGadgetAttribute(#CANV_MANDEL, #PB_Canvas_MouseY)
CxNew = (maxXMandel - minXMandel) * (xCurseur - (Hwindow) / 2) / Hwindow + (maxXMandel - (maxXMandel - minXMandel) / 2)
CyNew = (maxYMandel - minYMandel) * ((Hwindow) / 2 - yCurseur) / Hwindow + (maxYMandel - (maxYMandel - minYMandel) / 2)
minXMandel = CxNew - zoomMandel
maxXMandel = CxNew + zoomMandel
minYMandel = CyNew - zoomMandel
maxYMandel = CyNew + zoomMandel
dessinerMandelbrot(#IMG_MANDEL, Hwindow, Hwindow, minXMandel, maxXMandel, minYMandel, maxYMandel)
SetGadgetText(#CANV_MANDEL_TEXT_Z, "z0 = " + StrF(CxNew, 5) + " + " + StrF(CyNew, 5) + "i")
StartDrawing(CanvasOutput(#CANV_MANDEL))
DrawImage(ImageID(#IMG_MANDEL), 0, 0)
StopDrawing()
EndIf ; EventType() = #PB_EventType_LeftClick
EndIf ; EventGadget() = #CANV_MANDEL
If EventGadget() = #CANV_MANDEL_BTN_RAZ
iterMaxMandel.l = 80
zoomMandel.f = 1
minXMandel.f = -2
maxXMandel.f = 0.6
minYMandel.f = -1.3
maxYMandel.f = 1.3
dessinerMandelbrot(#IMG_MANDEL, Hwindow, Hwindow, minXMandel, maxXMandel, minYMandel, maxYMandel)
StartDrawing(CanvasOutput(#CANV_MANDEL))
DrawImage(ImageID(#IMG_MANDEL), 0, 0)
StopDrawing()
SetGadgetText(#CANV_MANDEL_TEXT_Z, "z0 =EN ATTENTE...")
EndIf ; EventGadget() = #CANV_MANDEL_BTN_RAZ
If EventGadget() = #CANV_MANDEL_BTN_SAUVER
IDmandel = IDmandel + 1
SaveImage(#IMG_MANDEL, "mandel" + Str(IDmandel) + ".png")
EndIf ; #CANV_MANDEL_BTN_SAUVER
;}
;- gestion : onglet Julia
;{
If EventGadget() = #CANV_JULIA
SetGadgetAttribute(#CANV_JULIA, #PB_Canvas_Cursor, #PB_Cursor_Cross)
If EventType() = #PB_EventType_LeftClick
zoomJulia = zoomJulia * 0.5
iterMaxJulia = iterMaxJulia * 1.2
xCurseur = GetGadgetAttribute(#CANV_JULIA, #PB_Canvas_MouseX)
yCurseur = GetGadgetAttribute(#CANV_JULIA, #PB_Canvas_MouseY)
CxNew = (maxXJulia - minXJulia) * (xCurseur - (Hwindow) / 2) / Hwindow + (maxXJulia - (maxXJulia - minXJulia) / 2)
CyNew = (maxYJulia - minYJulia) * ((Hwindow) / 2 - yCurseur) / Hwindow + (maxYJulia - (maxYJulia - minYJulia) / 2)
minXJulia = CxNew - zoomJulia
maxXJulia = CxNew + zoomJulia
minYJulia = CyNew - zoomJulia
maxYJulia = CyNew + zoomJulia
dessinerJulia(#IMG_JULIA, a, b, Hwindow, Hwindow, minXJulia, maxXJulia, minYJulia, maxYJulia)
SetGadgetText(#CANV_JULIA_TEXT_Z_ZOOM, "z0 = " + StrF(CxNew, 5) + " + " + StrF(CyNew, 5) + "i")
StartDrawing(CanvasOutput(#CANV_JULIA))
DrawImage(ImageID(#IMG_JULIA), 0, 0)
StopDrawing()
EndIf ; EventType() = #PB_EventType_LeftClick
EndIf ; EventGadget() = #CANV_JULIA
If EventGadget() = #CANV_JULIA_BTN_RAZ
iterMaxJulia.l = 80
zoomJulia.f = 1
minXJulia.f = -2
maxXJulia.f = 2
minYJulia.f = -2
maxYJulia.f = 2
dessinerJulia(#IMG_JULIA, a, b, Hwindow, Hwindow, minXJulia, maxXJulia, minYJulia, maxYJulia)
SetGadgetText(#CANV_JULIA_TEXT_Z_ZOOM, "z0 EN ATTENTE...")
StartDrawing(CanvasOutput(#CANV_JULIA))
DrawImage(ImageID(#IMG_JULIA), 0, 0)
StopDrawing()
EndIf ; EventGadget() = #CANV_JULIA_BTN_RAZ
If EventGadget() = #CANV_JULIA_BTN_SAUVER
IDjulia = IDjulia + 1
SaveImage(#IMG_JULIA, "julia" + Str(IDjulia) + ".png")
EndIf ; #CANV_JULIA_BTN_SAUVER
;}
EndIf ; Event = #PB_Event_Gadget
Until Event = #PB_Event_CloseWindow
EndIf ; OpenWindow(0, 0, 0, Lwindow, Hwindow, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)