annotate pytouhou/utils/interpolator.py @ 59:4fe37a620b22

Handle set_random_angle properly! At last!
author Thibaut Girka <thib@sitedethib.com>
date Wed, 24 Aug 2011 01:34:11 +0200
parents 694f25881d0f
children af7914413b89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
14
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 50
diff changeset
15
13
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
16 class Interpolator(object):
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17 def __init__(self, values=()):
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18 self.values = tuple(values)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19 self.start_values = tuple(values)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
20 self.end_values = tuple(values)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
21 self.start_frame = 0
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
22 self.end_frame = 0
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
23 self._frame = 0
13
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
24
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
25
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
26 def __nonzero__(self):
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
27 return self._frame <= self.end_frame
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
28
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
29
13
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
30 def set_interpolation_start(self, frame, values):
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
31 self.start_values = tuple(values)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
32 self.start_frame = frame
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
33
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
34
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
35 def set_interpolation_end(self, frame, values):
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
36 self.end_values = tuple(values)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
37 self.end_frame = frame
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
38
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
39
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40 def set_interpolation_end_frame(self, end_frame):
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41 self.end_frame = end_frame
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
42
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
44 def set_interpolation_end_values(self, values):
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
45 self.end_values = tuple(values)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
47
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
48 def update(self, frame):
50
811cefefb5c8 Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents: 20
diff changeset
49 self._frame = frame
13
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
50 if frame >= self.end_frame:
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
51 self.values = tuple(self.end_values)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52 self.start_values = tuple(self.end_values)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
53 self.start_frame = frame
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54 else:
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
55 truc = float(frame - self.start_frame) / float(self.end_frame - self.start_frame)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
56 self.values = tuple(start_value + truc * (end_value - start_value)
58bc264aba38 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
57 for (start_value, end_value) in zip(self.start_values, self.end_values))
20
6ebf9539c077 Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents: 13
diff changeset
58