diff options
-rwxr-xr-x | build_all.sh | 6 | ||||
-rw-r--r-- | examples/julia_set.c | 33 |
2 files changed, 29 insertions, 10 deletions
diff --git a/build_all.sh b/build_all.sh index eb44f68..5946fad 100755 --- a/build_all.sh +++ b/build_all.sh @@ -31,7 +31,7 @@ mkdir -p bin/x11 mkdir -p bin/web # gcc $FLAGS_X11 -o ./bin/x11/graph ./examples/graph.c -# gcc $FLAGS_X11 -o ./bin/x11/julia_set ./examples/julia_set.c +gcc $FLAGS_X11 -o ./bin/x11/julia_set ./examples/julia_set.c # gcc $FLAGS_X11 -o ./bin/x11/game_of_life ./examples/game_of_life.c # gcc $FLAGS_X11 -o ./bin/x11/labyrinth ./examples/labyrinth.c # gcc $FLAGS_X11 -o ./bin/x11/sinewave ./examples/sinewave.c @@ -41,10 +41,10 @@ mkdir -p bin/web # gcc $FLAGS_X11 -o ./bin/x11/particles ./examples/particles.c # gcc $FLAGS_X11 -o ./bin/x11/echo ./examples/echo.c -gcc $FLAGS_X11 -o ./bin/x11/screenshot ./examples/screenshot.c +# gcc $FLAGS_X11 -o ./bin/x11/screenshot ./examples/screenshot.c # clang $FLAGS_WEB -o ./bin/web/graph.wasm ./examples/graph.c -# clang $FLAGS_WEB -o ./bin/web/julia_set.wasm ./examples/julia_set.c +clang $FLAGS_WEB -o ./bin/web/julia_set.wasm ./examples/julia_set.c # clang $FLAGS_WEB -o ./bin/web/game_of_life.wasm ./examples/game_of_life.c # clang $FLAGS_WEB -o ./bin/web/labyrinth.wasm ./examples/labyrinth.c # clang $FLAGS_WEB -o ./bin/web/sinewave.wasm ./examples/sinewave.c diff --git a/examples/julia_set.c b/examples/julia_set.c index 6ae8e6f..e819ca5 100644 --- a/examples/julia_set.c +++ b/examples/julia_set.c @@ -1,5 +1,7 @@ #include "../graphics.c" +#define SCALE_LIMIT (0.9) + f64 view_x = 0.; f64 view_y = 0.; f64 view_s = 1.; @@ -9,6 +11,28 @@ f64 radius = 2.; i64 limit = 1024; i64 time_0; +void apply_scale(f64 delta) { + while (delta > SCALE_LIMIT) { + apply_scale(SCALE_LIMIT); + delta -= SCALE_LIMIT; + } + while (delta < -SCALE_LIMIT) { + apply_scale(-SCALE_LIMIT); + delta += SCALE_LIMIT; + } + + f64 ds = view_s * delta * .1; + if (view_s + ds < EPSILON) + return; + f64 dx = (g_platform.cursor_x * 1. - g_platform.real_width * .5); + f64 dy = (g_platform.cursor_y * 1. - g_platform.real_height * .5); + view_x -= view_s * dx; + view_y -= view_s * dy; + view_s += ds; + view_x += view_s * dx; + view_y += view_s * dy; +} + void update_and_render_frame(void) { i32 num_events = p_handle_events(); @@ -44,13 +68,8 @@ void update_and_render_frame(void) { } if (g_platform.wheel_dy != 0.) { - f64 dx = (g_platform.cursor_x * 1. - g_platform.real_width * .5); - f64 dy = (g_platform.cursor_y * 1. - g_platform.real_height * .5); - view_x -= view_s * dx; - view_y -= view_s * dy; - view_s += view_s * g_platform.wheel_dy * .1; - view_x += view_s * dx; - view_y += view_s * dy; + apply_scale(g_platform.wheel_dy / 2.0); + apply_scale(g_platform.wheel_dy / 2.0); } for (i32 j = 0; j < g_platform.frame_height; ++j) |