#if 0 /* #/ ================================================================ #/ #/ julia_set.c #/ #/ ================================================================ #/ #/ Self-compilation shell script #/ SRC=${0##*./} BIN=${SRC%.*} gcc \ -Wall -Wextra -Werror -pedantic \ -Wno-old-style-declaration \ -Wno-missing-braces \ -Wno-unused-variable \ -Wno-unused-but-set-variable \ -Wno-unused-parameter \ -Wno-overlength-strings \ -g -O3 \ -fsanitize=undefined,address,leak -mshstk \ -lX11 -lm \ -o $BIN $SRC && \ ./$BIN $@ && rm $BIN exit $? # */ #endif #include "../reduced_system_layer.c" i32 main(i32 argc, c8 **argv) { (void) argc; (void) argv; platform = (Platform) { .title = "Julia Set", .frame_width = 960, .frame_height = 720, }; p_init(); i64 p = 4; f64 view_x = 0.; f64 view_y = 0.; f64 view_s = 1.; f64 cx = -.8; f64 cy = .1; f64 radius = 2.; i64 limit = 1024; while (!platform.done) { p_wait_events(); if (platform.key_pressed['\n']) p = (p == 1 ? 4 : 1); if (platform.key_pressed[KEY_ESCAPE]) { view_x = 0.; view_y = 0.; view_s = 1.; } f64 d = platform.key_down[MOD_CTRL] ? .0005 : .01; if (platform.key_pressed['q']) cx -= d; if (platform.key_pressed['w']) cx += d; if (platform.key_pressed['a']) cy -= d; if (platform.key_pressed['s']) cy += d; if (platform.key_down[BUTTON_LEFT]) { view_x += platform.cursor_dx * view_s; view_y += platform.cursor_dy * view_s; } view_s += .1 * platform.wheel_dy * view_s; for (i32 j = 0; j + p <= platform.frame_height; j += p) for (i32 i = 0; i + p <= platform.frame_width; i += p) { f64 x = .003 * ((i - platform.frame_width * .5) * view_s - view_x); f64 y = .003 * ((j - platform.frame_height * .5) * view_s - view_y); i64 n = 0; for (; x * x + y * y < radius * radius && n < limit; ++n) { f64 z = x * x - y * y; y = 2. * x * y + cy; x = z + cx; } u32 c; if (n == limit) c = 0; else c = 0xffffff - n * 8 - n * 256 * 4; for (i32 jj = 0; jj < p; ++jj) for (i32 ii = 0; ii < p; ++ii) platform.pixels[(j + jj) * platform.frame_width + (i + ii)] = c; } p_render_frame(); } p_cleanup(); return 0; }