Exemple #1
0
def rain():
    wait = 0.08
    nSteps = 100
    p_new = 0.3
    global hue
    drops_old = []
    drops_new = []
    for i in range(nSteps):
        for drop in drops_old:  # update drop positions
            i = XYZ(drop[0], drop[1], drop[2])
            pixels[i] = (0, 0, 0)  # remove old dot
            if drop[2] > 0:
                drop[2] -= 1
                drops_new.append([drop[0], drop[1], drop[2]])  # update list
                i = XYZ(drop[0], drop[1], drop[2])
                color = fancy.CHSV(hue % 255)
                color = fancy.gamma_adjust(color, brightness=brightness)
                pixels[i] = color.pack()
        if random.random() > p_new:  # generate new drop
            x = random.randint(0, 3)
            y = random.randint(0, 3)
            drops_new.append([x, y, 3])
            i = XYZ(x, y, 3)
            color = fancy.CHSV(hue % 255)
            color = fancy.gamma_adjust(color, brightness=brightness)
            pixels[i] = color.pack()
        drops_old = drops_new.copy()
        drops_new.clear()
        pixels.show()
        time.sleep(wait)
        hue += 1
    def parse_color(self, input_string):
        """Parse color."""
        color = fancyled.CHSV(h=0.5, s=1.0, v=1.0)
        values = self.parse_values(input_string, float)
        print("color values", values)
        if len(values) == 1:
            # white
            color = fancyled.CHSV(
                h=0.5,
                s=0.0,
                v=values[0]
            )
        elif len(values) == 2:
            # full saturated color
            color = fancyled.CHSV(
                h=values[0],
                s=1.0,
                v=values[1]
            )
        elif len(values) == 3:
            # full color
            color = fancyled.CHSV(
                h=values[0],
                s=values[1],
                v=values[2]
            )

        return color
    def __init__(self, trellis, app):
        super().__init__()

        self.app = app

        self.center_strip = LightStrip(
            pixels=trellis.pixels,
            x_range=range(1, 7),
            y_range=range(1, 3),
            speed=0.1,
            colors=[
                fancy.CHSV(0, 0, 0.5),
                fancy.CHSV(0.5, 0.25, 0.25),
                fancy.CHSV(0.0, 0.25, 0.25),
                fancy.CHSV(0.2, 0.25, 0.25),
            ],
            palette_shift_speed=-4,
            value=12,
        )

        self.edge_strip = LightStrip(
            pixels=trellis.pixels,
            positions=EDGE_POSITIONS,
            speed=EDGE_STRIP_TIME * 0.6 / 20,
            colors=palettes.RED_KEY + palettes.BLUE_KEY + palettes.YELLOW_KEY,
            value=0,
        )
Exemple #4
0
    def __init__(self, trellis, app):
        super().__init__()

        self.app = app

        # Used to animate the box going away
        self.chain_bg_strip = LightStrip(
            pixels=trellis.pixels,
            x_range=range(1, 7),
            y_range=range(0, 4),
            colors=[fancy.CHSV(0, 0, 0.0)],
            brightness=0.8,
            speed=CHAIN_STRIP_SPEED,
            background_color=None,
            value=0,
        )

        self.chain_strip = LightStrip(
            pixels=trellis.pixels,
            x_range=range(1, 7),
            y_range=range(0, 4),
            colors=palettes.CHAINS,
            brightness=0.8,
            speed=CHAIN_STRIP_SPEED,
            value=-1,
            background_color=fancy.CHSV(4 / 6.0, 0.3, 0.2),
            highlight_color=fancy.CHSV(0, 0.8, 0.0),
            highlight_speed=0.25,
        )

        self.strips = [self.chain_strip, self.chain_bg_strip]
Exemple #5
0
def chase(color):
    scaled = fancy.CHSV(color.hue, color.saturation, color.value * scale())
    for i in range(0, neopixel_len):
        neopixel[i] = color.pack()
        for j in range(0, FADE):
            v = scaled.value / (j + 1)
            c = fancy.CHSV(scaled.hue, scaled.saturation, v)
            neopixel[i - j] = c.pack()
        neopixel[i - FADE] = 0
        neopixel.show()
Exemple #6
0
    def doTask(self):
        while self.running:
            speed = 5

            x2 = round(
                (scale(noise.noise3d(millis() * speed, 25355, 685)) >> 8) /
                25.6) - 1
            y2 = round(
                (scale(noise.noise3d(millis() * speed, 355, 11685)) >> 8) /
                25.6) - 1

            #x3 = round((scale(noise.noise3d(millis() * speed, 55355, 6685 )) >> 8) / 25.6) -1
            #y3 = round((scale(noise.noise3d(millis() * speed, 25355, 22685  )) >> 8) / 25.6) -1

            x1 = beatsin8(23 * speed, 0, 9)
            y1 = beatsin8(28 * speed, 0, 9)

            #logger.info(((x1, y1), (x2, y2), (x3, y3)))

            for y in range(0, 10):
                for x in range(0, 10):
                    dx = abs(x - x1)
                    dy = abs(y - y1)
                    dist = 2 * sqrt((dx * dx) + (dy * dy))

                    dx = abs(x - x2)
                    dy = abs(y - y2)
                    dist = dist + sqrt((dx * dx) + (dy * dy))

                    #dx = abs(x - x3)
                    #dy = abs(y - y3)
                    #dist = dist + sqrt((dx * dx) + (dy * dy))

                    logging.info(dist)
                    colour = 1000 / (dist + 1)
                    logging.info(colour)

                    if colour > 0 and colour < 100:
                        self.pixels[self.XY(x, y)] = toRGB(
                            fancy.CHSV(colour, 255, 255))
                    else:
                        self.pixels[self.XY(x, y)] = toRGB(
                            fancy.CHSV(0, 255, 255))

                    self.pixels[self.XY(x1,
                                        y1)] = toRGB(fancy.CHSV(255, 255, 255))
                    self.pixels[self.XY(x2,
                                        y2)] = toRGB(fancy.CHSV(255, 255, 255))
                    #self.pixels[self.XY(x3, y3)] = toRGB(fancy.CHSV(255, 255, 255))

            self.pixels.show()
            time.sleep(0.020)
Exemple #7
0
 def color(self):
     if self.type == CELL_PREDATOR:
         hunger = FRAME_COUNT - self.last_feed
         feed_bright = map_(hunger, PREDATOR_FEED_CYCLE-1, 0, BRIGHT_MIN, BRIGHT_MAX)
         feed_sat = map_(hunger, PREDATOR_FEED_CYCLE-1, 0, 0.80, 1.0)
         return fancy.CHSV(PREDATOR_HUE, feed_sat, feed_bright)
     elif self.type == CELL_PREY:
         age = FRAME_COUNT - self.birth
         age_bright = map_(age, 5, 0, BRIGHT_MIN, BRIGHT_MAX, clip=True)
         age_sat = map_(age, 10, 0, 0.80, 1.0, clip=True)
         return fancy.CHSV(PREY_HUE, age_sat, age_bright)
     else:
         # CELL_EMPTY and TOMB
         return fancy.CHSV(0,0,0)
Exemple #8
0
    def doTask(self):
        while self.running:
            scale_val = 1000
            for x in range(0, 10):
                for y in range(0, 10):
                    i = self.XY(x, y)
                    shift_x = 0
                    shift_y = 0

                    real_x = (self.x[i] + shift_x) * scale_val
                    real_y = (self.y[i] + shift_y) * scale_val

                    real_z = millis() * 20

                    noise_val = (scale(noise.noise3d(real_x, real_y, real_z)) +
                                 1) >> 8

                    index = noise_val * 3
                    bri = noise_val

                    colour = fancy.CHSV(index, 255, bri)
                    self.pixels[i] = toRGB(colour)

            self.pixels.show()
            time.sleep(1 / 10)
Exemple #9
0
def stepRainbow(pixels):
    global rainbowHue
    for led in range(Defines.NUM_LEDS):
        ledHue = int( (rainbowHue + (51*led)) % 256)
        pixels[led] = fancy.CHSV(ledHue, 255, 255).pack()
    pixels.show()
    rainbowHue = (rainbowHue + 3) % 256
    def handle_pixel_map_set(self, input_string):
        """Handle Pixel Set."""
        print("handle_pixel_map_set")
        col = 0
        row = 0

        seperator_pos = input_string.find(":")
        if seperator_pos == -1:
            values = self.parse_values(input_string[1:], int)
            color = fancyled.CHSV(h=0.5, s=1.0, v=1.0)
        else:
            values = self.parse_values(input_string[1:seperator_pos], int)
            color = self.parse_color(input_string[seperator_pos+1:])
        print("values", values)
        try:
            col, row = values
        except ValueError as e:
            print("Exception parsing 'col & row': ", e)

        print(
            "col:{:2} "
            "row:{:2} "
            "color:{} "
            "".format(
                col,
                row,
                color,
            )
        )
        self.animation.set_pixel_color(col, row, color)
        self.animation.pixels.show()
Exemple #11
0
    def enter(self, t):
        super().enter(t)

        p = self.app.current_player

        self.x_range = range(0, 6) if p.side == Player.SIDE_LEFT else range(
            7, 1, -1)
        self.y_range = range(0, 4)

        self.chain_strip.set_position(x_range=self.x_range,
                                      y_range=self.y_range)
        self.chain_bg_strip.set_position(x_range=self.x_range,
                                         y_range=self.y_range)

        self.chain_bg_strip.set_value(0)
        self.chain_strip.speed = CHAIN_STRIP_SPEED
        self.chain_strip.set_value(p.chains, t, now=True)
        self.chain_strip.dirty = True

        self.chain_strip.highlight_color = fancy.CHSV(0, 0.8, 0.0)
        self.chain_strip.highlight_speed = 0.25

        self.decrement_button = None

        for (x, y) in self.app.pressed:
            if y == 3 and p.chains > 0:
                self.decrement_button = x
                self.events.add_task("decrement_chain", 0.5, t)
    def render(self, t):
        if (self.value == self.rendered_value
                and (self.palette_shift_speed == None or self.value == 0)
                and not self.dirty and self.highlight == None):
            return

        if self.last_value_t == None or self.speed is None:
            time_delta = self.max_val
        else:
            time_diff = t - self.last_value_t
            time_delta = int(time_diff / self.speed)

        if self.value > self.last_value:
            self.rendered_value = min(self.value, self.last_value + time_delta)
        else:
            self.rendered_value = max(self.value, self.last_value - time_delta)

        highlight_mix = abs(0.5 -
                            ((t - self.highlight_t) % self.highlight_speed) /
                            (self.highlight_speed) *
                            1.5) if self.highlight_speed != None else 0

        if self.palette_shift_speed == None:
            palette_animation_offset = 0
        else:
            palette_t = t if self.last_value_t == None else t - self.last_value_t
            palette_animation_offset = (palette_t % self.palette_shift_speed
                                        ) / self.palette_shift_speed
        i = 1

        if self.color_from_end:
            palette_align = self.max_val - self.rendered_value
        else:
            palette_align = 0

        for (x, y) in self.positions:
            if i <= self.min_value:
                c = None
            elif i <= self.rendered_value:
                c_idx = (i - 1 + palette_align
                         ) * self.palette_step + palette_animation_offset
                c = fancy.palette_lookup(self.colors, c_idx)
            else:
                c = self.background_color

            if self.highlight != None and (x, y) in self.highlight:
                if c == None:
                    c = fancy.CHSV(0, 0, 0.0)

                c = fancy.mix(self.highlight_color, c, highlight_mix)

            if c != None:
                c_packed = pack(
                    fancy.gamma_adjust(c, brightness=self.brightness))
                self.pixels[x, y] = c_packed

            i = i + 1

        self.dirty = False
Exemple #13
0
def singleCursor():
    red = fancy.CHSV(0, 210, 127).pack()
    pos = 20
    for i in range(80):
        grid[pos] = red * (i % 2)
        led.value = not (i % 2)
        grid.show()
        time.sleep(0.08)
def rainbow_cycle__hsv():
    """Render Rainbow Cycle."""
    for offset in range(255):
        for pixel_index in range(num_pixels):
            rc_index = (pixel_index * 256 // num_pixels) + offset
            hue = rc_index & 255
            pixels[pixel_index] = fancyled.CHSV(hue, 255, 255).pack()
        pixels.show()
Exemple #15
0
def color_temp():
    color = fancy.CHSV(map_values(tempC,minimum_temp,maximum_temp,0.6,0.0),1.0,1.0)
    packed = color.pack()
    cp.pixels
    for i in range(10):
        cp.pixels[i]=packed
    cp.pixels.brightness = map_values(Lux,0,50,0.009,.25)
    cp.pixels.show()
    return
Exemple #16
0
 def render_static(self):
     """Render Static Color."""
     # pixels.fill(fancyled.CHSV(0.08, 1.0, 1.0))
     self.pixels.fill(
         fancyled.CHSV(
             self.config["animation"]["mode_settings"]["static"]["hue"],
             self.config["animation"]["mode_settings"]["static"]
             ["saturation"],
             self.config["animation"]["mode_settings"]["static"]["value"]))
Exemple #17
0
 def draw(self):
     for i in range(NLEDS):
         self.pixels[i][1] *= TAIL_BRIGHT_DECAY
         self.pixels[i][0] -= TAIL_HUE_SHIFT
     for p in self.particles:
         self.pixels[int(p.pos)] = [p.hue, 1.0]
     for (i, (hue, bright)) in enumerate(self.pixels):
         self.neos[i] = fancy.CHSV(hue, 1.0, bright).pack()
     self.neos.show()
Exemple #18
0
def nextBlue(c):
    hue = random.uniform(hue_min, hue_max)
    value = random.random()
    chaos = random.random()
    if (chaos >= 0.35):
        value /= 12.5
    value = neopixel_limits(value * scale())
    color = fancy.CHSV(hue, 1.0, value)
    return color
Exemple #19
0
def colorcycle():
    global hue
    for j in range(255):
        color = fancy.CHSV(hue % 255)
        color = fancy.gamma_adjust(color, brightness=brightness)
        pixels.fill(color.pack())
        pixels.show()
        # time.sleep(wait)
        hue += 2
    def effect_plasma_update(self):
        """Plasma."""
        for col_index in range(Matrix_col_count):
            for row_index in range(Matrix_row_count):
                # calculate plasma
                # mostly inspired by
                # https://www.bidouille.org/prog/plasma
                col = map_range(
                    col_index,
                    0, Matrix_col_count-1,
                    # 0, 1.0
                    -0.5, 0.5
                )
                row = map_range(
                    row_index,
                    0, Matrix_row_count-1,
                    # 0, 1.0
                    -0.5, 0.5
                )

                # moving rings
                cx = col + 0.5 * math.sin(self._offset / 5)
                cy = row + 0.5 * math.cos(self._offset / 3)
                value = math.sin(
                    math.sqrt(100 * (cx*cx + cy*cy) + 1)
                    + self._offset
                )
                # mapping
                contrast = map_range(
                    value,
                    -1, 1,
                    self._contrast_min, self._contrast_max
                )
                hue = map_range(
                    value,
                    -1, 1,
                    self._hue_min, self._hue_max
                )
                # map to color
                color = fancyled.CHSV(
                    hue,
                    v=contrast
                )
                # handle gamma and global brightness
                color_r, color_g, color_b = fancyled.gamma_adjust(
                    color,
                    brightness=self.brightness)
                pixels.set_pixel_float_value(
                    pmap.map_raw[row_index][col_index],
                    color_r, color_g, color_b
                )
        # update animation offset
        self._offset += self.stepsize
        if self._offset > (math.pi * 30):
            self._offset = 0
        # write data to chips
        pixels.show()
 def mode_5(self):
     """ hue cycle """
     for i in range(TrainLantern.NUM_LED):
         hue = self.unit_counter + (0.25 * i)
         if hue > 1:
             hue -= 1
         color = fancy.CHSV(hue)
         self.neopixels[i] = color.pack()
     self.neopixels.show()
     self.update_tick()
Exemple #22
0
def stepStrobe(pixels):
    global stepHue
    for pixel in range(Defines.NUM_LEDS):
        randomValue = random.randint(0, 256)
        color = fancy.CHSV(stepHue, 255, randomValue).pack()
        pixels[pixel] = color
    pixels.show()
    time.sleep(0.04)

    stepHue = (stepHue + 6) % 256
def hsv2rgb_spectrum(hue, sat, val):
    """This is named the same thing as FastLED's simpler HSV to RGB function
    (spectrum, vs rainbow) but implementation is a bit different for the
    sake of getting something running (adapted from some NeoPixel code).

    ACCEPTS: hue, saturation, value in range 0 to 255
    RETURNS: CRGB color.
    """

    return fancy.CRGB(fancy.CHSV(hue / 255, sat / 255, val / 255))
def everyOtherPulse(pixelInput, inputHue, ledSelect, numLeds=Defines.NUM_LEDS):
    ledSelect = ledSelect % 2
    for i in range(256):
        color = fancy.CHSV(inputHue, 255, i).pack()

        for pixelId in range(ledSelect, numLeds, 2):
            pixelInput[pixelId] = color

        pixelInput.show()

    for i in range(255, 0, -1):
        color = fancy.CHSV(inputHue, 255, i).pack()

        for pixelId in range(ledSelect, numLeds, 2):
            pixelInput[pixelId] = color

        pixelInput.show()
    pixelInput.fill(Defines.COLOR_CLEAR)
    pixelInput.show()
Exemple #25
0
def rainbow_cycle():
    global hue
    wait = 0.05
    for i in range(num_pixels):
        color = fancy.CHSV(hue % 255)
        color = fancy.gamma_adjust(color, brightness=brightness)
        pixels[i] = color.pack()
        pixels.show()
        time.sleep(wait)
        hue += 4
Exemple #26
0
def sparkle():
    white = fancy.CHSV(0, 0, 127).pack()
    pos = [0, 0, 0]
    for i in range(50):
        for j in range(len(pos)):
            pos[j] = random.randrange(GRIDLEN)
            grid[pos[j]] = white
        grid.show()
        for p in pos:
            grid[p] = 0
        grid.show()
 def mode_3(self):
     """ front full white, others alternate """
     self.tick_delay = 0.25
     self.unit_speed = 0.5
     for i in range(self.NUM_LED):
         if i == 3:
             color = TrainLantern.WHITE
         else:
             color = fancy.gamma_adjust(fancy.CHSV(self.unit_counter))
         self.neopixels[i] = color.pack()
     self.neopixels.show()
     self.update_tick()
Exemple #28
0
    def rainbow_update(self):
        """Rainbow."""
        for row_index in range(Matrix_row_count):
            # Load each pixel's color from the palette using an offset
            # color = fancyled.palette_lookup(
            #     palette,
            #     self.offset + row_index / Matrix_row_count
            #
            # )

            # results in 84,47ms
            # but has not as nice colors...
            # color_r, color_g, color_b = fancyled.CRGB(fancyled.CHSV(
            #     self.offset +
            #     # (row_index / Matrix_row_count),
            #     map_range(
            #         row_index,
            #         0, Matrix_row_count,
            #         0, 1.0
            #     ),
            #     v=0.1
            # ))

            # results in 99.41ms
            color = fancyled.CHSV(
                self.offset +
                # (row_index / Matrix_row_count),
                map_range(row_index, 0, Matrix_row_count, 0, 1.0),
                # v=0.05
            )
            color_r, color_g, color_b = fancyled.gamma_adjust(
                color, brightness=self.brightness)

            for col_index in range(Matrix_col_count):
                # pixels[pmap.map(col=col_index, row=row_index)] = color
                pixels.set_pixel_float_value(
                    # pmap.map(col=col_index, row=row_index),
                    pmap.map_raw[row_index][col_index],
                    color_r,
                    color_g,
                    color_b)
                # pixels.set_pixel_float_value(
                #     pmap.map_raw[row_index][col_index],
                #     0.1,
                #     0.5,
                #     0.5,
                # )
        pixels.show()

        self.offset += 0.01  # Bigger number = faster spin
        if self.offset >= 10:
            self.offset -= 10
Exemple #29
0
def fade():
    reps = 300 + random.randrange(GRIDLEN)
    hue = random.randrange(256)
    colors = [fancy.CHSV(hue, 255, v).pack() for v in range(0, 256, 32)]
    rcolors = colors[:]
    rcolors.reverse()
    colors = colors + rcolors
    for count in range(reps):
        pos = count % GRIDLEN
        for color in colors:
            grid[pos] = color
            pos -= 1
        grid.show()
Exemple #30
0
def frontback():
    global hue
    wait = 0.1
    for y in range(4):
        for x in range(4):
            for z in range(4):
                i = XYZ(x, y, z)
                color = fancy.CHSV(hue % 255)
                color = fancy.gamma_adjust(color, brightness=brightness)
                pixels[i] = color.pack()
                hue += 1
        pixels.show()
        time.sleep(wait)