spectrum_cmbrot
diff test.c @ 0:e56d8b0eee4b
spectrum fractal :)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 17 Feb 2014 10:17:17 +0200 |
parents | |
children | c2815c765fea |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test.c Mon Feb 17 10:17:17 2014 +0200 1.3 @@ -0,0 +1,69 @@ 1.4 +#define FB_ADDR ((unsigned char*)0x4000) 1.5 +#define ATTR_ADDR ((unsigned char*)0x5800) 1.6 +#define LINESKIP (256 / 8) 1.7 + 1.8 +unsigned char mbrot(int px, int py); 1.9 + 1.10 +int main() 1.11 +{ 1.12 + unsigned int i, j, k, start; 1.13 + 1.14 + for(;;) { 1.15 + start = 0; 1.16 + 1.17 + for(i=0; i<192; i++) { 1.18 + unsigned int banky = i & 0x3f; 1.19 + unsigned int cell = banky / 8; 1.20 + unsigned int cline = banky % 8; 1.21 + unsigned int memline = cell + cline * 8; 1.22 + unsigned char *ptr = FB_ADDR + (start + memline) * LINESKIP; 1.23 + 1.24 + for(j=0; j<32; j++) { /* 256 pixels, 8 pixels per byte */ 1.25 + unsigned char pixel = 0; 1.26 + for(k=0; k<8; k++) { 1.27 + unsigned char res = mbrot((j << 3) + k, i); 1.28 + pixel = pixel | (res & 1); 1.29 + if(k < 7) pixel <<= 1; 1.30 + } 1.31 + *ptr++ = pixel; 1.32 + } 1.33 + 1.34 + if((i & 0x3f) == 0x3f) { 1.35 + start += 0x40; 1.36 + } 1.37 + } 1.38 + } 1.39 +} 1.40 + 1.41 +#define int2fix8_8(i) ((i) << 8) 1.42 +#define fix_mul8_8(a, b) ((a >> 4) * (b >> 4)) 1.43 +#define int2fix5_11(i) ((i) << 11) 1.44 +#define fix_mul5_11(a, b) ((a >> 5) * (b >> 6)) 1.45 + 1.46 +unsigned char mbrot(int px, int py) 1.47 +{ 1.48 + unsigned char i; 1.49 + int cx, cy, zx, zy, x, y, len; 1.50 + 1.51 + cx = int2fix8_8(px - 192) >> 6; 1.52 + cy = int2fix8_8(py - 96) >> 6; 1.53 + 1.54 + cx <<= 3; 1.55 + cy <<= 3; 1.56 + 1.57 + zx = cx; 1.58 + zy = cy; 1.59 + 1.60 + for(i=0; i<32; i++) { 1.61 + x = fix_mul5_11(zx, zx) - fix_mul5_11(zy, zy) + cx; 1.62 + y = fix_mul5_11(zy, zx) + fix_mul5_11(zx, zy) + cy; 1.63 + len = fix_mul5_11(x, x) + fix_mul5_11(y, y); 1.64 + 1.65 + if(len > int2fix5_11(4)) return 0; 1.66 + 1.67 + zx = x; 1.68 + zy = y; 1.69 + } 1.70 + 1.71 + return 1; 1.72 +}