summaryrefslogtreecommitdiff
path: root/examples/julia_set.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2025-01-12 12:13:56 +0100
committerMitya Selivanov <automainint@guattari.tech>2025-01-12 12:13:56 +0100
commit29d736aecc5db0deb67053931e5b1cf03a9defc3 (patch)
tree50caf18887aeda07b24bee5d4143130f8546aff7 /examples/julia_set.c
parent464575c72a8a20b5e565f91cebfeb470edc8542e (diff)
downloadreduced_system_layer-29d736aecc5db0deb67053931e5b1cf03a9defc3.zip
f32 colors; g_ prefix
Diffstat (limited to 'examples/julia_set.c')
-rw-r--r--[-rwxr-xr-x]examples/julia_set.c61
1 files changed, 17 insertions, 44 deletions
diff --git a/examples/julia_set.c b/examples/julia_set.c
index c25b028..26e7a7a 100755..100644
--- a/examples/julia_set.c
+++ b/examples/julia_set.c
@@ -1,30 +1,3 @@
-#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 \
- -lX11 -lm -lasound \
- -o $BIN $SRC && \
- ./$BIN $@ && rm $BIN
-exit $? # */
-#endif
-
#include "../reduced_system_layer.c"
i64 p = 4;
@@ -43,43 +16,43 @@ void update_and_render_frame(void) {
i64 time_elapsed = p_time() - time_0;
time_0 += 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];
+ b8 left = g_platform.key_down[KEY_LEFT];
+ b8 right = g_platform.key_down[KEY_RIGHT];
+ b8 up = g_platform.key_down[KEY_UP];
+ b8 down = g_platform.key_down[KEY_DOWN];
if (!left && !right && !up && !down && num_events == 0) {
p_sleep_for(1);
return;
}
- if (platform.key_pressed['\n'])
+ if (g_platform.key_pressed['\n'])
p = (p == 1 ? 4 : 1);
- if (platform.key_pressed[KEY_ESCAPE]) {
+ if (g_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;
+ f64 d = (g_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;
+ if (g_platform.key_down[BUTTON_LEFT]) {
+ view_x += g_platform.cursor_dx * view_s;
+ view_y += g_platform.cursor_dy * view_s;
}
- view_s += .1 * platform.wheel_dy * view_s;
+ view_s += .1 * g_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);
+ for (i32 j = 0; j + p <= g_platform.frame_height; j += p)
+ for (i32 i = 0; i + p <= g_platform.frame_width; i += p) {
+ f64 x = .003 * ((i - g_platform.frame_width * .5) * view_s - view_x);
+ f64 y = .003 * ((j - g_platform.frame_height * .5) * view_s - view_y);
i64 n = 0;
@@ -98,7 +71,7 @@ void update_and_render_frame(void) {
for (i32 jj = 0; jj < p; ++jj)
for (i32 ii = 0; ii < p; ++ii)
- platform.pixels[(j + jj) * platform.frame_width + (i + ii)] = c;
+ g_platform.pixels[(j + jj) * g_platform.frame_width + (i + ii)] = rgb_f32_from_u32(c);
}
p_render_frame();
@@ -108,7 +81,7 @@ i32 main(i32 argc, c8 **argv) {
(void) argc;
(void) argv;
- platform = (Platform) {
+ g_platform = (Platform) {
.title = "Julia Set",
.frame_width = 960,
.frame_height = 720,