// 2>/dev/null; set -e; [ .mb.elf -nt "$0" ] || gcc -o .mb.elf -std=gnu99 -Wall -O3 "$0" -lm; exec ./.mb.elf "$@" #include #include #include #include #include #include #include #include #include #include #include #include #include void quit(int s) { system("tput cnorm"); exit(s && 1); } int main(int argc, char *argv[]) { // parameters double outside = 16, ox = -0.5, oy = 0, r = 1.5; long max_i = 50, rb_i = 30; char **p = argv; if (*++p) { ox = atof(*p); if (*++p) { oy = atof(*p); if (*++p) { r = atof(*p); if (*++p) { max_i = atoi(*p); if (*++p) { rb_i = atoi(*p); if (*++p) { outside = atof(*p); }}}}}} // framebuffer signal(SIGINT, quit); system("tput civis"); int fb = open("/dev/fb0", O_RDWR); struct fb_var_screeninfo framebuffer_info; ioctl(fb, FBIOGET_VSCREENINFO, &framebuffer_info); int w = framebuffer_info.xres; int h = framebuffer_info.yres; if (framebuffer_info.bits_per_pixel != 32) return 1; uint32_t *v = mmap(NULL, w*h*4, PROT_WRITE, MAP_SHARED, fb, 0); // rainbow uint32_t rb[360]; #define d2r(a) (M_PI*a/180) #define rbc(a, b) ((cos(a-d2r(b))+1)/2) #define byt(v) ((int)(v == 1 ? 255 : 256*v)) #define rgb(r, g, b) (byt(r)<<16 | byt(g)<<8 | byt(b)) for (int A=0; A<360; ++A) { double a = A*M_PI/180; rb[A] = rgb( rbc(a, -120), .9 * rbc(a, 0), rbc(a, 120) ); } // smoothing int smooth_n = 8; // 32 double smooth_fac = pow(2, 1.0/smooth_n); double smooth_outside[smooth_n]; for (int i=0; i= smooth_outside[j]; ++j, --i); int max_i_smooth = max_i * smooth_n, rb_i_smooth = rb_i * smooth_n; // mandelbrot set, slowly double d = 2*r/h, x0 = ox-d*w/2, y0 = oy+d*h/2; for (int y=0; y