Share your repls and programming experiences

← Back to all posts
Mandelbrot
LizFoster (592)

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. ^ ^"

Commentshotnewtop
MatthewDoan1 (336)

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.

LizFoster (592)

@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.. Σ( > _ < ; )

MatthewDoan1 (336)

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

LizFoster (592)

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

MatthewDoan1 (336)

@LizFoster Is English not your native language?

LizFoster (592)

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

MatthewDoan1 (336)

@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.

LizFoster (592)

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

JordanDixon1 (308)

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

LizFoster (592)

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

Hashcode (184)

This is great! (worth the wait)

LizFoster (592)

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

AmazingMech2418 (661)

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.

LizFoster (592)

@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?

AmazingMech2418 (661)

@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.

LizFoster (592)

@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..

AmazingMech2418 (661)

@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.

AmazingMech2418 (661)

@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.

LizFoster (592)

@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.

AmazingMech2418 (661)

@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.

LizFoster (592)

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

Thank you! ^__ ^*

AmazingMech2418 (661)

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

bgrubert (140)

You can make a Julia set generator now!

LizFoster (592)

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

AgastyaSandhuja (146)

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

LizFoster (592)

@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)

AgastyaSandhuja (146)

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

LizFoster (592)

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

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

AgastyaSandhuja (146)

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

LizFoster (592)

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

DJWang (1130)

Wow! You are very talented!

LizFoster (592)

@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!

DJWang (1130)

@LizFoster Say, would you like to collab?

LizFoster (592)

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

DJWang (1130)

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

LizFoster (592)

@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?

LizFoster (592)

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

LizFoster (592)

@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..

bgrubert (140)

Nice job! Coloring is way better than mine!

LizFoster (592)

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

AdriaDonohue (53)

@LizFoster wanna chat on warriors game?

LizFoster (592)

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