comparison +anim/animate.m @ 79:4cd77c7bdcaf

Fixed bug in anim.animate for starting times != 0.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 25 Nov 2015 18:32:29 +0100
parents 1edee9e1ea41
children 6ec2248b83c4
comparison
equal deleted inserted replaced
78:80948a4084f3 79:4cd77c7bdcaf
3 % F takes the time to generate the frame for and returns the actual time for the generated frame. 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 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. 5 % it will be called for increasnig t.
6 6
7 %Todo: make it catch up and produce warnings if it lags behind? Instead of just requesting the next target time 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) 8 function animate(F, tstart, tend, time_modifier , frame_rate)
9 if ~exist('time_modifier') 9 if ~exist('time_modifier')
10 time_modifier = 1; 10 time_modifier = 1;
11 end 11 end
12 12
13 if ~exist('frame_rate') 13 if ~exist('frame_rate')
16 16
17 frame_time = 1/frame_rate; 17 frame_time = 1/frame_rate;
18 dt = frame_time*time_modifier; 18 dt = frame_time*time_modifier;
19 19
20 animation_start = tic(); 20 animation_start = tic();
21 t = F(t); 21 t = F(tstart);
22 while t < tend 22 while t < tend
23 t = F(t + dt); 23 t = F(t + dt);
24 24 t_left = (t-tstart)/time_modifier-toc(animation_start);
25 t_left = t/time_modifier-toc(animation_start);
26
27 pause(t_left) 25 pause(t_left)
28 end 26 end
29 time_to_animate = toc(animation_start); 27 time_to_animate = toc(animation_start);
30 expected_time = tend/time_modifier; 28 expected_time = tend/time_modifier;
31 29