Skip to end of metadata
Go to start of metadata

CS 351 - Assignment 2:Fractals

Titobiloluwa Awe and Elena Kirillova


In this project, we built some useful structures and functions in our image.c library. With these functions and structures, we were able to create Mandelbrot and Julia sets. These sets have very interesting characteristics that allow them to form certain shapes when they are drawn. We were also able to implement the Perlin noise function through a function that we created. Finally, we used existing files to compose two pictures and come up with interesting final results. 


Our first task was to to create a file image.c that held all of the functions that we would need to implement pictures for an Image structure. We had to create input and output functions to read in files and output files and accessor functions, to get the value of an Image's color or data. Then, we had to implement the Mandelbrot function and the Julia function which were the functions that created a whole plane of pixels given initial starting and ending (x,y) values. Then, we had to implement a fractal noise like the Perlin noise to create some sort of visual effect. Finally, we had to compose multiple pictures to get an interesting final picture.


Mandelbrot set

To implement the mandlebrot function, we looped through every single pixel, found the x and y components of the complex number z, used this to compute cx and cy and then used that value in a separate loop to find out what elements of the rectangle were inside the set and those that weren't. We colored those that were outside black, while we used a different coloring method to color the other pixels.

The image below shows the Mandelbrot set shaded in black:

Julia Set

To implement our Julia set, we followed similar steps, but left cx and cy unchanged while changing zx and zy.

The image below shows the Julia set for a large rectangle:

The image below shows the same Julia set for a smaller rectangle. We note that the shape of the set remains the same as we zoom in on the picture.


For our noise functions, we implemented a noise function that was based on a random number from 1 to 10 being chosen. Then, depending on the number that we chose, we colored the pixels accordingly.

The image below shows the noise generated from a random number generator. (Carpet)

Visualization of Math Expression

Here we came up with our own mathematical expression and mapped it onto the 2D plane. Some new variables were introduced for this task:

where i and j represented pixel's position on the plane. So the placement of the colors for this image depended on the value of x.

Below is the image. The gradient change in color was accomplished by putting the values of x through a log function, also the shape can be explained in the same way, since there is a log in the x equation.


For our composition, we used the mask and merge programs that we had already and created some interesting pictures.

This is the image generated when we composed the Carpet with the Julia Set:

Another composition was made by the blending program taking in the visualization of our own math expression and a Mandelbrot image:


We created even more interesting pictures.

This is the image generated when we add more else statements checking for divisibility of n by 2:

This is the Julia set image generated when checking for divisibility by 2 and 3 and 4. We can see that it sort of spirals at some critical points and produces interesting patterns:

This the fuzzy image that was generated by adding a random number between 0 and 1 to the existing pixel value:


  • We created our own Image structure for internal representation and manipulation of image data.
  • We have seen that Mandelbrot and Julia sets are very interesting sets and that they can produce very striking pictures. We have also seen that we can produce our own noise functions, which are not as fractalized as the Perlin noise function, but come close.
  • All in all, we have learned a lot about mapping different mathematical expressions onto a 2D plane, how patterns could be created and how simple manipulation of pixel position can create something fascinating.