Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation longer than 10^7 seconds gives very inaccurate timestep value #63

Open
LilithHafner opened this issue Jan 26, 2024 · 2 comments · May be fixed by #75
Open

Animation longer than 10^7 seconds gives very inaccurate timestep value #63

LilithHafner opened this issue Jan 26, 2024 · 2 comments · May be fixed by #75
Labels
Acknowledged We are aware of this issue and will respond soon Temporary Fix Available There is a workaround for this issue

Comments

@LilithHafner
Copy link
Contributor

LilithHafner commented Jan 26, 2024

I'm trying to play an animation indefinitely and the closest I could find was using Animation(render_area, seconds(1e10)). However, setting a time span longer than about 1e7 breaks the invariant value * timespan = time_elapsed.

Here's a working example of the code I wrote which ran into this (I made it work by lowering the animation length)

using Mousetrap

main() do app::Application
    window = Window(app)
    set_title!(window, "Bouncing Ball")

    render_area = RenderArea()

    shape = Ellipse(Vector2f(0, 0), 0.2, 0.2, 128)
    add_render_task!(render_area, RenderTask(shape))

    aspect_ratio = Ref(1.0)
    Mousetrap.connect_signal_resize!(render_area, shape) do ::RenderArea, width::Integer, height::Integer, ::Shape
        aspect_ratio[] = width / height
        nothing
    end

    animation = Animation(render_area, seconds(1e5))
    on_tick!(animation, render_area) do self::Animation, value::Float64, ra
        t = value * 1e5
        x = abs(t % 4 - 2) - 1
        t *= Base.MathConstants.φ
        y = 1 - (t % 22 - 2)^2

        w = min(.2, .2 / aspect_ratio[])
        h = min(.2, .2 * aspect_ratio[])
        as_ellipse!(shape,
            Vector2f((1-w)x, (1-h)y),
            w,
            h,
            128
        )
        queue_render(ra)
    end


    set_child!(window, render_area)

    present!(window)

    play!(animation)
end

When I set the animation time to 1e10, it moves really really fast.

@Clemapfel Clemapfel added the Acknowledged We are aware of this issue and will respond soon label Feb 8, 2024
@Clemapfel
Copy link
Owner

Clemapfel commented Feb 8, 2024

I can reproduce this, I'm not sure what's happening with the setting-animation-duration-really high, but if you want an animation to continue indefinitely, you may want to use a tick callback instead, which continues infinitely:

using Mousetrap

main() do app::Application
    window = Window(app)
    set_title!(window, "Bouncing Ball")

    render_area = RenderArea()

    shape = Ellipse(Vector2f(0, 0), 0.2, 0.2, 128)
    add_render_task!(render_area, RenderTask(shape))

    aspect_ratio = Ref(1.0)
    Mousetrap.connect_signal_resize!(render_area, shape) do ::RenderArea, width::Integer, height::Integer, ::Shape
        aspect_ratio[] = width / height
        nothing
    end

    # use tick-callback
    elapsed = 0
    set_tick_callback!(render_area, render_area) do clock::FrameClock, ra
        elapsed += as_seconds(get_time_since_last_frame(clock))
        t = elapsed
        x = abs(t % 4 - 2) - 1
        t *= Base.MathConstants.φ
        y = 1 - (t % 22 - 2)^2

        w = min(.2, .2 / aspect_ratio[])
        h = min(.2, .2 * aspect_ratio[])
        as_ellipse!(shape,
            Vector2f((1-w)x, (1-h)y),
            w,
            h,
            128
        )
        queue_render(ra)
        return TICK_CALLBACK_RESULT_CONTINUE 
        # always returning continue, means the callback will never be removed
    end

    set_child!(window, render_area)
    present!(window)
end

@Clemapfel Clemapfel added the Temporary Fix Available There is a workaround for this issue label Feb 8, 2024
@LilithHafner
Copy link
Contributor Author

tick_callback is exactly what I (and I'm guessing anyone else using animations longer than 100 days) am looking for! Thanks.

@Clemapfel Clemapfel linked a pull request Feb 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Acknowledged We are aware of this issue and will respond soon Temporary Fix Available There is a workaround for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants