Skip to content
Sign upLog in
← Back to Community

The Mandelbrot Set as seen on the Complex Plane

Profile icon
LizFoster

I nearly forgot to post before bed T_T

I made this for a school project, but now that it is graded and fully optimized, I want to post it here ^..^

This uses a quite inefficient method for rendering the Mandelbrot set, in Python Turtle. It almost works like a printer. It took me eight days from when I started to complete the very first version, and then took me until yesterday to fully optimize it (It used to take an hour and a half to finish running T^T). It took my teacher's old iPad 4 minutes to render it in its current state!

Please enjoy .^ ^.

EDIT: Wow, this is on the hot tab. Everyone, thanks. ^ ^"

Voters
Profile icon
user2445880
Profile icon
LukeClarke2
Profile icon
AmazingMech2418
Profile icon
DJWang
Profile icon
SotoAyam
Profile icon
math_genius
Profile icon
Axrevyn
Profile icon
AgastyaSandhuja
Profile icon
bgrubert
Profile icon
MatthewDoan1
Comments
hotnewtop
Profile icon
MatthewDoan1

This is a cool program, could you explain how it works? I'm familiar with the equation f(z) = z^2 + c or something like that, but I'm not sure I quite understand what's happening in this program.

Profile icon
LizFoster

@MatthewDoan1
Sure thing!

Since you already know the equation, I assume you know about complex numbers and the complex plane.

The program sets the turtle to the top left of what is, in terms of the complex plane, a 2 by 4 section around (0, 0i). Then, it moves the turtle horizontally to the other side of the plane, and does that over and over again, moving it down a row every time.

For every point, it iterates the equation until it finds that the iteration number's corresponding index in the MAG list is less than the absolute value of z. Once it finds that, it breaks out of the loop. This saves a massive amount of time, as before it was finding the optimal color, but still kept checking for a better one. Also, since the majority of the points it will check will be identified quickly (since they escape to infinity much faster), this cuts even more time off of the total render time.

If you have any further questions, please do let me know; I'd be delighted to help out.

Please pardon any bad grammar.. Σ( > _ < ; )

Profile icon
MatthewDoan1

@LizFoster
Thanks for the explanation, it was crystal clear!

Profile icon
LizFoster

@MatthewDoan1
Oh, nice! I am glad I was able to explain it well. (= ^ ^ = )

Profile icon
MatthewDoan1

@LizFoster
Is English not your native language?

Profile icon
LizFoster

@MatthewDoan1
Well, not really. Is it that obvious? >_<

Profile icon
MatthewDoan1

@LizFoster
No, it wasn't obvious at all. But you mentioned that "Oh, it is good that it was understandable!" so I asked whether English was your native language.

Profile icon
LizFoster

@MatthewDoan1
Oh okay. Well at least that means my grammar is probably decent, ha ha

Profile icon
JordanDixon1

Not bad. It's very satisfying to be honest. XD

Profile icon
LizFoster

@JordanDixon1
Nyahaha, thanks ^ ^" Yeah, I love watching it appear in front of my eyes. It's such an amazing structure.

Profile icon
Hashcode

This is great! (worth the wait)

Profile icon
LizFoster

@Hashcode
Thanks! Glad you liked it ^ ^ This was fun to code (At least in the beginning _ _)

Profile icon
AmazingMech2418

I can tell that you are rendering on the complex plane and that you are using z=z^2+c and iterating n times until z is greater than index n of the MAG list and using setting the color to color n from the COLOR list, but do you by any chance know how the fractal itself works? I'm guessing it has something to do with the exponentiation of complex numbers, but I'm not completely sure. Also, I had no idea that Python could handle complex numbers! I know JavaScript can't without an external library (if you try to find the square root of -1, it returns "NaN"). By the way, this would also be great for the "learn" section if you know how the fractal itself works.

Profile icon
LizFoster

@AmazingMech2418
I do, in fact, know how it works!

Think of it this way: Each and every point on the complex plane has an individual, unique Julia Set, right? Well, those Julia Sets are like a bunch of mirrors: Reflections, of reflections, of reflections, etcetera etcetera.

(Sorry, I am not good with words _ _ This is difficult to explain)

Although before I go on, I must ask, what do you mean by "works?" Do you mean, why does it have such complicated patterns despite only changing the initial value by such minuscule amounts? Or, do you mean, why does it form any pattern at all?

Profile icon
AmazingMech2418

@LizFoster
The complicated patterns. Of course, any such equation would form a pattern of some type, but I'm wondering about how the specific pattern of the Mandelbrot Set is formed.

Profile icon
LizFoster

@AmazingMech2418
Ah, I see.

Unfortunately, that is pretty much one of the only things I do not fully understand about the Mandelbrot Set. Although, now that you've mentioned it, I am pretty sure it has something to do with Complex Exponentation (or something equivalent).

Really sorry, but I do not know the exact answer to this..

Profile icon
AmazingMech2418

@LizFoster
It's fine. I have an equation that I derived for complex exponentiation that I could possibly send you so that you can maybe figure out from that. I just have to find it first... I just don't really know how an equation can create a fractal anyways and was wondering about this specific equation for the Mandelbrot Set.

Profile icon
AmazingMech2418

@LizFoster
Well, I just realized that I never actually found a formula for every exponent, but i^(a+bi)=(cos(a*pi/2)+i*sin(a*pi/2))(cos(b*i*pi/2)+i*sin(b*i*pi/2)). Also, x^(a+bi)=x^a(cos(b*ln(x))+i*sin(b*ln(x))). I also have a formula for any logarithm if that may help, but it is VERY long.

Profile icon
LizFoster

@AmazingMech2418
Ooh, those look fun! I'd like to check out what these look like specifically on a graph for myself!

If you don't mind, I'd love to see the formula for any log! Only if it is not too much of a burden, though.

Profile icon
AmazingMech2418

@LizFoster
log_(a+bi)(c+di)=((log(c^2+d^2))/2+(i*arccos(c/(10^(log(c^2+d^2)/2)))/ln(10)))/((log(a^2+b^2))/2+(i*arccos(a/(10^(log(a^2+b^2)/2)))/ln(10))) I said it was long... By the way, log_(a+bi)(c+di) means the log, base a+bi of c+di.

Profile icon
LizFoster

@AmazingMech2418
Ahhh, cool cool. That looks exciting! (Lol)

Thank you! ^__ ^*

Profile icon
AmazingMech2418

@LizFoster
You're welcome! Hopefully, it can help us figure out how the Mandelbrot Set works as well.

Profile icon
LizFoster

@AmazingMech2418
Yes, let's hope!

Profile icon
bgrubert

You can make a Julia set generator now!

Profile icon
LizFoster

@bgrubert
Yes, I was actually thinking about that last night!

Profile icon
AgastyaSandhuja

wow, this is very amazing and satisfying! To be honest, I could watch this all day on repeat.

Profile icon
LizFoster

@AgastyaSandhuja
Thank you! Yes, I agree, it's very fun to watch it run. It's even more fun to watch as the one that made it in the first place (I am surprised turtle is able to do it at all wwwwww)

Profile icon
AgastyaSandhuja

@LizFoster
It would be really satisfying if I recorded this and put it into a time-lapse loop :p

Profile icon
LizFoster

@AgastyaSandhuja
Ooh, yes it would~! Do it ଲ(ⓛ ω ⓛ)ଲ

(If you can, do not feel pressured [> _ < "])

Profile icon
AgastyaSandhuja

@LizFoster
definitely doing it when I have time!
Homework right now but in an hour or so...
I'll comment it

Profile icon
LizFoster

@AgastyaSandhuja
Nice! Good luck on homework. ^ ^* Take your time on it!

Profile icon
DJWang

Wow! You are very talented!

Profile icon
LizFoster

@DJWang
Really?! Thank you so much! It means a lot to me to hear that. I am proud of how far I've come, and hope to go even further, ha ha ha!

Profile icon
DJWang

@LizFoster
Say, would you like to collab?

Profile icon
LizFoster

@DJWang
Sure, I would be delighted! What did you have in mind?

Profile icon
DJWang

@LizFoster
I've been coding some games in python, and wondering if your graphic skills could help.

Profile icon
LizFoster

@DJWang
Sounds like fun! I am working on something at the moment, but I'll let you know when I am free. Why don't you invite me to collaborate on one of those games?

Profile icon
DJWang

@LizFoster
Sure! Thanks

Profile icon
LizFoster

@DJWang
No problem! Thanks for the invitation! (=⌒‿‿⌒=)

Profile icon
LizFoster

@DJWang
Oh, although I'd like to point out, unless it is a fairly simple top-down game like snake, it could get fairly complicated, fairly quickly..

Profile icon
bgrubert

Nice job! Coloring is way better than mine!

Profile icon
LizFoster

@bgrubert
Aww, no way. Thanks! Yeah, this was the best color scheme for the set in my honest opinion (Lol)

Profile icon
AdriaDonohue

omg

Profile icon
LizFoster

@AdriaDonohue
What do you think? (Lol)

Profile icon
AdriaDonohue

@LizFoster
its amazing!

Profile icon
AdriaDonohue

@LizFoster
wanna chat on warriors game?

Profile icon
LizFoster

@AdriaDonohue
I am sorry, I'm actually headin to therapy shortly. ^ ^"

Profile icon
AdriaDonohue

@LizFoster
ok!seeya!