Exemple #1
0
 def __init__(self, width, height, frame_delay=0.3):
     MatrixPixelEffect.__init__(self, width, height, 1, frame_delay)
     self.base_color = ColorRGB.random()
     self.new_base_color = ColorRGB.random()
     self.color = self.base_color
     self.color_conversion_progress = 0
     self.last_time = ''
     self.sprites = []
     self.sprites.append([[1, 1, 1], [1, 0, 1], [1, 0, 1], [1, 0, 1],
                          [1, 0, 1], [1, 0, 1], [1, 1, 1]])
     self.sprites.append([[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1],
                          [0, 0, 1], [0, 0, 1], [0, 0, 1]])
     self.sprites.append([[1, 1, 1], [0, 0, 1], [0, 0, 1], [1, 1, 1],
                          [1, 0, 0], [1, 0, 0], [1, 1, 1]])
     self.sprites.append([[1, 1, 1], [0, 0, 1], [0, 0, 1], [1, 1, 1],
                          [0, 0, 1], [0, 0, 1], [1, 1, 1]])
     self.sprites.append([[1, 0, 1], [1, 0, 1], [1, 0, 1], [1, 1, 1],
                          [0, 0, 1], [0, 0, 1], [0, 0, 1]])
     self.sprites.append([[1, 1, 1], [1, 0, 0], [1, 0, 0], [1, 1, 1],
                          [0, 0, 1], [0, 0, 1], [1, 1, 1]])
     self.sprites.append([[1, 1, 1], [1, 0, 0], [1, 0, 0], [1, 1, 1],
                          [1, 0, 1], [1, 0, 1], [1, 1, 1]])
     self.sprites.append([[1, 1, 1], [0, 0, 1], [0, 0, 1], [0, 1, 0],
                          [0, 1, 0], [1, 0, 0], [1, 0, 0]])
     self.sprites.append([[1, 1, 1], [1, 0, 1], [1, 0, 1], [1, 1, 1],
                          [1, 0, 1], [1, 0, 1], [1, 1, 1]])
     self.sprites.append([[1, 1, 1], [1, 0, 1], [1, 0, 1], [1, 1, 1],
                          [0, 0, 1], [0, 0, 1], [1, 1, 1]])
     self.sprites.append([[0, 0, 0], [0, 0, 0], [0, 1, 0], [0, 0, 0],
                          [0, 1, 0], [0, 0, 0], [0, 0, 0]])
    def play_frame(self):
        step_r = 0
        step_g = 0
        step_b = 0

        if self.current_step == self.steps - 30:
            self.bounce_direction = -1
        elif self.current_step == 0:
            self.bounce_direction = 1
            target_color = ColorRGB.random(2, self.drawer.intensity_min,
                                           self.drawer.intensity_max)

            step_r = target_color.r / float(self.steps)
            step_g = target_color.g / float(self.steps)
            step_b = target_color.b / float(self.steps)

        self.current_step += self.bounce_direction
        current_color = ColorRGB(step_r * self.current_step,
                                 step_g * self.current_step,
                                 step_b * self.current_step)

        for z in range(0, self.drawer.n_led - 1):
            self.drawer.set_color(z, current_color)

        self.drawer.show()
 def __init__(self, drawer, steps, cycles, frame_delay=0):
     PixelEffect.__init__(self, drawer, frame_delay)
     self.steps = steps
     self.cycles = cycles
     self.current_step = 0
     self.current_cycle = 0
     self.transition_cycle = -1
     self.target_color = ColorRGB.random(2, drawer.intensity_min,
                                         drawer.intensity_max)
     self.target_transition_color = ColorRGB.random(2, drawer.intensity_min,
                                                    drawer.intensity_max)
Exemple #4
0
    def play_frame(self, drawer):
        t = datetime.now().strftime("%H:%M:%S")
        if self.last_time == t:
            return

        self.last_time = t

        self.color_conversion_progress = self.color_conversion_progress + 0.01

        if self.color_conversion_progress > 1:
            self.base_color = self.new_base_color
            self.new_base_color = ColorRGB.random()
            self.color_conversion_progress = 0

        self.color = self.base_color.convert(self.new_base_color,
                                             self.color_conversion_progress)

        sec = datetime.now().second
        i = 0
        drawer.clear(False)
        print(t)

        for s in t:
            if s == ':':
                if sec % 2 == 0:
                    self.print_symbol(drawer, 10, i)
            else:
                self.print_symbol(drawer, int(s), i)
            i = i + 1

        drawer.show()
    def play_frame(self):
        if len(self.blinks) < self.max_leds:
            blink_color = ColorRGB(
                random.randint(0, self.drawer.intensity_max),
                random.randint(0, self.drawer.intensity_max),
                random.randint(0, self.drawer.intensity_max))

            blink = Blink(random.randint(0, self.drawer.n_led - 1),
                          blink_color, 10)
            self.blinks.append(blink)

        to_remove = []

        for blink in self.blinks:
            if not blink.next_step():
                to_remove.append(blink)

        for blink in to_remove:
            self.blinks.remove(blink)

        for z in range(0, self.drawer.n_led - 1):
            self.drawer.set_empty(z)

        for blink in self.blinks:
            self.drawer.set_color(blink.position, blink.current_color)

        self.drawer.show()
    def play_frame(self):
        if self.current_cycle >= self.cycles:
            if self.current_cycle == self.cycles:
                self.target_transition_color = ColorRGB.random(
                    2, self.drawer.intensity_min, self.drawer.intensity_max)

            self.transition_cycle = self.current_cycle - self.cycles

            if self.transition_cycle == self.drawer.n_led:
                self.transition_cycle = -1
                self.target_color = self.target_transition_color
                self.current_cycle = 0

        self.current_cycle += 1
        self.current_step += 1

        for z in self.drawer.pixels_indexes:
            m = abs(math.sin((z + self.current_step) / self.steps))

            if z <= self.transition_cycle:
                c = self.target_transition_color
            else:
                c = self.target_color

            m_c = c.multiply(m, True)

            self.drawer.set_color(z, m_c)

        self.drawer.show()
 def __init__(self, position):
     self.position = position
     self.was_born = datetime.now()
     self.altitude = 0
     self.heat = 255
     self.color = ColorRGB(255, 0, 0)
     self.speed = random.randint(0, 10) / 10
    def play_frame(self):
        self.drawer.clear(False)

        for x in range(self.width):
            if random.randint(0, 1000) > 885:
                self.sparks.append(Spark(x))

        for spark in self.sparks:
            spark.process()

        to_remove = []

        for spark in self.sparks:
            if spark.altitude >= self.height:
                to_remove.append(spark)
            else:
                self.draw_spark(spark)

        for x in range(self.width):
            position = super(FireEffect, self).translate_to_matrix_columns(
                x, self.height - 1)
            color = ColorRGB(255, 0, 0)
            self.drawer.set_color(position, color)

        for r in to_remove:
            self.sparks.remove(r)

        self.drawer.show()
 def __init__(self, position, target_color, steps=5):
     self.position = position
     self.steps = steps
     self.step = 0
     self.target_color = target_color
     self.incr_r = target_color.r / steps
     self.incr_g = target_color.g / steps
     self.incr_b = target_color.b / steps
     self.current_color = ColorRGB()
     self.is_fading = False
     self.is_done = False
    def play_frame(self):
        if self.current_cycle >= self.cycles:
            self.transition_cycle += 1
            if self.current_cycle - self.cycles == self.drawer.n_led:
                self.current_cycle = 0

        self.current_cycle += 1
        self.current_step += 1

        for z in self.drawer.pixels_indexes:
            pixel = colorsys.hsv_to_rgb((z + self.transition_cycle) * self.p,
                                        1, 1)

            m = abs(math.sin((z + self.current_step) / self.steps))
            c = ColorRGB(pixel[0] * self.drawer.intensity_max,
                         pixel[1] * self.drawer.intensity_max,
                         pixel[2] * self.drawer.intensity_max)
            m_c = c.multiply(m, True)
            self.drawer.set_color(z, m_c)

        self.drawer.show()
    def play_frame(self):
        drops_count = len(self.drops)
        if drops_count == 0:
            self.drops.append([
                0,
                ColorRGB.random(2, self.drawer.intensity_min,
                                self.drawer.intensity_max)
            ])
        elif self.drops[drops_count -
                        1][0] == self.tail_len + self.drops_distance:
            self.drops.append([
                0,
                ColorRGB.random(2, self.drawer.intensity_min,
                                self.drawer.intensity_max)
            ])

        delete_first = False

        for drop in self.drops:
            drop[0] = drop[0] + 1
            if drop[0] == self.drawer.n_led + self.tail_len:
                delete_first = True
            else:
                faid = self.tail_len
                for z in range(
                        drop[0] - self.tail_len - 1 - self.drops_distance,
                        drop[0]):
                    if 0 < z < self.drawer.n_led - 1:
                        if faid <= 0:
                            pixel = ColorRGB()
                        else:
                            pixel = drop[1].multiply(1 / float(faid))

                        self.drawer.set_color(z, pixel)
                        faid = faid - 1

        if delete_first:
            self.drops.remove(self.drops[0])

        self.drawer.show()
    def next_step(self):
        if self.is_fading:
            self.step -= 1
        else:
            self.step += 1

        if self.step == 0:
            return False

        if self.step > self.steps:
            self.is_fading = True

        self.current_color = ColorRGB(self.incr_r * (self.step - 1),
                                      self.incr_g * (self.step - 1),
                                      self.incr_b * (self.step - 1))

        return True
    def play_frame(self):
        if self.bounce_direction == 0:
            self.index = self.index + 1
            if self.index == self.drawer.n_led:
                self.bounce_direction = 1
                self.index = self.index - 1

        if self.bounce_direction == 1:
            self.index = self.index - 1
            if self.index == 0:
                self.bounce_direction = 0

        for i in range(0, self.drawer.n_led - 1):
            if i == self.index:
                self.drawer.set_color(
                    i,
                    ColorRGB.CHSV(self.drawer.n_led, i,
                                  self.drawer.intensity_max, 1))
            else:
                self.drawer.set_empty(i)

        self.drawer.show()
Exemple #14
0
 def __init__(self):
     self.altitude = 0
     self.speed = 1
     self.color = ColorRGB.random(3, 100, 200)
     self.radius = 3
     self.tail_pixels = []
Exemple #15
0
 def calibrate_color(self, color):
     return ColorRGB(self.calibration_table[color.r],
                     self.calibration_table[color.g],
                     self.calibration_table[color.b])
 def draw_spark(self, spark):
     for y in range(0, int(spark.altitude)):
         position = super(FireEffect, self).translate_to_matrix_columns(
             spark.position, self.height - 1 - y)
         color = ColorRGB(255 / ((y + 1) * 1), 0, 0)
         self.drawer.set_color(position, color)