static void destroy(void);
static void draw(void);
static int julia(long x, long y, long cx, long cy, int max_iter);
-static int calc_walk(struct vec2x *path, long x, long y, int max_steps);
static struct screen scr = {
"fract",
static void draw(void)
{
- int i, j, len, x, y;
- unsigned short *pixels = fb_pixels;
- struct vec2x walkpos[WALK_SIZE];
+ int i, j;
+ unsigned short *pixels = vmem_back;
cx = mouse_x;
cy = mouse_y;
}
}
- pixels = fb_pixels;
-
- if((len = calc_walk(walkpos, mouse_x, mouse_y, WALK_SIZE))) {
- x = walkpos[0].x >> 16;
- y = walkpos[0].y >> 16;
-
- for(i=1; i<len; i++) {
- int x0 = x;
- int y0 = y;
- int x1 = walkpos[i].x >> 16;
- int y1 = walkpos[i].y >> 16;
-
- if(clip_line(&x0, &y0, &x1, &y1, 0, 0, fb_width - 1, fb_height - 1)) {
- draw_line(x0, y0, x1, y1, PACK_RGB16(32, 128, 255));
- }
- x = x1;
- y = y1;
- }
- }
-
+ pixels = vmem_back;
pixels[mouse_y * fb_width + mouse_x] = 0xffe;
-
- swap_buffers(fb_pixels);
+ swap_buffers(vmem_back);
}
static long normalize_coord(long x, long range)
return (x << 17) / range - 65536;
}
-static long device_coord(long x, long range)
-{
- /* (x + 1) / 2 * (range - 1) */
- return ((x + 65536) >> 1) * (range - 1);
-}
-
static int julia(long x, long y, long cx, long cy, int max_iter)
{
int i;
return i < max_iter ? (256 * i / max_iter) : 0;
}
-
-static int calc_walk(struct vec2x *path, long x, long y, int max_steps)
-{
- int i;
- long cx, cy;
-
- /* convert to fixed point roughly [-1, 1] */
- x = cx = (normalize_coord(x, fb_width) >> 8) * xscale_24x8;
- y = cy = (normalize_coord(y, fb_height) >> 8) * yscale_24x8;
-
- for(i=0; i<max_steps; i++) {
- /* z_n = z_{n-1}**2 + c */
- long px = x >> 8;
- long py = y >> 8;
-
- path[i].x = device_coord((x << 8) / xscale_24x8, fb_width);
- path[i].y = device_coord((y << 8) / yscale_24x8, fb_height);
-
- if(px * px + py * py > (4 << 16)) {
- break;
- }
- x = px * px - py * py + cx;
- y = (px * py << 1) + cy;
- }
-
- return i;
-}