X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fscr%2Ffract.c;fp=src%2Fscr%2Ffract.c;h=6eeb6787611475468edfa3e68593674f335184a5;hb=ba648ddfc62fc6d3f47294aa8bfc10ea6ca3f479;hp=0000000000000000000000000000000000000000;hpb=3398fc6c4188104048f99b650a6cb90beda9b6ed;p=dosdemo diff --git a/src/scr/fract.c b/src/scr/fract.c new file mode 100644 index 0000000..6eeb678 --- /dev/null +++ b/src/scr/fract.c @@ -0,0 +1,95 @@ +#include +#include +#include "demo.h" +#include "screen.h" +#include "gfxutil.h" + +struct vec2x { + long x, y; +}; + +static int init(void); +static void destroy(void); +static void draw(void); +static int julia(long x, long y, long cx, long cy, int max_iter); + +static struct screen scr = { + "fract", + init, + destroy, + 0, 0, + draw +}; + +/*static long aspect_24x8 = (long)(1.3333333 * 256.0);*/ +static long xscale_24x8 = (long)(1.3333333 * 1.2 * 256.0); +static long yscale_24x8 = (long)(1.2 * 256.0); +static int cx, cy; +static int max_iter = 50; + +#define WALK_SIZE 20 + +struct screen *fract_screen(void) +{ + return &scr; +} + +static int init(void) +{ + return 0; +} + +static void destroy(void) +{ +} + +static void draw(void) +{ + int i, j; + unsigned short *pixels = fb_pixels; + + cx = mouse_x; + cy = mouse_y; + + for(i=0; i> 3) | ((pidx >> 2) << 5) | ((pidx >> 3) << 11); + } + } + + pixels = fb_pixels; + pixels[mouse_y * fb_width + mouse_x] = 0xffe; + swap_buffers(0); +} + +static long normalize_coord(long x, long range) +{ + /* 2 * x / range - 1*/ + return (x << 17) / range - 65536; +} + +static int julia(long x, long y, long cx, long cy, int max_iter) +{ + int i; + + /* convert to fixed point roughly [-1, 1] */ + x = (normalize_coord(x, fb_width) >> 8) * xscale_24x8; + y = (normalize_coord(y, fb_height) >> 8) * yscale_24x8; + cx = (normalize_coord(cx, fb_width) >> 8) * xscale_24x8; + cy = (normalize_coord(cy, fb_height) >> 8) * yscale_24x8; + + for(i=0; i> 8; + long py = y >> 8; + + if(px * px + py * py > (4 << 16)) { + break; + } + x = px * px - py * py + cx; + y = (px * py << 1) + cy; + } + + return i < max_iter ? (256 * i / max_iter) : 0; +}