**CS 351 Assignment #2: Fractals**

*Justin Russell & Adam Lowenstein*

**Abstract**

In this assignment, we created and altered a number of images. We started by defining the appropriate type structures and functions in C. These programs allowed us to produce and edit different types of images. Some of the images that we produced were generated from scratch, like the fractals created through the use of Mandelbrot and Julia sets. The program that we created to generate these images tested each pixel to see whether it was in the zero attractor (i.e., it was eventually going to zero) or the infinity attractor. *The picture to the right was generated using the Julia set with an iteration limit of 100, meaning that if the number of iterations exceeded 100, the pixel was assumed to be going to infinity*.

The other part of this assignment involved making a number of modifications to a photograph taken in front of a blue screen. These modifications included changing the background color, replacing the background color with a photograph of the same size, and replacing the background with a photograph of a different size. These operations are described in greater detail in the sections below.

**Description**

Before we could begin generating images of the Mandelbrot and Julia sets, we needed to create the Image type structure in C. To do so, we created a function called Image_init() that takes two integer parameters, rows and columns, and allocates the corresponding space for an image. In Image_mandelbrot(), we used Image_init() to implement the Mandelbrot algorithm provided in the lab notes. By altering the variables and constants within the algorithm, we were able to create a number of different representations of the Mandelbrot and Julia sets.

In the second part of the lab, we took a picture of Adam that was taken in front of a blue screen replaced the background. First, we wrote a program that turned to black all of the blue pixels above a certain threshold of "blueness," so the image was set against a black background. Then, we replaced the black background and imported an image of the Wu-Tang Clan (R.I.P. ODB) as our new background

**How we solved the the task**

As mentioned earlier, the algorithm used to generate the Mandelbrot and Julia sets was based on the pseudocode provided in the lab notes. Our implementation of that algorithm is shown below:Image *Image_julia(float x0, float y0, float x1, float y1, int rows, float cx, float cy) {

Image *im;

int cols = (x1 -x0) * rows / (y1 - y0);

int i, j, n;

float x, y, zx, zy, scols, srows;

scols = (x1 - x0) / cols;

srows = (y1 - y0) / rows;

im = Image_init(rows, cols);

for(i = 0; i < rows; i++) {

for(j = 0; j < cols; j++) {

x = (scols * j + x0);

y = (-srows * i + y1);

for(n = 0; n < 100; n++) {

zx = x*x - y*y - cx;

zy = 2 * x * y - cy;

x = zx;

y = zy;

if( sqrt(x*x + y*y) > 2)

}

if(n < 100)

else

}

}

return(im);

}

Using this algorithm in conjunction with another Mandelbrot.c file (to generate the image and specify its dimensions), we created the following images: