From 7161b6990a8e73d9e79c1bdddacf22ce4068a72d Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Wed, 21 Aug 2024 18:00:17 +0200 Subject: Fix platform global var; Update Julia Set example --- examples/julia_set.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'examples/julia_set.c') 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; -- cgit v1.2.3