Specify direction and spread rather than angle limits.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 10:17:50 +0000 (12:17 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 10:17:50 +0000 (12:17 +0200)
data/stations/station-alpha.json
tabakrolletjie/lights.py
tabakrolletjie/rays.py

index e8e96194f7c62e036451835bf50f6ae907f840b6..6259351bee9ff8d2ce33c61dc29c7a2da52d49fe 100644 (file)
@@ -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
     },
index 119a13a3c46c545512499f87807d7feda2dc70e0..8353c280ed76af9a40998fba750db5c79bba45a8 100644 (file)
@@ -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
index 6e98d83337d646f39f1d4c5d27f06e1c42f906d5..65fbc3d628b19de13a237124c89f73484ab5e5a5 100644 (file)
@@ -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):