Mercurial > repos > public > sbplib
view +anim/animate.m @ 87:0a29a60e0b21
In Curve: Rearranged for speed. arc_length_fun is now a property of Curve. If it is not supplied, it is computed via the derivative and spline fitting. Switching to the arc length parameterization is much faster now. The new stuff can be tested with testArcLength.m (which should be deleted after that).
author | Martin Almquist <martin.almquist@it.uu.se> |
---|---|
date | Sun, 29 Nov 2015 22:23:09 +0100 |
parents | 4cd77c7bdcaf |
children | 6ec2248b83c4 |
line wrap: on
line source
% 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, tstart, 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(tstart); while t < tend t = F(t + dt); t_left = (t-tstart)/time_modifier-toc(animation_start); pause(t_left) end time_to_animate = toc(animation_start); expected_time = tend/time_modifier; fprintf('\n'); fprintf('Time to animate: %.3f\n', time_to_animate) fprintf('Expected time : %.3f\n', expected_time) end