2/21/2023 0 Comments Nodebox mandelbrot![]() ![]() A pixel (rectangle of 1 width and height) is plotted in the position i, j. ![]() A color is assigned to canvas pixel, if the complex number passed to mandelbrot function belongs to set, the black color is chosen, otherwise the color depends of the number of iteration made by mandelbrot function.The "complex" variable store a complex number x and y, are calculated getting a relative value, of the width and height of the canvas, plus the values that belong to the mandelbrot set.The entire width and height of the canvas are iterated.colors, store a list of 16 random hexadecimal colors.IMAGINARY_SET represent, the imaginary numbers in y axis, the domain in y axis goes from -1 to 1.REAL_SET constant represent the real numbers of Mandlebrot set, as you saw the Figure 1 of this entry, the domain in x axis goes from -2 to 1.In the first lines, the canvas element is found and its context, then the window width and height is assigned to the canvas.Finally, the function returns a tuple, with the iteration number that it took to reach a modulus greater than 2, and whether the complex number passed to it, belongs to Mandelbrot set.Īnd that's it!, we have implemented a mandelbrot equation.The whole process is repeated while the modulus of z belongs to Mandelbrot set and the iteration number is less than 80.Add one when each iteration is completed (n += 1).d is the modulus of the new complex number (z), computed before.z is recalculated and now it contains the addition of the received complex number (c) and the previous z.The p variable contains the computing of the square of z, which is also a complex number, please refer to this, to understand how basic operations such as addition, subtraction and multiplication works in complex numbers.The mandelbrot function receives a complex number, it has real and imaginary part, here we are representing those components as x and y.The number of iterations to reach a modulus greater than 2 can be used to determine the color to use when we are plotting.Ī complex plane can be represented in a normal 2D plane, where the X axis, will represent the real number, meanwhile the Y axis will represent the imaginary number, for instance, x = 3 y= 5i.įor a better understanding please refer to this video.įinally, after understand a bit of the Mandelbrot equation, it's time to implement it:Įnter fullscreen mode Exit fullscreen mode When the modulus of Zn is greater than 2, means that the number does not belong to Mandelbrot set, otherwise it is part of the set. Of a part of the complex plane, if Zn is bounded. To represent visually this set we need to find, for each point c In this entry you will learn how to plot in JS, the previous image.īut before, let's see a little more theory about how this set works.Īs we mention before, the mandelbrot set is defined in the set of complex numbers c for which the function,ĭoes not diverge when iterated from z = 0.īelow, the previous equation is broken down:Īs you can see, the Mandelbrot set is obtained from the quadratic recursive equation where, z and c represents a complex number. In the next picture you can see what I mean.įigure 1: Mandelbrot set - black and white In a nutshell, a mandelbrot set is one of the most beautiful and famous fractal, that is defined by the set of complex numbers. In general, a Mandelbrot set marks the set of points in the complex plane such that the corresponding Julia set is connected and not computable. Note: If you are not familiar with the mathematical terms used here, I recommend you to read about complex numbers and fractals.įirst of all, What a heck is a Mandelbrot Set?, according to mathworld:Ī Mandelbrot Set, is used to refer both to a general class of fractal sets and to a particular instance of such a set. In this entry I want to share with you, a little of my knowledge to show you how to plot a Mandelbrot Set without any library just JS, so go ahead!. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |