Page 1 of 1

Mandelbrot set dilemma

Posted: Sun Oct 25, 2009 3:18 am
by michaeled314
okay I am a high school student who likes math a ton... Number theory and mainly fractals...

I was wondering how you would go about making a real and imaginary axis to draw the mandelbrot set... I was wondering if it was possible

with a screen of course

Re: Mandelbrot set dilemma

Posted: Sun Oct 25, 2009 4:49 am
by Demivec
michaeled314 wrote:okay I am a high school student who likes math a ton... Number theory and mainly fractals...

I was wondering how you would go about making a real and imaginary axis to draw the mandelbrot set... I was wondering if it was possible

with a screen of course
A complex number: a + bi
Real axis measures: a
Imaginary axis measures: bi
A complex number can be represented by the point (a,bi).

Re: Mandelbrot set dilemma

Posted: Sun Oct 25, 2009 9:33 am
by Kaeru Gaman
the coordinates are (a,b), the i is just the scale.

but yes, the approach is correct.
in fact the Apfelmaennchen is a 2D visualisation of the area close to (0,0)
the colors describe the calculation depth of the formula.

Re: Mandelbrot set dilemma

Posted: Sun Oct 25, 2009 11:54 am
by gnasen
I would start like this:

Code: Select all

InitKeyboard()

Structure complex
  real.d ;<- .d instead of .f like suggested for more precision
  imag.d
EndStructure

Procedure complex_add(*zahl1.complex,*zahl2.complex,*result.complex)
  *result\real = *zahl1\real + *zahl2\real
  *result\imag = *zahl1\imag + *zahl2\imag
EndProcedure
Procedure complex_mul(*zahl1.complex,*zahl2.complex,*result.complex)
  *result\real = *zahl1\real * *zahl2\real - *zahl1\imag * *zahl2\imag
  *result\imag = *zahl1\real * *zahl2\imag + *zahl1\imag * *zahl2\real
EndProcedure

Define zahl1.complex
zahl1\real = 2
zahl1\imag = 5

Define zahl2.complex
zahl2\real = 1
zahl2\imag = 2

Define result1.complex 
complex_mul(zahl1,zahl2,result1)

Define result2.complex 
complex_add(zahl1,zahl2,result2)

InitSprite()

If OpenScreen(640, 480, 16, "Sprite")
  
  Repeat
    
    ExamineKeyboard()
    
    ClearScreen(RGB(0,0,0))
    
    StartDrawing(ScreenOutput())
      LineXY(640/2,0,640/2,480,RGB(0,255,0))
      LineXY(0,480/2,640,480/2,RGB(0,255,0))
      Box(640/2-1+zahl1\real*10,480/2-1-zahl1\imag*10,3,3,RGB(255,0,0))
      Box(640/2-1+zahl2\real*10,480/2-1-zahl2\imag*10,3,3,RGB(255,0,0))
      Box(640/2-1+result1\real*10,480/2-1-result1\imag*10,3,3,RGB(255,0,255))
      Box(640/2-1+result2\real*10,480/2-1-result2\imag*10,3,3,RGB(255,0,255))
    StopDrawing()
    
    FlipBuffers()
    
  Until KeyboardPushed(#PB_Key_Escape)
  
EndIf
The trick is to split each number in the real and imaginary part. Now you can just draw them by interpreting real part as x axis, imaginary part as y axis.

Re: Mandelbrot set dilemma

Posted: Sun Oct 25, 2009 12:02 pm
by Kaeru Gaman
I would strongly recommend using Double!
fractal calculations need really high precision.

Re: Mandelbrot set dilemma

Posted: Sun Oct 25, 2009 3:07 pm
by STARGÅTE
an the end is ^^:

Code: Select all

Structure FractalGradient
  x.l : y.l : Size.l : MaxIteration.l
EndStructure
Procedure.d Iteration(cx.d, cy.d)
  Shared FractalGradient.FractalGradient
  Protected Iter.l, x.d, y.d, xt.d, yt.d
  While x*x + y*y <= 6 And Iter < FractalGradient\MaxIteration
    xt = x*x - y*y + cx 
    yt = 2*x*y + cy 
    x = xt : y = yt : Iter + 1 
  Wend 
  ProcedureReturn Iter/FractalGradient\MaxIteration
EndProcedure
Procedure.f FractalGradientCallback(x, y)
  Shared FractalGradient.FractalGradient
  With FractalGradient
    ProcedureReturn Iteration((x-\x)/\Size, (y-\y)/\Size)
  EndWith
EndProcedure
Procedure FractalGradient(x, y, Size, MaxIteration)
  Shared FractalGradient.FractalGradient
  With FractalGradient
    \x = x : \y = y : \Size = Size : \MaxIteration = MaxIteration
  EndWith
  CustomGradient(@FractalGradientCallback())
EndProcedure

Enumeration
  #Image
  #Window
  #Gadget
EndEnumeration

CreateImage(#Image, 384, 256)
StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Gradient)
  FractalGradient(256, 128, 128,63)
    GradientColor(0.00, $0000FF)
    GradientColor(0.25, $00FFFF)
    GradientColor(0.50, $00FF00)
    GradientColor(0.75, $FFFF00)
    GradientColor(1.00, $FF0000)
  Box(0,0,384,256)
StopDrawing()

OpenWindow(#Window, 0, 0, ImageWidth(#Image), ImageHeight(#Image), "Fractal", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(#Gadget,0,0,ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))

Repeat : until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Mandelbrot set dilemma

Posted: Sun Oct 25, 2009 7:41 pm
by michaeled314
thanks guys

See me in a year when I release something bigger and greater than FRACTINT

:D

Persistency is the key

Re: Mandelbrot set dilemma

Posted: Thu Jun 30, 2011 11:36 am
by luis
@gnasen

Hi, does that code work for you ? It's missing a InitKeyboard().

Bye!


Ahhhhhhhhhhhh.... Mandelbrot ... nice times...

Re: Mandelbrot set dilemma

Posted: Thu Jun 30, 2011 12:33 pm
by gnasen
luis wrote:@gnasen

Hi, does that code work for you ? It's missing a InitKeyboard().

Bye!


Ahhhhhhhhhhhh.... Mandelbrot ... nice times...
Nanu, wo hast du denn diesen Thread ausgegraben? Ich erinner mich gar nicht mehr daran, diesen Post geschrieben zu haben :D
Aber du hast natürlich recht, das fehlt da, kA wieso ich das "damals" nicht im Code hatte (vergessen zu kopieren oder whatever).

Edit: Sorry, didnt notice that Im in the english forums, but its nothing important and as a summary for the not german ones "yes, youre totally right"

Re: Mandelbrot set dilemma

Posted: Thu Jun 30, 2011 1:12 pm
by luis
LOL, you are right ... I didn't notice the date of the thread, I thought was a recent one... don't know how I stumbled upon this.

Sorry :)