view general/algo/iterate_sched.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents e44f49929e56
children
line wrap: on
line source
function tm=iterate_sched(nextfn,X,T,varargin)
% iterate_sched - Iterate function under control of timer
%
% iterate_sched :: 
%    (A=>A)          ~'state transformer action',
%    A               ~'initial state',
%    real            ~'time between updates in seconds'
%    options {
%       drawnow   :: {0,1} /0 ~'call drawnow after each iteration';
%       busy_mode :: {'queue','drop'} /'queue'  ~'See TIMER';
%       its       :: natural / inf ~'iteration limit'
% -> timer.

	opts=prefs('its',inf,'drawnow',0,'busy_mode','queue','props',{},varargin{:});
	if opts.drawnow, post=@drawnow; else post=@nop; end

	tm=rsched(@action,nows,T,opts.its,iterdata(nextfn,X));
	function [err,s]=action(t_sched,dt,s)
		err=nows-t_sched;
		s=nextfn(s);
		post();
	end
end