summaryrefslogtreecommitdiff
path: root/examples/julia_set.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-08-21 18:00:17 +0200
committerMitya Selivanov <automainint@guattari.tech>2024-08-21 18:00:17 +0200
commit7161b6990a8e73d9e79c1bdddacf22ce4068a72d (patch)
treed8d326cbf1582630a7bb1f61dfbe44fe500b6217 /examples/julia_set.c
parent7cc971f6b0011efea0f459948cf98ce2afed0cef (diff)
downloadreduced_system_layer-7161b6990a8e73d9e79c1bdddacf22ce4068a72d.zip
Fix platform global var; Update Julia Set example
Diffstat (limited to 'examples/julia_set.c')
-rwxr-xr-xexamples/julia_set.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/examples/julia_set.c b/examples/julia_set.c
index 9d12bb8..747c339 100755
--- a/examples/julia_set.c
+++ b/examples/julia_set.c
@@ -45,13 +45,28 @@ i32 main(i32 argc, c8 **argv) {
f64 view_y = 0.;
f64 view_s = 1.;
- f64 cx = -.8;
- f64 cy = .1;
+ f64 cx = -.771;
+ f64 cy = .1005;
f64 radius = 2.;
i64 limit = 1024;
+ i64 time = p_time();
+
while (!platform.done) {
- p_wait_events();
+ 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);
@@ -62,13 +77,12 @@ i32 main(i32 argc, c8 **argv) {
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;
+ 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;