int main() { int i, j; int count=0; count = mandelbrot(); #ifdef PRINT_IMG int i, j; unsigned char final[WIDTH][HEIGHT]; for (j = 0; j < HEIGHT; j++) { for (i = 0; i < WIDTH; i++) { final[i][j] = img[i][j]; /* final[i+1][j] = img1[i+1][j]; final[i+2][j] = img2[i+2][j]; final[i+3][j] = img3[i+3][j];*/ } } print_image(WIDTH, HEIGHT, 1, final); //print_image(WIDTH, HEIGHT, 1, img); //print_image(WIDTH, HEIGHT, MAX_ITER, img); #else printf("Count: %d\n", count); if (count == 12013) { printf("PASS\n"); } else { printf("FAIL\n"); } #endif return count; }
int main(int argc, char **argv) { Image<int> output(100, 30); const char *code = " .:-~*={}&%#@"; const int iters = strlen(code) - 1; struct timeval t1, t2; gettimeofday(&t1, NULL); // Compute 100 different julia sets for (float t = 0; t < 100; t++) { float fx = cos(t/10.0f), fy = sin(t/10.0f); mandelbrot(-2.0f, 2.0f, -1.4f, 1.4f, fx, fy, iters, output.width(), output.height(), output); } gettimeofday(&t2, NULL); char buf[4096]; char *buf_ptr = buf; for (int y = 0; y < output.height(); y++) { for (int x = 0; x < output.width(); x++) { *buf_ptr++ = code[output(x, y)]; } *buf_ptr++ = '\n'; } *buf_ptr++ = 0; printf("%s", buf); fflush(stdout); int64_t time = (t2.tv_usec - t1.tv_usec) / 1000; time += (t2.tv_sec - t1.tv_sec) * 1000; printf("Success (%lld ms)!\n", (long long)time); return 0; }
int main(int argc, char * argv[]) { printf(" UNSW Computing 1 - ASCII-BROT\n"); // iterate through each row int x = 0; int y = 0; while (y < HEIGHT) { // iterate through each column while (x < WIDTH) { if (mandelbrot(x, y)) { printf("*"); } else { printf(" "); } x++; } printf("\n"); x = 0; y++; } return EXIT_SUCCESS; }
int main (int argc, char **argv) { int imgsize; double scale; /* help */ if (argc!=3) { printf ("%s <imgsize> <file.ppm>\n\n", argv[0]); exit(0); } /* setup */ imgsize = atoi (argv[1]); assert (imgsize >= 1024); scale = SCALE * 1024 / imgsize; matrix = (unsigned char*) calloc (imgsize*imgsize, sizeof (unsigned char)); assert (matrix != NULL); /* mandelbrot */ mandelbrot(imgsize, scale) ; /* output to file */ output_ppm (argv[2], COLORMAP, matrix, imgsize, imgsize, 255); free (matrix); return 1; }
int mouse_motion_hook(int x, int y, t_mlx *mlx) { t_mand mand; t_julia ju; if (mlx->motion == 1) { mlx->add = mlx_get_data_addr(mlx->new_img, &mlx->bpp, &mlx->s_l, &mlx->edn); mlx->x = x; mlx->y = y; if (mlx->choice == 1) choice_one(mlx); if (mlx->choice == 2) { set_mandelbrot(&mand); mandelbrot(mlx, &mand); } if (mlx->choice == 3) { set_julia(&ju, mlx); manu(mlx, &ju); } mlx_put_image_to_window(mlx->init, mlx->win, mlx->new_img, 0, 0); } return (0); }
void display_mandelbrot(t_env *e) { int i; double tmp; e->x = -1; while (++e->x < e->image_x) { e->y = -1; while (++e->y < e->image_y) { i = mandelbrot(e); while (i++ < e->im && e->z_r * e->z_r + e->z_i * e->z_i < 4) { tmp = e->z_r; e->z_r = (e->z_r * e->z_r) - (e->z_i * e->z_i) + e->c_r; e->z_i = 2 * e->z_i * tmp + e->c_i; } if (i == e->im) display(e, 0, 0, 0); else display(e, i * 255 / e->im - e->b - 255, i * 255 / e->im - e->g - 255, i * 255 / e->im - e->r - 255); } } }
void handleButtonPress (XEvent *myevent, struct drawing *canvas, struct window *win) /* Zoom in on the mouse pointer */ { double range = 0.0; range = fractal_options.range; /* center clicked area */ fractal_options.origin.real += (double) (range * myevent->xbutton.x) / (double) (canvas->width * 2.0); fractal_options.origin.imag -= (double) (range * myevent->xbutton.y) / (double) (canvas->height * 2.0); /* and magnify */ fractal_options.range /= 2.0; /* increase the depth so there's a picture worth looking at */ fractal_options.depth *= 2.0; print_fractal_info (); XSetForeground (win->display, win->gc, 0x00); XSetBackground (win->display, win->gc, 0x00); XFillRectangle (win->display, canvas->pixmap, win->gc, 0, 0, canvas->width, canvas->height); XClearWindow (win->display, win->win); if (fractal_options.type == MANDELBROT) mandelbrot (canvas, win); else julia (canvas, win); }
void mandelbrot_omp(int img_x, int img_w, int img_y, int img_h, float mdb_x, float mdb_w, float mdb_y, float mdb_h, IntArray arr, int procs) { int x, y; float mx, my = mdb_y; float xi = mdb_w / img_w, yi = mdb_h / img_h; omp_set_num_threads(procs); #pragma omp parallel for \ private(x, y, mx, my) \ firstprivate(xi, yi, mdb_x, mdb_y, img_h, img_w) \ shared(arr) for (y = 0; y < img_h; y++) { mx = mdb_x; my = mdb_y + y * yi; for (x = 0; x < img_w; x++) { arr.ptr[y * img_w + x] = mandelbrot(mx, my); mx += xi; } } }
int main() { // tests(); int x = 0; int y = 0; while( y < HEIGHT) { while ( x < WIDTH) { if(mandelbrot(x, y)) { printf("*"); } else { printf(" "); } x++; } printf("\n"); x = 0; y++; } return 0; }
int main ( int argc, char * argv[] ) { double cx = 0.0, cy = 0.0; int iter=N; _c c; if ( 2<=argc ) { cx = strtod(argv[1],NULL); } if ( 3<=argc ) { cy = strtod(argv[2],NULL); } if ( 4<=argc ) { iter = strtol(argv[3],NULL,10); } c->x = cx; c->y = cy; mandelbrot(c,iter); return 0; }
void computeFractal( unsigned char *ptr) { // map from x, y to pixel position for (int x = 0; x < gImageWidth; x++) for (int y = 0; y < gImageHeight; y++) { int offset = x + y * gImageWidth; // now calculate the value at that position int fractalValue = mandelbrot( x, y); // Colorize it int red = 255 * fractalValue/maxiter; if (red > 255) red = 255 - red; int green = 255 * fractalValue*4/maxiter; if (green > 255) green = 255 - green; int blue = 255 * fractalValue*20/maxiter; if (blue > 255) blue = 255 - blue; ptr[offset*4 + 0] = red; ptr[offset*4 + 1] = green; ptr[offset*4 + 2] = blue; ptr[offset*4 + 3] = 255; } }
int main (int argc, const char * argv[]) { struct timeval aTv; gettimeofday(&aTv, NULL); long init_time = aTv.tv_sec; long init_usec = aTv.tv_usec; int x,y; for (y=-39; y<39; y++) { printf("\n"); for (x = -39; x < 39; x++) { int i = mandelbrot(x/40.0, y/40.0); if (i==0) printf("*"); else printf(" "); } } printf ("\n"); gettimeofday(&aTv,NULL); double query_time = (aTv.tv_sec - init_time) + (double)(aTv.tv_usec - init_usec)/1000000.0; printf ("C Elapsed: %0.2f\n", query_time); return 0; }
int main(int argc, char *argv[]) { uint16_t w = 1280; uint16_t h = 1024; uint8_t p[3 * w * h]; for(int y = 0; y < h; ++y) { float b = 1 - 2. * y / h; for(int x = 0; x < w; ++x) { float a = -2.5 + 3.5 * x / w; uint8_t v = 2 * mandelbrot(a, b); uint8_t r = v; uint8_t g = v; uint8_t b = v; int i = 3 * (y * w + x); p[i + 0] = r; p[i + 1] = g; p[i + 2] = b; } } tga_write(stdout, p, w, h); return EXIT_SUCCESS; }
static int ft_fractal(t_env env, int x, int y) { if (env.type == 1) return (mandelbrot(env, x, y)); if (env.type == 2) return (julia(env, x, y)); if (env.type == 3) return (mandelbar(env, x, y)); return (0); }
/** * Calculate the mandelbrot set * standard: flops=mandelbrotX(img,4096,-2.0,1.0,1.5,-1.5); */ int main(void) { double secs,flops; IMAGE *img=makeimage(1024,1024); start_timer(); flops=mandelbrot(img,4096,-1.2,-0.7,0.5,0.0); secs = stop_timer(); printf("%10.3e %10.3e %10.3e\n",secs,flops,1.0e-9*flops/secs); saveimage(img,"mandel.ppm"); return 0; }
int rand_mandel(int n, t_stock *param) { if (n == 53) { free(param->data); exit(1); } else if (n == 15) { *param->data = ft_init_data(*param->data); param->h = 1; mandelbrot(*param, param->color); } else if (n == 8) { param->color = rand(); mandelbrot(*param, param->color); } return (0); }
void draw_fract(t_env *env) { draw_options(env); if (env->fract == 'm') mandelbrot(env); else if (env->fract == 'j' || env->fract == 'k' || env->fract == 'l' || env->fract == 'n' || env->fract == ';') julia(env); else if (env->fract == 's') sierpinski_carpet(env); }
void _mandelbrot (int *w) { cl_char (*data)[200] = (cl_char*) w[0]; // due to the [][] array w[1] is 50 and w[2] is 200 // w[3] would be jobs #if CLMANDEL mandelbrot (data, (cl_fract*) (w[3])); #else mandelbrot_c (data, (cl_fract*) (w[3])); #endif }
void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float pulse = sin((iGlobalTime * 2.0 * pi * ITERATIONS_PER_SECOND / float(MAX_ITERATIONS))); int iterations = int(floor(float(MAX_ITERATIONS) * (1.05 + pulse))); vec2 coordinate = fragCoordToXY(fragCoord); int crossoverIteration = mandelbrot(coordinate, iterations); float color = 1.0 * float(crossoverIteration) / float(iterations); fragColor = vec4(color, color, color, 1.0); }
int expose_hook(t_env *en) { if (en->set == 1) mandelbrot(en); if (en->set == 2) julia(en); if (en->set == 3) glynn(en); if (en->set == 4) fperso(en); mlx_put_image_to_window(en->mlx, en->win, en->img.img_ptr, 0, 0); return (0); }
void run2() { int x,y; for (y = -39; y < 39; y++) { fputs("\n", stderr); for (x = -39; x < 39; x++) { int i = mandelbrot(x/40.0, y/40.0); if (i==0) fputs("*", stderr); else fputs(" ", stderr); } } fputs("\n", stderr); }
int * time_mandelbrot(float x[SIZE], float y[SIZE], mandelbrot_fn mandelbrot, const char *version) { struct timeval start, end; int *ret; gettimeofday(&start, NULL); for (int i = 0; i < ITER; i++) { ret = mandelbrot(x, y); } gettimeofday(&end, NULL); long elapsed = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec); printf("%s version: %d iterations, %ld usec\n", version, ITER, elapsed); return ret; }
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; }
int main(int a, char *args[]) { int i, j; printf("fractal"); unsigned int* pixmap = malloc(1024*1024*sizeof(int)); start_timer(); mandelbrot(1024.0f, 1024.0f, pixmap); stop_timer("Calculated mandelbrot."); start_timer(); writetga(pixmap, 1024, 1024, "fracout.tga"); stop_timer("Written file."); free(pixmap); return 0; }
int main(void) { FILE* f = fopen("mandel.ppm", "wb"); if (f) { enum { WIDTH = 640, HEIGHT = 428 // WIDTH = 800, HEIGHT = 534 // WIDTH = 900, HEIGHT = 600 }; fprintf(f, "P6\n %s\n %d\n %d\n %d\n", "#Mandelbrot Set", WIDTH, HEIGHT, 255); mandelbrot(f, WIDTH, HEIGHT, -2, 1, -1, 1, 1000); fclose(f); } return 0; }
int main(int argc, char *argv[]) { Image *src; src = image_create(750, 1000); //src = image_read("1view.ppm"); mandelbrot( src, 1.755, -0.02, 0.02); //mandelbrot( src, -1.0, -1.0, 3.0); //julia( src, -2.0, -2.0, 4.0); //image_noise( src, 50); image_write( src, "fractal.ppm"); image_free( src ); return(0); }
GLfloat* calculateColor(GLfloat u, GLfloat v){ switch(fracCount) { case 0: juliaSpecial=0.5; return greenJulia(u,v); break; case 1: juliaSpecial=0.0; return mandelbrot(u,v); break; case 2: //color=0; juliaSpecial=0.5; return mandelbrot3(u,v); break; case 3: // printf("Flower\n"); juliaSpecial=0.0; //color=0.0; return flower(u,v); break; case 4: //printf("Star\n"); juliaSpecial=0.9; //color=45; return starFractal(u,v); break; case 5: //printf("Julia\n"); //color=0; juliaSpecial=0.5; return julia(u,v); break; default: //printf("default\n"); //juliaSpecial=0.0; fracCount=0; glutPostRedisplay(); //return mandelbrot(u,v); break; } }
void drawMandelbrot(QImage & image, int iterations, QVector2D offset, double size, ComplexNumber critical) { ComplexNumber fz, c; double rx, ry; float color = 0.0; int wx = image.width(), wy = image.height(); int byteOffset = image.bytesPerLine() / image.width(); #pragma omp parallel for ordered schedule(dynamic) for(int y = 0; y < wy; ++y) { uchar *scanline = image.scanLine(y); for(int x = 0; x < wx; x++) { rx = (2.0 * ((double)x / (double)wx) - 1.0); ry = (2.0 * ((double)y / (double)wy) - 1.0); c = ComplexNumber(rx * size + offset.x(), ry * size + offset.y()); fz = critical; //qDebug() << "x: " << z << ", y: " << c; //fz = mandelbrot(fz, c); int i = 0; for(i = 0; i < iterations && abs(fz) <= 2.0; ++i) { fz = mandelbrot(fz, c); } #pragma omp ordered { color = (float)i / (float)iterations; if(image.format() == QImage::Format_RGB888) { *(scanline + x * byteOffset) = 255 * color; *(scanline + x * byteOffset + 1) = 255 * color; *(scanline + x * byteOffset + 2) = 255 * color; } if(image.format() == QImage::Format_Indexed8) { *(scanline + x * byteOffset) = i % (image.colorCount() + 1);// * color; } } //image.setPixel(x, y, qRgb(i % 256, i % 256, i % 256)); //image.setPixel(x, y, i % 256); } } }
void updateViewTexture(sf::Uint8* pixels, sf::Texture& texture, const sf::Rect<T> view, const std::vector<sf::Color>& palette) { const auto textureSize = texture.getSize(); sf::Vector2u ti; sf::Vector2<T> c(view.left, view.top); const sf::Vector2<T> cInc(view.width / textureSize.x, view.height / textureSize.y); unsigned int i = 0; for(ti.y = 0, c.y = view.top; ti.y < textureSize.y; ++ti.y, c.y += cInc.y) { for(ti.x = 0, c.x = view.left; ti.x < textureSize.x; ++ti.x, c.x += cInc.x, i += 4) { const auto count = mandelbrot(c, 255); const sf::Color color = palette.at(count); pixels[i] = color.r; pixels[i+1] = color.g; pixels[i+2] = color.b; pixels[i+3] = color.a; } } texture.update(pixels); }
/* / Initialize mandelbrot image for some determined area of the screen */ void *mandelbrotImage(void *threadarg) { struct thread_data *my_data; my_data = (struct thread_data *) threadarg; int max_count = my_data -> max; int Ystart = my_data-> Ystart; int Ystop = my_data -> Ystop; int Xstart = my_data -> Xstart; int Xstop = my_data -> Xstop; for (int y = Ystart; y < Ystop; y++) for (int x = Xstart; x < Xstop; x++) { float C_real = center_real - radius + (2 * radius * x) / X_WINDOW; float C_imaginary = center_imaginary - radius + (2 * radius * y) / Y_WINDOW; image[y][x][0] = image[y][x][1] = image[y][x][2] = 4 * mandelbrot(C_real, C_imaginary, max_count); } pthread_exit(NULL); }