11 static int init(void);
12 static void destroy(void);
13 static void draw(void);
14 static int julia(long x, long y, long cx, long cy, int max_iter);
16 static struct screen scr = {
24 /*static long aspect_24x8 = (long)(1.3333333 * 256.0);*/
25 static long xscale_24x8 = (long)(1.3333333 * 1.2 * 256.0);
26 static long yscale_24x8 = (long)(1.2 * 256.0);
28 static int max_iter = 50;
32 struct screen *fract_screen(void)
42 static void destroy(void)
46 static void draw(void)
49 unsigned short *pixels = fb_pixels;
54 for(i=0; i<FB_HEIGHT; i++) {
55 for(j=0; j<FB_WIDTH; j++) {
56 unsigned char pidx = julia(j, i, cx, cy, max_iter) & 0xff;
57 *pixels++ = (pidx >> 3) | ((pidx >> 2) << 5) | ((pidx >> 3) << 11);
62 pixels[mouse_y * FB_WIDTH + mouse_x] = 0xffe;
66 static long normalize_coord(long x, long range)
68 /* 2 * x / range - 1*/
69 return (x << 17) / range - 65536;
72 static int julia(long x, long y, long cx, long cy, int max_iter)
76 /* convert to fixed point roughly [-1, 1] */
77 x = (normalize_coord(x, FB_WIDTH) >> 8) * xscale_24x8;
78 y = (normalize_coord(y, FB_HEIGHT) >> 8) * yscale_24x8;
79 cx = (normalize_coord(cx, FB_WIDTH) >> 8) * xscale_24x8;
80 cy = (normalize_coord(cy, FB_HEIGHT) >> 8) * yscale_24x8;
82 for(i=0; i<max_iter; i++) {
83 /* z_n = z_{n-1}**2 + c */
87 if(px * px + py * py > (4 << 16)) {
90 x = px * px - py * py + cx;
91 y = (px * py << 1) + cy;
94 return i < max_iter ? (256 * i / max_iter) : 0;