Mandelbrot set dilemma
-
michaeled314
- Enthusiast

- Posts: 340
- Joined: Tue Apr 24, 2007 11:14 pm
Mandelbrot set dilemma
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
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
A complex number: a + bimichaeled314 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
Real axis measures: a
Imaginary axis measures: bi
A complex number can be represented by the point (a,bi).
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Mandelbrot set dilemma
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.
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.
Re: Mandelbrot set dilemma
I would start like this:
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.
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
Last edited by gnasen on Thu Jun 30, 2011 12:34 pm, edited 2 times in total.
pb 5.11
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Mandelbrot set dilemma
I would strongly recommend using Double!
fractal calculations need really high precision.
fractal calculations need really high precision.
oh... and have a nice day.
Re: Mandelbrot set dilemma
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_CloseWindowPB 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 more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
-
michaeled314
- Enthusiast

- Posts: 340
- Joined: Tue Apr 24, 2007 11:14 pm
Re: Mandelbrot set dilemma
thanks guys
See me in a year when I release something bigger and greater than FRACTINT

Persistency is the key
See me in a year when I release something bigger and greater than FRACTINT
Persistency is the key
Re: Mandelbrot set dilemma
@gnasen
Hi, does that code work for you ? It's missing a InitKeyboard().
Bye!
Ahhhhhhhhhhhh.... Mandelbrot ... nice times...
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 ?"
Re: Mandelbrot set dilemma
Nanu, wo hast du denn diesen Thread ausgegraben? Ich erinner mich gar nicht mehr daran, diesen Post geschrieben zu habenluis wrote:@gnasen
Hi, does that code work for you ? It's missing a InitKeyboard().
Bye!
Ahhhhhhhhhhhh.... Mandelbrot ... nice times...
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
Re: Mandelbrot set dilemma
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
Sorry
"Have you tried turning it off and on again ?"