# How Fractals are Generated, Part One

This section will show you the process, but not the difficult math, behind generating fractals. When you see a fractal image, you should think of the screen as a plane (a flat surface) made up of many, many points, or pixels. Each pixel has an x-coordinate and a y-coordinate, which determine its position on the screen. Since each pixel is in a different place, each pixel's coordinates are different from the rest.

To generate the fractal, first we need a function. A function is a bunch of math that can be performed on any pair of coordinates, and it will give you two new coordinates. So to start, a pixel is selected. Then, a function is iterated on the point. This brings us to a new x-coordinate and a new y-coordinate. So we "move" that point to the new location specified by these coordinates. To iterate a function means to keep applying it over and over, so that's what we do. We take the new coordinates, and use our function again. This brings us to a new set of coordinates for that point. And then we use the function on those coordinates, and so on.

As we do this, one of two things happens. The point may move around when we iterate the function, but never leave the screen. Or, it may stay on the screen for a while, and then leave, never to be seen again. Which of these occurs determines the different colors that you see in fractal pictures. If the point never leaves the screen, then we go back to the first coordinates for that point, and make the pixel there a certain color. The points that never leave the screen are all colored the same color. If eventually the point does leave the screen, however, than we count how many times we had to iterate our function to make it leave, and use that number to color the pixel at the original coordinates. For example, if it takes one iteration to make the point leave the screen, then maybe we color it blue. If it takes two, then maybe it's red. And so on. When you see smoothly shaded fractals, it simply means that one iteration makes a light blue, two makes a little darker blue, and so on.

The following chart shows the movement of the point labeled 0 under the function that produces the Mandelbrot set. Each of the numbered points shows the new location after another iteration. So after one iteration of the function it has moved to position 1. After two, it has moved to position 2, and so on. As you can see, this point leaves the screen after 5 iterations, so it will be colored with color #5.

In the case of the Mandelbrot set, the pixels inside the strangely shaped boundary are the ones that never leave the screen. The next image shows the iteration of a point inside this boundary, and as you can see, it keeps looping back to itself. This point never leaves the screen no matter how much you iterate it. So we color it with whichever color we are using for such points.

Now we repeat this process with every pixel in the image. There may be 800,000 or more pixels in one picture, so that's why making fractals can take a long time!

So here's an example. We start with a pixel whose x-coordinate is 4 and whose y-coordinate is 5. We will write this as (4,5). Say that when we use this function, the new coordinates are (3,9). That point is still on our screen, so we continue. When we iterate the function again, our coordinates are now (4,5). That's where we started! So now we know that if we iterate this again, it will go back to (3,9), then back to (4,5), and so on. This point will never leave the screen because of this. So we go to the original coordinates, (4,5), and color it, say, black. From now on any point that doesn't leave the screen will be black.

Now say we pick the next pixel, with coordinates (5,5). When we iterate this, maybe we get (5, 13). When we do it again, we get (324, 573457), which is not on our screen! So it took two iterations to make this point leave the screen. So we go back to (5,5), and color that point with color #2.

We continue with the next pixel, and we do this until we have done every pixel on the screen! Then, step back, and look at what we have. A fractal! Which one? Well, that's determined by the function. If we use one function, we may get the Mandelbrot set, and if we use another, we may get a Julia set. There are an infinite number of functions, and therefore there are an infinite number of fractals!
You can keep reading about how fractals are generated in Part Two