summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgroup1 <f16_group1@pbridge.adm.cs.cmu.edu>2016-10-10 00:05:10 -0400
committergroup1 <f16_group1@pbridge.adm.cs.cmu.edu>2016-10-10 00:05:10 -0400
commit7e93a2df3c49bac0b9e55a0f3a809d9252475037 (patch)
treeea6c18822ecee3c39934370bdc6a8822edadfa48
parent882a9d5a8799016f98a34cba1deae11b3aad8c66 (diff)
downloadbridge-7e93a2df3c49bac0b9e55a0f3a809d9252475037.tar.zst
Improve sun colors
-rw-r--r--sunrise.py64
1 files changed, 29 insertions, 35 deletions
diff --git a/sunrise.py b/sunrise.py
index 7e11ee3..59818d5 100644
--- a/sunrise.py
+++ b/sunrise.py
@@ -9,38 +9,40 @@ from show import Show
class Sun(object):
"""Object displayed on the bridge, probably a fish."""
- def __init__(self, x, y, width, height, c, step):
+ def __init__(self):
"""Create fish with default parameters."""
- self.x = x
- self.y = y
- self.x = 75
- self.y = -2
- self.width = width
- self.width = 75
- self.height = height
- self.height = 2
- self.color = c
- self.color = color.RGB(1, 0.5, 0)
- self.speed = step
- self.step = step
+ self.center_x = 140
+ self.center_y = -5
+ self.width = 30
+ self.height = 5
self.wait = 0
def update(self):
"""Swim gently to the other side of the bridge."""
- #self.x += self.step
- #if self.x > 200:
- # self.x = 0
- #self.y = 0.25 + 0.25 * math.sin(math.pi * self.x / 10)
- #theta = random.random() * math.pi / 2 - math.pi / 4
- #self.y += 0.01 * math.sin(theta)
- #print(self.y)
- self.y += 0.005
- if self.y >= 1:
- self.y = 1
+ self.center_y += 0.005
+ if self.center_y >= 1:
+ self.center_y = 1
self.wait += 1
if self.wait >= 200:
self.wait = 0
- self.y = -2
+ self.center_y = -5
+
+ def color_at(self, x, y):
+ ball_width = 15
+ if abs(x - self.center_x) < ball_width:
+ return color.RGB(1, 1, 1)
+ distance = abs(self.center_x - x)
+ start_hue = 58 / 360
+ end_hue = 41 / 360
+ start_sat = 0
+ end_sat = 0.92
+ sat = scale_with_clamp(distance, ball_width, 60, start_sat, end_sat)
+ hue = scale_with_clamp(distance, ball_width, 100, start_hue, end_hue)
+ return color.HSV(hue, sat, 1).to_RGB()
+
+
+def scale_with_clamp(inp, min_inp, max_inp, min_out, max_out):
+ return (clamp(min_inp, inp, max_inp) - min_inp) / (max_inp - min_inp) * (max_out - min_out) + min_out
class Light(object):
@@ -54,17 +56,9 @@ class Light(object):
self.x = x
self.y = y
- def update(self, fish):
+ def update(self, sun):
"""Change color depending on where the fish is."""
- if self.y == 1:
- new_color = color.RGB(0.5, 0.5, 0.5)
- else:
- new_color = color.RGB(0.5, 0.5, 0)
- coverage = compute_coverage(fish, self.x, self.y)
- ccolor = new_color * (1 - coverage) + fish.color * coverage
- self.light.setRGBRaw(
- *map(lambda x: clamp(0, x, 1), ccolor.components)
- )
+ self.light.setRGBRaw(*sun.color_at(self.x, self.y).components)
class SunriseShow(Show):
@@ -72,7 +66,7 @@ class SunriseShow(Show):
self.lights = [Light(x, y, self.bridge.get_light(x, y))
for y in xrange(self.bridge.HEIGHT)
for x in xrange(self.bridge.WIDTH)]
- self.sun = Sun(0, 0, 23, 1.5, color.black, 1)
+ self.sun = Sun()
def update(self):