void update_colors(struct mandelbrot_param* param) { // Gradient color int start_r, start_g, start_b, end_r, end_g, end_b; // Other control variables int i; if(color != NULL) { free(color); } color = malloc(sizeof(int) * num_colors(param)); // Start color start_r = 219; start_g = 57; start_b = 0; // Stop color end_r = 0; end_g = 0; end_b = 0; // Initialize the color vector for (i = 0; i < num_colors(param); i++) { color[i] = (((int) ((end_g - start_g) * ((double) i / num_colors(param)) + start_g) & 255) << 16) + (((int) ((end_r - start_r) * ((double) i / num_colors(param)) + start_r) & 255) << 8) + (((int) ((end_b - start_b) * ((double) i / num_colors(param)) + start_b) & 255) << 0); } }
void update_colors(struct mandelbrot_param* param) { // Gradient color color_t start, stop; // Other control variables int i; if(color != NULL) { free(color); } color = malloc(sizeof(color_t) * num_colors(param)); // Start color start.red = 219; start.green = 57; start.blue = 0; // Stop color stop.red = 0; stop.green = 0; stop.blue = 0; // Initialize the color vector for (i = 0; i < num_colors(param); i++) { color[i].green = (stop.green - start.green) * ((double) i / num_colors(param)) + start.green; color[i].red = (stop.red - start.red) * ((double) i / num_colors(param)) + start.red; color[i].blue = (stop.blue - start.blue) * ((double) i / num_colors(param)) + start.blue; } }
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); } } }
/***** 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); } } }