Mercurial > repos > public > sbplib
diff +anim/animate.m @ 0:48b6fb693025
Initial commit.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 17 Sep 2015 10:12:50 +0200 |
parents | |
children | 1edee9e1ea41 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+anim/animate.m Thu Sep 17 10:12:50 2015 +0200 @@ -0,0 +1,33 @@ +% Calls F(t) repeatedly +% Should there be a Fsetup and a F, two function, to allow creating a plot and then updating it? +% F takes the time to generate the frame for and returns the actual time for the generated frame. +% t = F(t_r) is a function that paints a frame for time t. t is the closest time <=t_r +% it will be called for increasnig t. + +%Todo: make it catch up and produce warnings if it lags behind? Instead of just requesting the next target time +function animate(F, t, tend, time_modifier , frame_rate) + if ~exist('time_modifier') + time_modifier = 1; + end + + if ~exist('frame_rate') + frame_rate = 30; + end + + frame_time = 1/frame_rate; + dt = frame_time*time_modifier; + + animation_start = tic(); + t = F(t); + while t < tend + t = F(t + dt); + + t_left = t/time_modifier-toc(animation_start); + + pause(t_left) + end + time_to_animate = toc(animation_start); + expected_time = tend/time_modifier; + fprintf('Time to animate: %.3f\n', time_to_animate) + fprintf('Expected time : %.3f\n', expected_time) +end