void redraw() { printf("initer: %f\n", initer); printf("X: %f %f\n", Minx, Maxx); float _x = Maxx - Minx; float _y = _x / width * height; Miny = 0 - _y / 2; Maxy = _y / 2; printf("Y: %f %f\n", Miny, Maxy); printf("conx: %f cony: %f\n", conx, cony); decors(); newcolor = 0; lastcolor = 0; pixcorx = (Maxx - Minx) / width; pixcory = (Maxy - Miny) / height; int j = 0; do { int i = 1; do { julia(i,j); if (lastcolor != newcolor) julia(i-1,j); else if (i > 0) GFX_(i-1,j) = colors[lastcolor]; newcolor = lastcolor; i+= 2; } while ( i < width ); ++j; } while ( j < height ); }
void AnimationTexture(SoSeparator * root) { // Generate a julia set to use as a texturemap julia(cr, ci, 2.5, texturewidth, textureheight, 4, bitmap, 64); SoTexture2 * texnode = texture(); // Enable backface culling SoShapeHints * hints = new SoShapeHints; hints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; hints->shapeType = SoShapeHints::SOLID; // Timer sensor SoTimerSensor * texturetimer = new SoTimerSensor(timersensorcallback, texnode); texturetimer->setInterval(0.05); texturetimer->schedule(); // Scene graph if ( root == NULL ) return; // Shouldn't happen. root->ref(); // prevent from being deleted because of the still running timer sensor // SoSeparator * root = new SoSeparator; // root->ref(); root->addChild(hints); root->addChild(texnode); root->addChild(new SoCube); }
// This function is called 20 times each second. static void timersensorcallback(void * data, SoSensor *) { static SbBool direction = false; SoTexture2 * texnode = (SoTexture2*) data; if (!direction) { cr -= 0.0005; ci += 0.0005; } else { cr += 0.0005; ci -= 0.0005; } if (ci<0.30) direction = !direction; else if (ci>0.83) direction = !direction; SbVec2s size; int nc; unsigned char * image = texnode->image.startEditing(size, nc); // Generate a julia set to use as a texturemap julia(cr, ci, 2.5, size[0], size[1], 4, image, 64); texnode->image.finishEditing(); }
int expose_hook(t_env *e) { int x; int y; e->y1 = 0; e->x1 = 0; y = 0; while (y < e->height) { x = 0; while (x < e->width) { if (e->fractal == 1) madelbrot(x, y, e); if (e->fractal == 2) julia(x, y, e); if (e->fractal == 3) dentrite(x, y, e); x++; } y++; } mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); return (0); }
void display_julia(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 = julia(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, 30 - i * 20 / e->im, 20, i * 255 / e->im); } } }
void fractol_put_julia_to_image(t_mlx_image *im, t_centre *centre, t_complex *c, t_colour *depth) { t_point p; t_complex z; t_colour colour; double colour_value; colour.endian = depth->endian; p.i = -im->size_x / 2 - 1; while (p.i++ < im->size_x / 2) { z.i = (p.i / im->size_x) * centre->radius * 2 + centre->centre.i; p.j = -im->size_y / 2 - 1; while (p.j++ < im->size_y / 2) { z.j = (p.j / im->size_y) * centre->radius * 2 + centre->centre.j; colour_value = julia(&z, c); colour.blue = (unsigned char)(colour_value * depth->blue); colour.red = (unsigned char)(colour_value * depth->red); colour.green = (unsigned char)(colour_value * depth->green); mlx_put_point2d_to_image(&p, im, &colour); } } }
static void choice_one(t_mlx *mlx) { t_julia ju; set_julia(&ju, mlx); julia(mlx, &ju); }
void julia(double * u, double* v) { static int level = 0; if (level == MAX_LEVEL) { level = 0; *u = start_u; *v = start_v; return; } else { level++; julia(u, v); double u2 = *u; double v2 = *v; to_power(&u2, &v2, POLYNOM_POWER); u2 = u2 + C_REAL; v2 = v2 + C_IMG; if ((u2 == u2) && fabs(u2) != std::numeric_limits<double>::infinity( )) *u = u2; if ((v2 == v2) && fabs(v2) != std::numeric_limits<double>::infinity( )) *v = v2; if (u2 != u2) return; if (v2 != v2){ return; } } }
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 JuliaImageSequential::refreshAll(const DomaineMaths& domainNew){ int w = getW(); int h = getH(); float dx = (float) (domainNew.dx / (float) w); float dy = (float) (domainNew.dy / (float) h); float y = domainNew.y0; for(int i = 1; i <= h; ++i){ float x = domainNew.x0; for(int j = 1; j <= w; ++j){ float h = julia(x, y); //setFloatRGBA(i, j, h, h, h); if(h == 0){ setHSB(i, j, 0, 0, 0); } else { setHSB(i, j, h, 1.0, 1.0); } x += dx; } y += dy; } }
void init_fractal(t_env *e) { if (e->ret == 7) julia(e); else uter(e); init_xy1(e); }
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); }
void kernel(bitmap_image &image) { for (int y = 0; y < DIM; ++y) { for (int x = 0; x < DIM; ++x) { int offset = x + y * DIM; int julia_value = julia(x, y); image.set_pixel(x, y, 180 * julia_value, 180 * julia_value, 180 * julia_value); } } }
int ft_motion(int x, int y, t_env *env) { env->key++; if (env->space == 0) { env->c_real = ((double)(x * 2) / env->image_x) - 1; env->c_imag = ((double)(y * 2) / env->image_y) - 1; } julia(env); 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); }
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 choose_color(t_env *e) { e->color = (e->color + 1) % 3; if (e->fract == 1) julia(e); if (e->fract == 2) mandel(e); if (e->fract == 3) tric(e); if (e->fract == 4) cub_julia(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); }
void Sample_VolumeTex::generate() { /* Evaluate julia fractal for each point */ Julia julia(global_real, global_imag, global_theta); const float scale = 2.5; const float vcut = 29.0f; const float vscale = 1.0f/vcut; HardwarePixelBufferSharedPtr buffer = ptex->getBuffer(0, 0); Ogre::StringStream d; d << "HardwarePixelBuffer " << buffer->getWidth() << " " << buffer->getHeight() << " " << buffer->getDepth(); LogManager::getSingleton().logMessage(d.str()); buffer->lock(HardwareBuffer::HBL_NORMAL); const PixelBox &pb = buffer->getCurrentLock(); d.str(""); d << "PixelBox " << pb.getWidth() << " " << pb.getHeight() << " " << pb.getDepth() << " " << pb.rowPitch << " " << pb.slicePitch << " " << pb.data << " " << PixelUtil::getFormatName(pb.format); LogManager::getSingleton().logMessage(d.str()); Ogre::uint32 *pbptr = static_cast<Ogre::uint32*>(pb.data); for(size_t z=pb.front; z<pb.back; z++) { for(size_t y=pb.top; y<pb.bottom; y++) { for(size_t x=pb.left; x<pb.right; x++) { if(z==pb.front || z==(pb.back-1) || y==pb.top|| y==(pb.bottom-1) || x==pb.left || x==(pb.right-1)) { // On border, must be zero pbptr[x] = 0; } else { float val = julia.eval(((float)x/pb.getWidth()-0.5f) * scale, ((float)y/pb.getHeight()-0.5f) * scale, ((float)z/pb.getDepth()-0.5f) * scale); if(val > vcut) val = vcut; PixelUtil::packColour((float)x/pb.getWidth(), (float)y/pb.getHeight(), (float)z/pb.getDepth(), (1.0f-(val*vscale))*0.7f, PF_A8R8G8B8, &pbptr[x]); } } pbptr += pb.rowPitch; } pbptr += pb.getSliceSkip(); } buffer->unlock(); }
int main(void) { int width = DIM; int height = DIM; int quality = 75; char *scr=(char*)malloc(width*height*3); FILE* outfile = fopen("out.jpg", "wb"); for (int i=0;i<width;i++) for (int j=0;j<height;j++) { char *p = scr + j * width * 3 + i * 3; *p = julia(i, j) * 255; p++; *p = 0; p++; *p = 0; } /* Compress to JPEG */ struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); jpeg_stdio_dest(&cinfo, outfile); cinfo.image_width=width; cinfo.image_height=height; cinfo.input_components=3; cinfo.in_color_space=JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, true); jpeg_start_compress(&cinfo, TRUE); JSAMPROW row_pointer[1]; int row_stride; row_stride = cinfo.image_width*3; while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0]=(JSAMPLE *)(scr+cinfo.next_scanline*row_stride); jpeg_write_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); free(scr); return 0; }
int rand_julia(int n, t_stock *param) { if (n == 53) { free(param->data); exit(1); } else if (n == 1 && param->stopjulia == 1) param->stopjulia = 0; else if (n == 1 && param->stopjulia == 0) param->stopjulia = 1; else if (n == 15) { *param->data = ft_init_data_julia(*param->data, 0, 0); param->h = 1; julia(*param, param->color); } else if (n == 8) { param->color = rand(); julia(*param, param->color); } return (0); }
void initBitmap(unsigned char *ptr) { for (int tid = 0; tid < GLOBAL_DIM * GLOBAL_DIM; tid++) { int iPixel = tid * 4; int iLine = tid / GLOBAL_DIM; int iColumn = tid - iLine * GLOBAL_DIM; int offset = iPixel; bool isJulia = julia(iColumn, iLine) ? 255 : 0; ptr[offset] = isJulia ? 10 : 0; ptr[offset + 1] = isJulia ? 10 : 0; ptr[offset + 2] = isJulia ? 255 : 0; ptr[offset + 3] = isJulia ? 10 : 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 loop(t_env *e) { int i; int j; i = 0; while (i < 900) { j = 0; while (j < 1440) { if (e->fract_type == 1) mandelbrot(e, j, i); else julia(e, j, i); ++j; } ++i; } }
int main() { const char density[] = { ' ', '.', ',', '-', '~', '*', '+', '#', '$' }; double width = 260, height = 80; for (std::size_t i = 0; i < height; ++i) { for (std::size_t j = 0; j < width; ++j) { complex pos(2 - 4 * j / width, 2 * i / height - 1); std::size_t symbol = julia(pos) * sizeof(density); std::cout << density[symbol]; } std::cout << '\n'; } std::cout << "Press any key to continue" << std::endl; std::cin.get(); }
int main (int argc, char **argv) { int done = 0; struct drawing canvas; struct window win; XEvent myevent; initialize (&canvas, &win, argc, argv); if (fractal_options.type == MANDELBROT) mandelbrot (&canvas, &win); else julia (&canvas, &win); while (!done) { XNextEvent (win.display, &myevent); switch (myevent.type) { case ButtonPress: handleButtonPress (&myevent, &canvas, &win); break; case Expose: handleExpose (&myevent, &canvas, &win); break; case MappingNotify: XRefreshKeyboardMapping ((XMappingEvent *) &myevent); break; case ReparentNotify: handleReparentNotify (&myevent, &win); break; case KeyPress: exit (EXIT_SUCCESS); break; } } XFreeGC (win.display, win.gc); XDestroyWindow (win.display, win.win); XCloseDisplay (win.display); return EXIT_SUCCESS; }
int expose_hook(t_env *e) { if (e->av[1] && ft_strcmp(e->av[1], "-j") == 0) { init_julia(e); julia(e); } else if (e->av[1] && ft_strcmp(e->av[1], "-m") == 0) mandel(e); else if (e->av[1] && ft_strcmp(e->av[1], "-t") == 0) tric(e); else if (e->av[1] && ft_strcmp(e->av[1], "-J") == 0) { init_cub_julia(e); cub_julia(e); } else print_command(); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); return (0); }
void draw_fractal(t_env *env) { if (env->fractal == MANDELBROT) mandelbrot(env); else if (env->fractal == JULIA) julia(env); else if (env->fractal == BURNING) burning_ship(env); else if (env->fractal == JULIA_BURNING) julia_burning_ship(env); else if (env->fractal == BIOMORPH) biomorph(env); else if (env->fractal == BIRD) bird(env); else if (env->fractal == TRIBROT) tribrot(env); else if (env->fractal == JULIA_BIRD) julia_bird(env); else print_usage(); print_menu(env); }
static void choice(t_mlx *mlx) { t_julia ju; t_mand mand; mlx->add = mlx_get_data_addr(mlx->new_img, &mlx->bpp, &mlx->s_l, &mlx->edn); if (mlx->choice == 2) { set_mandelbrot(&mand); mandelbrot(mlx, &mand); } else if (mlx->choice == 1) { set_julia(&ju, mlx); julia(mlx, &ju); } else { set_manu(&ju, mlx); manu(mlx, &ju); } mlx_put_image_to_window(mlx->init, mlx->win, mlx->new_img, 0, 0); }
void init_fract(char **argv, t_env *env) { if (ft_strequ("mandelbrot", argv[1]) || ft_strequ("m", argv[1])) { mandelbrot(env); env->fract = 'm'; } else if (ft_strequ("julia", argv[1]) || ft_strequ("j", argv[1])) { julia(env); env->fract = 'j'; } else if (ft_strequ("carpet", argv[1]) || ft_strequ("c", argv[1])) { sierpinski_carpet(env); env->fract = 's'; } else print_usage(); }
static int fractol_core(t_fol *f) { do_key(f); if (out_limits(f)) exit(0); f->step = 1 / f->zoom; f->def_min.x = -f->mid.x / f->zoom; f->def_min.y = -f->mid.y / f->zoom; f->def_max.x = (WIN_H - f->mid.x) / f->zoom; f->def_max.y = (WIN_W - f->mid.y) / f->zoom; print_rules(f); print_param(f); if (f->type == 'j') julia(f); else if (f->type == 'b') buddha(f); else if (f->type == 'B') buddha2(f); else mandelbrot(f); mlx_put_image_to_window(f->mlx, f->win, f->im, 0, 0); return (1); }