Mercurial > repos > public > sbplib
annotate +noname/Animation.m @ 1301:8978521b0f06 default
Fix incorrect package name.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 08 Jul 2020 19:11:04 +0200 |
parents | c360bbecf260 |
children |
rev | line source |
---|---|
615
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
1 classdef Animation < handle |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
2 properties |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
3 timeStepper |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
4 representationMaker |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
5 updaters |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
6 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
7 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
8 % add input validation |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
9 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
10 methods |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
11 function obj = Animation(timeStepper, representationMaker, updaters); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
12 obj.timeStepper = timeStepper; |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
13 obj.updaters = updaters; |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
14 obj.representationMaker = representationMaker; |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
15 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
16 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
17 function update(obj, r) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
18 for i = 1:length(obj.updaters) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
19 obj.updaters{i}(r); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
20 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
21 drawnow |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
22 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
23 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
24 function run(obj, tEnd, timeModifier, do_pause) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
25 default_arg('do_pause', false) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
26 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
27 function next_t = G(next_t) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
28 obj.timeStepper.evolve(next_t); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
29 r = obj.representationMaker(obj.timeStepper); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
30 obj.update(r); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
31 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
32 if do_pause |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
33 pause |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
34 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
35 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
36 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
37 anim.animate(@G, obj.timeStepper.t, tEnd, timeModifier); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
38 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
39 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
40 function step(obj, tEnd, do_pause) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
41 default_arg('do_pause', false) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
42 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
43 while obj.timeStepper.t < tEnd |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
44 obj.timeStepper.step(); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
45 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
46 r = obj.representationMaker(obj.timeStepper); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
47 obj.update(r); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
48 |
618 | 49 % TODO: Make it never go faster than a certain fram rate |
50 | |
615
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
51 if do_pause |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
52 pause |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
53 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
54 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
55 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
56 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
57 function saveMovie(obj, tEnd, timeModifier, figureHandle, dirname) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
58 save_frame = anim.setup_fig_mov(figureHandle, dirname); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
59 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
60 function next_t = G(next_t) |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
61 obj.timeStepper.evolve(next_t); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
62 r = obj.representationMaker(obj.timeStepper); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
63 obj.update(r); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
64 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
65 save_frame(); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
66 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
67 |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
68 fprintf('Generating and saving frames to: ..\n') |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
69 anim.animate(@G, obj.timeStepper.t, tEnd, timeModifier); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
70 fprintf('Generating movies...\n') |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
71 cmd = sprintf('bash %s/+anim/make_movie.sh %s', sbplibLocation(),dirname); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
72 system(cmd); |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
73 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
74 end |
68f9c16569fa
Add class to handle animations in a smoother and more modular way
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
75 end |