From dca094220bded5c42218d1dd55752b1b93906000 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 26 Mar 2015 13:48:12 -0400 Subject: [PATCH] video recorder request; points; apply motion overflow --- __init__.py | 0 pgfw/Animation.py | 8 ++++---- pgfw/Configuration.py | 5 ++++- pgfw/Game.py | 3 ++- pgfw/Note.py | 1 + pgfw/Sprite.py | 19 ++++++++++++------- pgfw/VideoRecorder.py | 16 +++++++++++----- pgfw/motion.py | 25 ++++++++++++++++++++++++- 8 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pgfw/Animation.py b/pgfw/Animation.py index 99c3c20..b8d4470 100644 --- a/pgfw/Animation.py +++ b/pgfw/Animation.py @@ -124,10 +124,10 @@ class Account: def get_current_interval(self): return self.interval[self.interval_index] - def increment_interval_index(self): - index = self.interval_index + 1 - if index >= len(self.interval): - index = 0 + def increment_interval_index(self, increment=1): + index = self.interval_index + increment + while index >= len(self.interval): + index -= len(self.interval) self.interval_index = index def reset_interval(self): diff --git a/pgfw/Configuration.py b/pgfw/Configuration.py index 7e00a3b..4d16b93 100644 --- a/pgfw/Configuration.py +++ b/pgfw/Configuration.py @@ -94,6 +94,7 @@ class Configuration(RawConfigParser): set_option(section, "file-extension", "png", False) section = "video-recordings" add_section(section) + set_option(section, "enable", "no", False) set_option(section, "rel-path", "vids", False) set_option(section, "directory-name-format", "%Y%m%d%H%M%S", False) set_option(section, "file-extension", "png", False) @@ -388,7 +389,9 @@ class TypeDeclarations(dict): "video-recordings": {"path": ["rel-path", "path"], - "int": "framerate"}, + "int": "framerate", + + "bool": "enable"}, "setup": {"list": ["classifiers", "resource-search-path", "requirements", "data-exclude", diff --git a/pgfw/Game.py b/pgfw/Game.py index 47d47f6..b1402cc 100644 --- a/pgfw/Game.py +++ b/pgfw/Game.py @@ -54,7 +54,8 @@ class Game(GameChild): self.update() else: self.interpolator.gui.update() - self.video_recorder.update() + if self.video_recorder.requested: + self.video_recorder.update() def run(self): self.mainloop.run() diff --git a/pgfw/Note.py b/pgfw/Note.py index 89db5da..c6c7154 100644 --- a/pgfw/Note.py +++ b/pgfw/Note.py @@ -123,3 +123,4 @@ class Note(Samples): self.fadeout(fadeout) if channel and panning: channel.set_volume(*panning) + return channel diff --git a/pgfw/Sprite.py b/pgfw/Sprite.py index 89e9d1a..c6373b1 100644 --- a/pgfw/Sprite.py +++ b/pgfw/Sprite.py @@ -2,7 +2,6 @@ from os import listdir from os.path import isfile, join from sys import exc_info, stdout from glob import glob -from traceback import print_exc, print_stack from pygame import Color, Rect, Surface from pygame.image import load @@ -237,6 +236,11 @@ class Location(Rect): def reset_motion_overflow(self): self.motion_overflow.place_at_origin() + def apply_motion_overflow(self, coordinates=None): + if coordinates is None: + coordinates = self.topleft + return self.motion_overflow + coordinates + def hide(self): self.hidden = True @@ -379,13 +383,14 @@ class Frameset: if len(self.order) > 1: self.increment_index() - def increment_index(self): - increment = 1 if not self.reversed else -1 + def increment_index(self, increment=None): + if increment is None: + increment = 1 if not self.reversed else -1 index = self.current_index + increment - if index < 0: - index = self.length() - 1 - elif index >= self.length(): - index = 0 + while index < 0: + index += self.length() + while index >= self.length(): + index -= self.length() self.current_index = index def length(self): diff --git a/pgfw/VideoRecorder.py b/pgfw/VideoRecorder.py index 2aba53c..524ff87 100644 --- a/pgfw/VideoRecorder.py +++ b/pgfw/VideoRecorder.py @@ -12,11 +12,17 @@ class VideoRecorder(GameChild): def __init__(self, parent): GameChild.__init__(self, parent) - self.display_surface = self.get_display_surface() - self.delegate = self.get_delegate() - self.load_configuration() - self.reset() - self.subscribe(self.respond) + self.set_requested() + if self.requested: + self.display_surface = self.get_display_surface() + self.delegate = self.get_delegate() + self.load_configuration() + self.reset() + self.subscribe(self.respond) + + def set_requested(self): + self.requested = self.get_configuration("video-recordings")["enable"] \ + or self.check_command_line("-enable-video") def load_configuration(self): config = self.get_configuration("video-recordings") diff --git a/pgfw/motion.py b/pgfw/motion.py index b9a0911..1d7383d 100644 --- a/pgfw/motion.py +++ b/pgfw/motion.py @@ -1,7 +1,30 @@ -from math import sin, cos, atan2 +from math import sin, cos, atan2, radians def get_step(start, end, speed): x0, y0 = start x1, y1 = end angle = atan2(x1 - x0, y1 - y0) return speed * sin(angle), speed * cos(angle) + +def get_endpoint(start, angle, magnitude): + x0, y0 = start + angle = radians(angle) + return x0 + sin(angle) * magnitude, y0 - cos(angle) * magnitude + +def rotate_2d(point, center, angle, translate_angle=True): + if translate_angle: + angle = radians(angle) + x, y = point + cx, cy = center + return cos(angle) * (x - cx) - sin(angle) * (y - cy) + cx, \ + sin(angle) * (x - cx) + cos(angle) * (y - cy) + cy + +def get_points_on_circle(center, radius, count, offset=0): + angle_step = 360.0 / count + points = [] + current_angle = 0 + for _ in xrange(count): + points.append(rotate_2d((center[0], center[1] - radius), center, + current_angle + offset)) + current_angle += angle_step + return points