|
| 1 | +""" |
| 2 | +Day 20 - Caleidoscope |
| 3 | +
|
| 4 | +Slowly changing symmetric pattern of random colors. |
| 5 | +Again, looks best on a 2D layout, and with correctly adjusted aspect: |
| 6 | +Change the number in the call to adjust_layout_aspect in the next to |
| 7 | +last line of the code below. |
| 8 | +""" |
| 9 | + |
| 10 | +from xled_plus.samples.sample_setup import * |
| 11 | + |
| 12 | +class SoftCaleidoScene(MovingShapesScene): |
| 13 | + def __init__(self, ctr, sym, colfunc): |
| 14 | + super(SoftCaleidoScene, self).__init__(ctr) |
| 15 | + self.freq = 0.6 |
| 16 | + self.symang = m.pi / sym |
| 17 | + self.colfunc = colfunc |
| 18 | + self.bgpat = ctr.make_solid_pattern(hsl_color(0,0,-0.5)) |
| 19 | + self.horizon = 320 |
| 20 | + self.preferred_frames = 640 |
| 21 | + |
| 22 | + def create(self): |
| 23 | + col = self.colfunc(self.time) |
| 24 | + speed = m.exp((random() - 0.5) * 1.1) / self.preferred_fps * 0.08 |
| 25 | + rad = 0.1 + random() * 0.3 |
| 26 | + angle = random() * 2 * m.pi |
| 27 | + offset = random() - 0.5 |
| 28 | + vec = (m.sin(angle), m.cos(angle)) |
| 29 | + cent = (-vec[0] * 1.5 + vec[1] * offset, -vec[1] * 1.5 - vec[0] * offset + 0.5) |
| 30 | + vel = (vec[0] * speed, vec[1] * speed) |
| 31 | + nstep = int(2.0 / speed) |
| 32 | + #shape = Blob(cent, rad, col) |
| 33 | + shape = Ellipse(cent, 0.0, rad, rad, col) |
| 34 | + shape.set_depth(0.0) |
| 35 | + shape.set_speed(vel[0], vel[1]) |
| 36 | + shape.duetime = self.time + nstep |
| 37 | + return shape |
| 38 | + |
| 39 | + def get_color(self, coord, ind): |
| 40 | + r = m.sqrt(coord[0] ** 2 + coord[1] ** 2) |
| 41 | + a = m.atan2(coord[1], coord[0]) |
| 42 | + a = abs((a % (2 * self.symang)) - self.symang) |
| 43 | + return super(SoftCaleidoScene, self).get_color((m.sin(a) * r, m.cos(a) * r), ind) |
| 44 | + |
| 45 | + def getnext(self): |
| 46 | + pat1 = super(SoftCaleidoScene, self).getnext() |
| 47 | + vec = self.getoccupancy() |
| 48 | + pat = [pat1[i] if vec[i] else self.bgpat[i] for i in range(self.ctr.num_leds)] |
| 49 | + return pat |
| 50 | + |
| 51 | +ctr = setup_control() |
| 52 | +ctr.adjust_layout_aspect(1.0) # How many times wider than high is the led installation? |
| 53 | +SoftCaleidoScene(ctr, 3, random_hsl_color_func(light=0.0)).launch_movie() |
0 commit comments