From 2b7c4e798a22d0f646061c044678f0e2e7c590d9 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 12:17:50 +0200 Subject: [PATCH] Specify direction and spread rather than angle limits. --- data/stations/station-alpha.json | 3 ++- tabakrolletjie/lights.py | 4 ++-- tabakrolletjie/rays.py | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/data/stations/station-alpha.json b/data/stations/station-alpha.json index e8e9619..6259351 100644 --- a/data/stations/station-alpha.json +++ b/data/stations/station-alpha.json @@ -30,7 +30,8 @@ "colour": "red", "position": [700, 500], "radius_limits": [20, 400], - "angle_limits": [90, 180], + "direction": 135, + "spread": 90, "angular_velocity": 5, "intensity": 0.8 }, diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 119a13a..8353c28 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -109,7 +109,7 @@ class BaseLight(object): def __init__( self, colour, position, intensity=1.0, radius_limits=None, - angle_limits=None): + direction=None, spread=None): self.colour = colour self.on = True self.intensity = intensity @@ -117,7 +117,7 @@ class BaseLight(object): self.body.light = self self.ray_manager = self.RAY_MANAGER( self.body, position, ray_filter=LIGHT_FILTER, - radius_limits=radius_limits, angle_limits=angle_limits) + radius_limits=radius_limits, direction=direction, spread=spread) self.fitting = pymunk.Circle( self.body, self.FITTING_RADIUS, self.ray_manager.position) self.fitting.filter = FITTINGS_FILTER diff --git a/tabakrolletjie/rays.py b/tabakrolletjie/rays.py index 6e98d83..65fbc3d 100644 --- a/tabakrolletjie/rays.py +++ b/tabakrolletjie/rays.py @@ -78,14 +78,15 @@ def to_pymunk_radians(deg): class RayPolyManager(object): def __init__( - self, body, position, ray_filter, radius_limits, angle_limits): + self, body, position, ray_filter, radius_limits, direction, + spread): self._body = body # light's body self._position = pymunk.Vec2d(position) # light's position self._ray_filter = ray_filter # light filter self._rays = [] # list of RayPolys self._start = None # normal vector in direction of start angle limit self._end = None # normal vector in direction of end angle limit - self._set_angle_limits(angle_limits) + self._set_angle_limits(direction, spread) self._max_radius = None # maximum radius in pixels self._min_radius = None # minimum radius in pixels self._set_radius_limits(radius_limits) @@ -139,20 +140,22 @@ class RayPolyManager(object): else: self._max_radius = radius_limits[1] + def rotatable(self): + return self._start is not None + def rotate_degrees(self, degrees): self._start.rotate_degrees(degrees) self._end.rotate_degrees(degrees) self._poly_cache = None - def _set_angle_limits(self, angle_limits): - if angle_limits is None: + def _set_angle_limits(self, direction, spread): + if direction is None or spread is None: self._start = None self._end = None else: - self._start = pymunk.Vec2d(1, 0).rotated( - to_pymunk_radians(angle_limits[0])) - self._end = pymunk.Vec2d(1, 0).rotated( - to_pymunk_radians(angle_limits[1])) + n = pymunk.Vec2d(1, 0) + self._start = n.rotated_degrees(-spread/2.) + self._end = n.rotated_degrees(spread/2.) self._poly_cache = None def polys(self): -- 2.34.1