Mandelbrot set dilemma

Everything else that doesn't fall into one of the other PB categories.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Mandelbrot set dilemma

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4283
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Mandelbrot set dilemma

Post 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).
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Mandelbrot set dilemma

Post 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.
oh... and have a nice day.
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Mandelbrot set dilemma

Post 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.
Last edited by gnasen on Thu Jun 30, 2011 12:34 pm, edited 2 times in total.
pb 5.11
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Mandelbrot set dilemma

Post by Kaeru Gaman »

I would strongly recommend using Double!
fractal calculations need really high precision.
oh... and have a nice day.
User avatar
STARGÅTE
Addict
Addict
Posts: 2315
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Mandelbrot set dilemma

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: Mandelbrot set dilemma

Post by michaeled314 »

thanks guys

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

:D

Persistency is the key
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Mandelbrot set dilemma

Post by luis »

@gnasen

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

Bye!


Ahhhhhhhhhhhh.... Mandelbrot ... nice times...
"Have you tried turning it off and on again ?"
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Mandelbrot set dilemma

Post 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"
Last edited by gnasen on Thu Jun 30, 2011 1:29 pm, edited 1 time in total.
pb 5.11
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Mandelbrot set dilemma

Post 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 :)
"Have you tried turning it off and on again ?"
Post Reply