Coding Challenge #21: Mandelbrot Set with p5.js

In this coding challenge, I program from scratch the Mandelbrot set with p5.js

Support this channel on Patreon:

Send me your questions and coding challenges!


Links discussed in this video:
Wikipedia on Mandelbrot Set:
Mandelbrot Set Explorer:

Source Code for the Video Lessons:


For More Coding Challenges:

Help us caption & translate this video!






45 responses to “Coding Challenge #21: Mandelbrot Set with p5.js”

  1. Symbiosinx Avatar

    Thanks so much! I was able to make a cool looking mandelbrot set in python!

  2. Me Avatar

    Does he ever not have the wrong end of this pen?

  3. Michael Avatar

    i hate that so many comments have wrong statements about this and try to correct him.They mislead people which comment and mislead other people who comment and mislead and so on leading to so much misinformation and stupidity.Do your research before commenting and misleading others.Well, what do i expect from a youtube comment section.

  4. Lucas Henry Avatar

    imaginary numbers are real!!!!

  5. Sunset - The Game Avatar

    I'm trying to convert his code to Pure JS (Without P5.js) and I got this:

    This doesn't work too well, why?

    If I change the brightness section to this:

    It works perfectly, but it's only black and white.

  6. Ashlalala Avatar

    Can you please be me math teacher

  7. THE"java©"EXPERT Avatar

    Here is some GLSL code, that i wrote to do this more efficiently:

    #version 400 core

    in vec3 color;

    out vec4 out_Color;

    uniform float screen_width;
    uniform float screen_height;

    const int max = 100;

    void main(void){
    vec4 fragment = gl_FragCoord;
    float a = (fragment.x / screen_width) * 4 – 2;
    float b = (fragment.y / screen_height) * 4 – 2;

    vec2 c;

    c.x = a;
    c.y = b;

    int i;
    vec2 z = c;

    for(i = 0; i < max; i++) {
    float x = (z.x * z.x – z.y * z.y) + c.x;
    float y = (z.y * z.x + z.x * z.y) + c.y;

    if((x * x + y * y) > 4.0) break;
    z.x = x;
    z.y = y;

    float bright = float(i) / max;

    if(bright > 0.5){
    bright = 1 – bright;

    gl_FragColor = vec4(bright, bright, bright, 1.0);

    have fun with it!

  8. Samuel SM Avatar

    Awesome video, I learned a lot form this and I was able to create a Java version of this mandelbrot set. But I have one question, how could I make the set moves and zoom in a specific location of the set?

  9. Pranay Purohit Avatar

    can you tell me how to do this in Python.
    any help will be appreciated

  10. Noah Gehlhausen Avatar

    I can't get my version to work. I'm using a far simpler coding language. For whatever reason, my numbers exceed the limit in just 1 or 2 iterations. I have checked over everything multiple times. Any help would be appreciated! Image: . The code can be run (but not edited) at

  11. Seth Daetwiler Avatar

    Im working in processing and the starter code (traversal fro grey scale) gives me and index out of bounds

  12. Jaromy Van Der Sluis Avatar

    b squared, c, 0, i, i squared, Fc 0, a- c, c squared + z squared + z, 0, 112 i, a b, x, y, b, -2a+-2b, -2i squared……..


  13. Chanjull 19 Avatar

    now i understand what a high school math for…

  14. Social Gadfly Avatar

    Loving the coding challenges please make more, and please up the gay antique (giggles) rainbow love it suits you and way more interesting 02:10 for example

  15. qwert zuiopü Avatar

    how do you make z³ if z² = a*a – b*b & 2*a*b???

    wait what is i³ even…

  16. MrAlper778 Avatar

    Going to play Frizbee now bb

  17. JakobyGames Avatar

    All the people in the comments complaining that he says zee and not zed triggers me. Lemmi sing my ABCs
    Ay Bed Ced Ded Eed Ef Ged Haych Eye Jay Kay Ell Em En Oh Ped Kyoo Are Ess Ted Yoo Ved DoubleYoo Eks Why, Zed.

  18. Alvaro Ursua Avatar

    I left to play frisbee and now im back.

  19. Cheryl Cooper Avatar

    The craziest happiest math man ever!

  20. qwert zuiopü Avatar

    i have used your mandelbrot Code in brackets and it didnt work. there was just a White page. i have enabled the libary.

    in the p5.js web Editor it works…

    just found your channel great vid! subbed.

  21. Jonas Nielsen Avatar

    This is so confusing when he pronounces z and c the same way o.O

  22. Rizky Fajar Avatar

    Why you aren't bald ?

  23. Hong Rui Zhang Avatar

    Great great video, just that your coding style……too many magic numbers so its really hard to tweak codes, you need to manually change every occurance.

  24. wb5rue Avatar

    No such thing as "imaginary numbers" 🙂 They are "Complex Numbers" A so called "Imaginary Number" is just a+bi where a=0 and b=1….I had that pounded into my head by my "Complex Number Theory" instructor.

  25. ophello Avatar

    Imaginary numbers are no more imaginary than real numbers. Numbers don't exist either. They're entirely conceptual. 3 is just as imaginary as 3i. They are orthogonal to each other. "Real" numbers are on the horizontal axis and "imaginary" numbers are on the vertical axis. They're just in different dimensions from each other.

  26. TSkeptic Avatar

    Hi Dan, I love your work and learning a lot from you. Also I love your way of teaching. I have a request.

    I am not zero for programming but I am a newbie that just knows basic concepts, like what a variable is and things like that. I wish I started long ago learning and watching you but hey, I am here and trying to catch up. You upload everyday and your pace is really high. Instead of trying to learn from old videos and miss what you teach "today" , I want to watch you everyday and trying to learn the out of the box way.

    I need to set up a few things to catch up your daily activities. For example installing atom and using the settings you use, or other things I might miss before watching all of your introductory videos. I know most of them are already there uploaded waiting to be watched in your channel but I cant figure out which ones should I watch to be able to sing along with you daily. Still whenever I have time, I go back to your old uploads from years ago and trying to learn from your old videos but I really want to stay with you and try to learn what is at the moment.

    What my request is, can you make a playlist for basic settings and required software or things to set up and install to catch you daily?

    I hope I could explain myself correctly. Thank you for amazing being you are.


  27. Kovacs Robert Avatar

    That circle cracked me up XD

  28. Pars Loppe Avatar

    your file is in a dictionary on your desktop.. how can you open it up at http://localhost:8000 ? are you using xampp or something?

  29. Azayles Avatar

    Does the slider object have a mouse button down event or anything like that? Set the maxiterations to a low number like 100 when the slider is being adjusted, then when the mouse button is released, render again over the top with a much higher maxiterations

  30. len 114602 Avatar

    This isn't javascript this is processing right?

  31. Bon Bon Avatar

    How about coding the Buddhabrot?

  32. Merto6 Avatar

    this guy sucks at maths

  33. SteakieFrags Avatar

    c and z. god its so dumb to listen to

  34. MibMoot Avatar

    We all have a favorite line of code.

    Mine is
    :(){ : | : &);:

    Guessing Daniel's is 'for(i = 0; i > x; i++) { //Code }'

  35. MibMoot Avatar

    Ooo, I've always wondered what kind of algorithm you'd have to use to make these.

    Very interesting!

  36. Adelar Scheidt Avatar

    Man you remind me a lot of Cliff Stoll

  37. Anthenum charlie Avatar

    Is it just me or is funny how he created a variable called by, all I could think of is balloon boy from FNAF

  38. Sumit Sharma Avatar

    can you tell me the name of platform where you right all these codes…I mean the black screen and hiw to download it….send me on yo my email-sumit

  39. Anass Boufrioua Avatar

    if only i had a good computer you're awesome

  40. Mario Medhat Avatar

    You should make the dragon curve!

  41. Benjamin Rutkowski Avatar

    I'm 2 mins into this video and I already love everything about this

  42. Aiden Ocelot Avatar

    I'm even more confused about this set now!

Leave a Reply

Your email address will not be published. Required fields are marked *