Example #1
0
static void
compute_chunk(struct mandelbrot_param *args)
{
	int i, j, val;
	float Cim, Cre;
	color_t pixel;

	// Iterate through lines
	for (i = args->begin_h; i < args->end_h; i++)
	{
		// Iterate through pixels in a line
		for (j = args->begin_w; j < args->end_w; j++)
		{
			// Convert the coordinate of the pixel to be calculated to both
			// real and imaginary parts of the complex number to be checked
			Cim = (float) i / args->height * (args->upper_i - args->lower_i)
			    + args->lower_i;
			Cre = (float) j / args->width * (args->upper_r - args->lower_r)
			    + args->lower_r;

			// Gets the value returned by is_in_mandelbrot() and scale it
			// from 0 to 255, or -1 if (Cre, Cim) is in the mandelbrot set.
			val = is_in_Mandelbrot(Cre, Cim, args->maxiter);

			// Change a negative value to 0 in val to make mandelbrot
			// elements to appear black in the final picture.
			pixel = val > args->maxiter ? args->mandelbrot_color : color[val
			    % num_colors(args)];

			ppm_write(args->picture, j, i, pixel);
		}
	}
}
Example #2
0
/***** You may modify this portion *****/
static void
compute_chunk(struct mandelbrot_param *args, int offseti, int offsetj)
{
	int i, j, val;
	float Cim, Cre;
	color_t pixel;
	
	//#pragma omp parallel for schedule(dynamic, 1) private(i,j,pixel,Cim,Cre,val)  
	for (i = 0; i < args->height; i++)
	{
		for (j = 0; j < args->width; j++)
		{
			// Convert the coordinate of the pixel to be calculated to both
			// real and imaginary parts of the complex number to be checked
			Cim = (float) i / args->height * (args->upper_i - args->lower_i)
			    + args->lower_i;
			Cre = (float) j / args->width * (args->upper_r - args->lower_r)
			    + args->lower_r;

			// Gets the value returned by is_in_mandelbrot() and scale it
			// from 0 to 255, or -1 if (Cre, Cim) is in the mandelbrot set.
			val = is_in_Mandelbrot(Cre, Cim, args->maxiter);

			// Change a negative value to 0 in val to make mandelbrot
			// elements to appear black in the final picture.
			val = val > args->maxiter ? args->mandelbrot_color : color[val
			    % num_colors(args)];

			// Permute green, red and blue to get different fancy colors
			pixel.green = val >> 16 & 255;
			pixel.red = val >> 8 & 255;
			pixel.blue = val & 255;
			ppm_write(args->picture, j + offsetj, i + offseti, pixel);
		}
	}
}