Mercurial > repos > public > sbplib
comparison +noname/Animation.m @ 615:68f9c16569fa feature/grids
Add class to handle animations in a smoother and more modular way
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 11 Oct 2017 16:01:02 +0200 |
parents | |
children | c360bbecf260 |
comparison
equal
deleted
inserted
replaced
614:64a9a8a27858 | 615:68f9c16569fa |
---|---|
1 classdef Animation < handle | |
2 properties | |
3 timeStepper | |
4 representationMaker | |
5 updaters | |
6 end | |
7 | |
8 % add input validation | |
9 | |
10 methods | |
11 function obj = Animation(timeStepper, representationMaker, updaters); | |
12 obj.timeStepper = timeStepper; | |
13 obj.updaters = updaters; | |
14 obj.representationMaker = representationMaker; | |
15 end | |
16 | |
17 function update(obj, r) | |
18 for i = 1:length(obj.updaters) | |
19 obj.updaters{i}(r); | |
20 end | |
21 drawnow | |
22 end | |
23 | |
24 function run(obj, tEnd, timeModifier, do_pause) | |
25 default_arg('do_pause', false) | |
26 | |
27 function next_t = G(next_t) | |
28 obj.timeStepper.evolve(next_t); | |
29 r = obj.representationMaker(obj.timeStepper); | |
30 obj.update(r); | |
31 | |
32 if do_pause | |
33 pause | |
34 end | |
35 end | |
36 | |
37 anim.animate(@G, obj.timeStepper.t, tEnd, timeModifier); | |
38 end | |
39 | |
40 function step(obj, tEnd, do_pause) | |
41 default_arg('do_pause', false) | |
42 | |
43 while obj.timeStepper.t < tEnd | |
44 obj.timeStepper.step(); | |
45 | |
46 r = obj.representationMaker(obj.timeStepper); | |
47 obj.update(r); | |
48 | |
49 if do_pause | |
50 pause | |
51 end | |
52 end | |
53 end | |
54 | |
55 function saveMovie(obj, tEnd, timeModifier, figureHandle, dirname) | |
56 save_frame = anim.setup_fig_mov(figureHandle, dirname); | |
57 | |
58 function next_t = G(next_t) | |
59 obj.timeStepper.evolve(next_t); | |
60 r = obj.representationMaker(obj.timeStepper); | |
61 obj.update(r); | |
62 | |
63 save_frame(); | |
64 end | |
65 | |
66 fprintf('Generating and saving frames to: ..\n') | |
67 anim.animate(@G, obj.timeStepper.t, tEnd, timeModifier); | |
68 fprintf('Generating movies...\n') | |
69 cmd = sprintf('bash %s/+anim/make_movie.sh %s', sbplibLocation(),dirname); | |
70 system(cmd); | |
71 end | |
72 end | |
73 end |