|
| 1 | +""" |
| 2 | +Day 19 - Rotating Star |
| 3 | +
|
| 4 | +A rotating star on a color shifting background (and another star |
| 5 | +behind it rotating the other way). |
| 6 | +""" |
| 7 | + |
| 8 | +from xled_plus.samples.sample_setup import * |
| 9 | + |
| 10 | +class RotatingStarScene(Scene): |
| 11 | + def __init__(self, ctr): |
| 12 | + super(RotatingStarScene, self).__init__(ctr) |
| 13 | + self.star1c = Star(5, (0, 0), 0.0, 0.25, 0.1, hsl_color(0.38, 1.0, 0.4)) |
| 14 | + self.star1b = Star(5, (0, 0), 0.0, 0.5, 0.2, hsl_color(0.40, 1.0, 0.2)) |
| 15 | + self.star1a = Star(5, (0, 0), 0.0, 0.75, 0.3, hsl_color(0.42, 1.0, 0.0)) |
| 16 | + self.star2 = Star(5, (0, 0), 0.0, 0.75, 0.4, hsl_color(0.48, 1.0, 0.1)) |
| 17 | + self.star1a.set_torque(24 / self.preferred_fps) |
| 18 | + self.star1b.set_torque(24 / self.preferred_fps) |
| 19 | + self.star1c.set_torque(24 / self.preferred_fps) |
| 20 | + self.star2.set_torque(-24 / self.preferred_fps) |
| 21 | + self.star1a.set_depth(1.2) |
| 22 | + self.star1b.set_depth(1.1) |
| 23 | + self.star1c.set_depth(1.0) |
| 24 | + self.star2.set_depth(2) |
| 25 | + self.add_shape(self.star1a) |
| 26 | + self.add_shape(self.star1b) |
| 27 | + self.add_shape(self.star1c) |
| 28 | + self.add_shape(self.star2) |
| 29 | + |
| 30 | + def update(self, step): |
| 31 | + self.star1a.update(step) |
| 32 | + self.star1b.update(step) |
| 33 | + self.star1c.update(step) |
| 34 | + self.star2.update(step) |
| 35 | + |
| 36 | + def reset(self, numframes): |
| 37 | + super(RotatingStarScene, self).reset(numframes) |
| 38 | + self.time = 0 |
| 39 | + |
| 40 | + def getnext(self): |
| 41 | + pat1 = super(RotatingStarScene, self).getnext() |
| 42 | + hue = (0.875 + 0.5 * abs(0.5 - (float(self.time) / self.preferred_frames))) % 1.0 |
| 43 | + patbg = ctr.make_layout_pattern(lambda pos: hsl_color(hue, 1.0, max(0.0, 0.9 - (pos[0]**2+pos[1]**2))), style="centered") |
| 44 | + vec = self.getoccupancy() |
| 45 | + pat = [pat1[i] if vec[i] else patbg[i] for i in range(self.ctr.num_leds)] |
| 46 | + self.time += 1 |
| 47 | + return pat |
| 48 | + |
| 49 | +ctr = setup_control() |
| 50 | +ctr.adjust_layout_aspect(1.0) # How many times wider than high is the led installation? |
| 51 | +RotatingStarScene(ctr).launch_movie() |
0 commit comments