http://ker.endofinternet.net/img/ (fait avec une version java)
J'ai eu 50.000 bugs de typage de variable... maintenant "ca marche", mais c'est vraiment degueulasse et y'a encore des bugs qui traine.
(la variable "dodraw" par exemple, je passe que 0 ou 1, mais je retrouve 0 ou 28905 dans ma procedure iterate)
A noter que je suis en 64bits avec PureBasic 4.40 (x64)
Voila le code, que j'essaye de nettoyer :
Code : Tout sélectionner
Global screenSize = 800
Global bailout = 1000
Global plots = 1000
Global maxexposure = 0
Global time = 0
Global exposures = 0
Global drawing = 0 ; 0 = false ; 1 = true
Global Dim exposure(screenSize*screenSize)
For i = 0 To screenSize*screenSize
exposure(i) = 1
;Debug exposure(i)
Next i
Structure Pixel
Pixel.l
EndStructure
Procedure iterate(x0.d, y0.d, dodraw)
x.f = 0.0
y.f = 0.0
xnew.f = 0.0
ynew.f = 0.0
ix = 0
iy = 0
For i = 0 To bailout
xnew.f = x.f * x.f - y.f * y.f + x0
ynew.f = 2 * x.f * y.f + y0
If ((dodraw.i <> 0) And (i > 0))
ix = Int(screenSize * (xnew.f + 1.5) / 2.0)
iy = Int(screenSize * (ynew.f + 1) / 2.0)
If ((ix>= 0) And (iy >= 0) And (ix < screenSize) And (iy < screenSize))
exposure(ix*screenSize+iy) = exposure(ix*screenSize+iy) + 1
EndIf
EndIf
If ((xnew*xnew + ynew*ynew) > 4)
;Debug 1
ProcedureReturn 1
EndIf
x.f = xnew.f
y.f = ynew.f
Next i
;Debug 0
ProcedureReturn 0
EndProcedure
Procedure plotPlots(plots.i)
x0.d = 0
y0.d = 0
For k = 0 To plots
x0.d = Random(10000000)/10000000.0 *3.0 - 2.0
;Debug x0
y0.d = Random(10000000)/10000000.0 *3.0 - 1.5
;Debug y0
If(iterate(x0.d,y0.d,0) = 1)
iterate(x0.d,y0.d,1)
exposures = exposures + 1
EndIf
Next k
EndProcedure
Procedure findMaxExposure()
maxexposure = 0
For i = 0 To screenSize*screenSize
If (exposure(i) > maxexposure)
maxexposure = exposure(i)
EndIf
Next i
EndProcedure
; initialize the sprite engine
If InitSprite() = 0
MessageRequester("Error", "Can't open screen & sprite enviroment!", 0)
End
EndIf
; open window
If OpenWindow(0, 0, 0, screenSize, screenSize, "Buddhabrot", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0), 0, 0, screenSize, screenSize, 0, 0, 0, #PB_Screen_NoSynchronization)
;If StartDrawing(ScreenOutput())
;Buffer = DrawingBuffer() ; Get the start address of the screen buffer
;Pitch = DrawingBufferPitch() ; Get the length (in byte) took by one horizontal line
;PixelFormat = DrawingBufferPixelFormat() ; Get the pixel format.
; StopDrawing()
; EndIf
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
plotPlots(plots)
time = time +1
If ((time % 30) = 0)
findMaxExposure()
StartDrawing(ScreenOutput())
CreateImage(0,screenSize,screenSize)
For x = 0 To screenSize -1
For y = 0 To ScreenSize - 1
ramp.d = exposure(x*screenSize+y) / (maxexposure / 2.5)
If (ramp.d > 1)
ramp.d = 1
EndIf
;Debug ramp
Plot(x,y,RGB(ramp*255.0,ramp*255.0,ramp*255.0))
Next y
Next x
StopDrawing()
EndIf
FlipBuffers()
;ClearScreen(RGB(0, 0, 0))
ForEver

J'ai passé une partie de la nuit dessus, alors c'est pas joli-joli.
Le but derriere sera d'optimiser le code a mort, mais d'abord faut que ca soit clean

Merci !