Mercurial > repos > public > sbplib
comparison +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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:48b6fb693025 |
---|---|
1 % Calls F(t) repeatedly | |
2 % Should there be a Fsetup and a F, two function, to allow creating a plot and then updating it? | |
3 % F takes the time to generate the frame for and returns the actual time for the generated frame. | |
4 % t = F(t_r) is a function that paints a frame for time t. t is the closest time <=t_r | |
5 % it will be called for increasnig t. | |
6 | |
7 %Todo: make it catch up and produce warnings if it lags behind? Instead of just requesting the next target time | |
8 function animate(F, t, tend, time_modifier , frame_rate) | |
9 if ~exist('time_modifier') | |
10 time_modifier = 1; | |
11 end | |
12 | |
13 if ~exist('frame_rate') | |
14 frame_rate = 30; | |
15 end | |
16 | |
17 frame_time = 1/frame_rate; | |
18 dt = frame_time*time_modifier; | |
19 | |
20 animation_start = tic(); | |
21 t = F(t); | |
22 while t < tend | |
23 t = F(t + dt); | |
24 | |
25 t_left = t/time_modifier-toc(animation_start); | |
26 | |
27 pause(t_left) | |
28 end | |
29 time_to_animate = toc(animation_start); | |
30 expected_time = tend/time_modifier; | |
31 fprintf('Time to animate: %.3f\n', time_to_animate) | |
32 fprintf('Expected time : %.3f\n', expected_time) | |
33 end |