t_env *init_env(void) { t_env *e; e = (t_env *)malloc(sizeof(t_env)); if (e == NULL) error_malloc(); e->win_width = WIDTH; e->win_height = HEIGHT; e->x = 0; e->y = 0; e->z = 150; e->option_x = WIDTH / 2; e->option_y = HEIGHT / 2; e->color_max = 0x000000; e->mlx = mlx_init(); e->i_max = 50; e->mouse_stop = 0; e->psychedelic = 0; e->color_value = 1; e->img = mlx_new_image(e->mlx, e->win_width, e->win_height); e->pxl = mlx_get_data_addr(e->img, &(e->bpp), &(e->s_line), &(e->ed)); e->mdb = init_mandelbrot(); e->jul = init_julia(); return (e); }
void put_mandelbrot(t_infos *i) { (i->first) ? 0 : init_mandelbrot(i); while (i->x < HEIGTH) { i->y = 0; while (i->y < WIDTH) { i->c_r = i->x / i->zoom + i->x1; i->c_i = i->y / i->zoom + i->y1; i->z_r = 0; i->z_i = 0; i->i = 0; while (i->z_r * i->z_r + i->z_i * i->z_i < 4 && i->i < i->i_max) { i->tmp = i->z_r; i->z_r = i->z_r * i->z_r - i->z_i * i->z_i + i->c_r; i->z_i = 2 * i->z_i * i->tmp + i->c_i; i->i++; } put_pixel(i); i->y++; } i->x++; } mlx_put_image_to_window(i->mlx, i->win, i->img, 0, 0); }
void reinit(t_win *win, t_frac *f) { if (win->type == FOL_JULIA) init_julia(f); else if (win->type == FOL_MANDEL) init_mandelbrot(f); else if (win->type == FOL_BURNI) init_burning_ship(f); }
int main(int argc, char ** argv) { struct mandelbrot_param param; param.height = HEIGHT; param.width = WIDTH; param.lower_r = LOWER_R; param.upper_r = UPPER_R; param.lower_i = LOWER_I; param.upper_i = UPPER_I; param.maxiter = MAXITER; param.mandelbrot_color.red = (MANDELBROT_COLOR >> 16) & 255; param.mandelbrot_color.green = (MANDELBROT_COLOR >> 8) & 255; param.mandelbrot_color.blue = MANDELBROT_COLOR & 255; // Initializes the mandelbrot computation framework. Among other, spawns the threads in thread pool init_mandelbrot(¶m); #ifdef MEASURE struct mandelbrot_timing ** thread, global; GETTIME(&global.start); thread = compute_mandelbrot(param); GETTIME(&global.stop); #elif GLUT == 1 srand(time(NULL)); gl_mandelbrot_init(argc, argv); gl_mandelbrot_start(¶m); #else compute_mandelbrot(param); ppm_save(param.picture, "mandelbrot.ppm"); #endif #ifdef MEASURE #if NB_THREADS > 0 int i; for (i = 0; i < NB_THREADS; i++) { printf("%i %li %li %li %li %li %li %li %li\n", i + 1, thread[i]->start.tv_sec, thread[i]->start.tv_nsec, thread[i]->stop.tv_sec, thread[i]->stop.tv_nsec, global.start.tv_sec, global.start.tv_nsec, global.stop.tv_sec, global.stop.tv_nsec); } #else printf("0 %li %li %li %li %li %li %li %li\n", thread[0]->start.tv_sec, thread[0]->start.tv_nsec, thread[0]->stop.tv_sec, thread[0]->stop.tv_nsec, global.start.tv_sec, global.start.tv_nsec, global.stop.tv_sec, global.stop.tv_nsec); #endif #endif // Final: deallocate structures destroy_mandelbrot(param); return EXIT_SUCCESS; }
static void launch_fractol(int type) { t_env e; e.type = type; init_mlx(&(e.mlx)); if (type == TYPE_JULIA) init_julia(&(e.info), &(e.data)); else if (type == TYPE_MANDELBROT) init_mandelbrot(&(e.info), &(e.data)); else if (type == TYPE_BUDDHABROT) init_buddhabrot(&(e.info), &(e.data)); mlx_expose_hook(e.mlx.win, expose_hook, &e); mlx_loop(e.mlx.mlx); }
int mandelbrotTest(int verbose, int iterations) { cl_int error = CL_SUCCESS; fprintf (stdout, "========= MANDELBROT =========\n"); error = init_mandelbrot(); fprintf (stdout, "init errors = %s\n", errorMessageCL(error)); cl_fract job[4] = {-25.000000, 534.086426, -0.271229, 1.159260}; cl_char *dataptr = (cl_char*)malloc(sizeof(cl_char)*100*2*50); //memset(dataptr, 2, (sizeof(cl_char)*100*2*50)); cl_char (*chdata)[200] = (cl_char*) dataptr; mandelbrot(chdata, &job[0]); free (dataptr); return error; }
void _initmandelbrot (int *w) { init_mandelbrot(); }
int mandelbrot (cl_char (*data)[200], cl_fract *job) { cl_int error; int i; #if ERROR_CHECK if (prog == NULL) { init_mandelbrot(); } #endif #if MULTI_GPUS // move to new context/cq int currentdevice = nextDevice(); cl_command_queue *cq = get_command_queue(); cl_context *context = get_cl_context(); #else int currentdevice = 0; #endif // Allocate memory for the kernel to work with cl_mem mem1, mem2; mem1 = clCreateBuffer(*context, CL_MEM_WRITE_ONLY, sizeof(cl_char)*(IMAGEHEIGHT*IMAGEWIDTH*2), 0, &error); if (mandelbrot_cl_float) { cl_float jobfloat[4]; for (i=0; i<4; i++) jobfloat[i] = (cl_float) job[i]; mem2 = clCreateBuffer(*context, CL_MEM_COPY_HOST_PTR, sizeof(cl_float)*4, jobfloat, &error); } else { mem2 = clCreateBuffer(*context, CL_MEM_COPY_HOST_PTR, sizeof(cl_fract)*4, job, &error); } // get a handle and map parameters for the kernel error = clSetKernelArg(k_mandelbrot[currentdevice], 0, sizeof(cl_mem), &mem1); error = clSetKernelArg(k_mandelbrot[currentdevice], 1, sizeof(cl_mem), &mem2); // Perform the operation (width is 100 in this example) size_t worksize[3] = {IMAGEHEIGHT, IMAGEWIDTH, 0}; error = clEnqueueNDRangeKernel(*cq, k_mandelbrot[currentdevice], 2, NULL, &worksize[0], 0, 0, 0, 0); // Read the result back into data error = clEnqueueReadBuffer(*cq, mem1, CL_TRUE, 0, sizeof(cl_char)*(IMAGEHEIGHT*IMAGEWIDTH*2), data, 0, 0, 0); // cleanup - don't perform a flush as the queue is now shared between all executions. The // blocking clEnqueueReadBuffer should be enough clReleaseMemObject(mem1); clReleaseMemObject(mem2); if (error) { fprintf (stderr, "ERROR! : %s\n", errorMessageCL(error)); exit(10); } #if C_PRINT // this will print a frame coming out of the CL kernel in a dirty but functional manner int j; int colour = -1; for (i=0; i < IMAGEHEIGHT; i++) { for (j=0; j < IMAGEWIDTH*2; j++) { if (colour != data[i][j]) { colour = data[i][j]; textcolour(colour); } j++; fprintf (stdout, "%c", data[i][j]); } fprintf(stdout, "\n"); } #endif return error; }
void draw_mandelbrot(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int h; complex c; double demrange; mandelstruct *mp; if (mandels == NULL) return; mp = &mandels[MI_SCREEN(mi)]; MI_IS_DRAWN(mi) = True; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (mp->mono_p) { XSetForeground(display, mp->gc, mp->cur_color); } else { mp->cur_color = (mp->cur_color + 1) % mp->ncolors; XSetForeground(display, mp->gc, mp->colors[mp->cur_color].pixel); } } else { if (MI_NPIXELS(mi) > 2) XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->cur_color)); else if (mp->cur_color) XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi)); else XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi)); if (++mp->cur_color >= (unsigned int) MI_NPIXELS(mi)) mp->cur_color = 0; } /* Rotate colours */ if (mp->cycle_p) { rotate_colors(display, mp->cmap, mp->colors, mp->ncolors, mp->direction); if (!(LRAND() % 1000)) mp->direction = -mp->direction; } /* so we iterate columns beyond the width of the physical screen, so that ** we just wait around and show what we've done */ if ((!mp->backwards && (mp->column >= 3 * mp->screen_width)) || (mp->backwards && (mp->column < -2 * mp->screen_width))) { /* reset to left edge of screen, bump power */ mp->backwards = (Bool) (LRAND() & 1); if (mp->backwards) mp->column = mp->screen_width - 1; else mp->column = 0; mp->power = NRAND(3) + MINPOWER; /* select a new region! */ Select(&mp->extreme_ul,&mp->extreme_lr, mp->screen_width,mp->screen_height, (int) mp->power,mp->reptop, mp->pow, mp->sin, &mp->ul,&mp->lr); } else if (mp->column >= mp->screen_width || mp->column < 0) { /* delay a while */ if (mp->backwards) mp->column--; else mp->column++; mp->counter++; return; } /* demrange is used to give some idea of scale */ demrange = mp->dem ? fabs(mp->ul.real - mp->lr.real) / 2 : 0; for (h = 0; h < mp->screen_height; h++) { unsigned int color; int result; /* c.real = 1.3 - (double) mp->column / mp->screen_width * 3.4; */ /* c.imag = -1.6 + (double) h / mp->screen_height * 3.2; */ c.real = mp->ul.real + (mp->ul.real-mp->lr.real)*(((double)(mp->column))/mp->screen_width); c.imag = mp->ul.imag + (mp->ul.imag - mp->lr.imag)*(((double) h) / mp->screen_height); result = reps(c, mp->power, mp->reptop, mp->binary, mp->interior, demrange, mp->pow, mp->sin); if (result < 0 || result >= mp->reptop) XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi)); else { color=(unsigned int) ((MI_NPIXELS(mi) * (float)result) / mp->reptop); XSetForeground(display, mp->gc, MI_PIXEL(mi, color)); } /* we no longer have vertical symmetry - so we compute all points ** and don't draw with redundancy */ XDrawPoint(display, window, mp->gc, mp->column, h); } if (mp->backwards) mp->column--; else mp->column++; mp->counter++; if (mp->counter > MI_CYCLES(mi)) { init_mandelbrot(mi); } }