#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 = -.771; f64 cy = .1005; f64 radius = 2.; i64 limit = 1024; i64 time = p_time(); while (!platform.done) { i32 num_events = p_handle_events(); i64 time_elapsed = p_time() - time; time += time_elapsed; b8 left = platform.key_down[KEY_LEFT]; b8 right = platform.key_down[KEY_RIGHT]; b8 up = platform.key_down[KEY_UP]; b8 down = platform.key_down[KEY_DOWN]; if (!left && !right && !up && !down && num_events == 0) { p_sleep_for(1); continue; } 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] ? .00005 : .001) * view_s * time_elapsed; if (left) { cx -= d; cy -= d; } if (right) { cx += d; cy += d; } if (up) { cx += d; cy -= d; } if (down) { cx -= d; 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; }