Esempio n. 1
0
    def step(self, amt):
        if self._dir:
            s = 255 - self._step
        else:
            s = self._step

        pos = 0
        cX, cY = self._center
        for x in range(self.width):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, x, 0, c)
            pos += 1

        for y in range(self.height):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, self.width-1, y, c)
            pos += 1

        for x in range(self.width-1, -1, -1):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, x, self.height-1, c)
            pos += 1

        for y in range(self.height-1, -1, -1):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, 0, y, c)
            pos += 1

        self._step += amt
        if(self._step >= 255):
            self._step = 0
            cX += 1
	    if cX >= self.width:
	        cX = 1
	    self._center = (cX, cY)
Esempio n. 2
0
    def step(self, amt):
        if self._dir:
            s = 255 - self._step
        else:
            s = self._step

        pos = 0
        cX, cY = self._center
        for x in range(self.width):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, x, 0, c)
            pos += 1

        for y in range(self.height):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, self.width - 1, y, c)
            pos += 1

        for x in range(self.width - 1, -1, -1):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, x, self.height - 1, c)
            pos += 1

        for y in range(self.height - 1, -1, -1):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, 0, y, c)
            pos += 1

        self._step += amt
        if (self._step >= 255):
            self._step = 0
            cX += 1
            if cX >= self.width:
                cX = 1
            self._center = (cX, cY)
Esempio n. 3
0
 def drawPipes(self):
     for p in self._pipes:
         self._led.drawLine(p[0],
                            0,
                            p[0],
                            p[1],
                            colorFunc=lambda pos: colors.hue_helper(
                                p[1] - pos, p[1], self._speedStep * 2))
         self._led.drawLine(p[0],
                            p[1] + self.height / 3,
                            p[0],
                            self.height - 1,
                            colorFunc=lambda pos: colors.hue_helper(
                                pos, self.height - p[1] + self.height / 3,
                                self._speedStep * 2))
 def __init__(self, led, minFrequency, maxFrequency):
     super(BassPulse, self).__init__(led)
     self.rec = Recorder()
     self.rec.setup()
     self.rec.continuousStart()
     self.colors = [colors.hue_helper(y, self.height, 0) for y in range(self.height)]
     self.frequency_limits = self.rec.calculate_channel_frequency(minFrequency, maxFrequency, self.width)
Esempio n. 5
0
 def __init__(self, recorder, led, minFrequency, maxFrequency, sensitivity):
     super(BaseEQAnim, self).__init__(led)
     self.rec = recorder
     self.rec.start()
     self.colors = [colors.hue_helper(y, self.height, 0) for y in range(self.height)]
     self.frequency_limits = self.rec.calculate_channel_frequency(minFrequency, maxFrequency, self.width)
     self.sensitivity = sensitivity
Esempio n. 6
0
 def __init__(self, led):
     super(EQ, self).__init__(led)
     self.rec = Recorder()
     self.rec.setup()
     self.rec.continuousStart()
     self.colors = [
         colors.hue_helper(y, self.height, 0) for y in range(self.height)
     ]
Esempio n. 7
0
 def drawBody(self):
     l = len(self._body)
     i = 0
     for b in self._body:
         c = colors.hue_helper(i, l, 1)
         x,y = b
         self._led.set(x, y, c)
         i += 1
Esempio n. 8
0
 def drawBody(self):
     body_len = len(self._body)
     i = 0
     for b in self._body:
         c = colors.hue_helper(i, body_len, 1)
         x, y = b
         self.layout.set(x, y, c)
         i += 1
 def drawBody(self):
     l = len(self._body)
     i = 0
     for b in self._body:
         c = colors.hue_helper(i, l, 1)
         x, y = b
         self._led.set(x, y, c)
         i += 1
Esempio n. 10
0
    def step(self, amt = 1):
        for i in range(self._size):
            c = colors.hue_helper(i, self._size, self._step)
            self._led.set(self._start + i, c)

        self._step += amt
        overflow = self._step - 256
        if overflow >= 0:
            self._step = overflow
Esempio n. 11
0
    def step(self, amt=8):
        for i in range(self.ringCount):
            c = colors.hue_helper(i, int(self.ringCount * self.spread),
                                  self._step)
            self._led.fillRing(i, c)

        self._step += amt
        if (self._step >= 255):
            self._step = 0
Esempio n. 12
0
 def __init__(self, recorder, led, minFrequency, maxFrequency, sensitivity):
     super(BaseEQAnim, self).__init__(led)
     self.rec = recorder
     self.rec.start()
     self.colors = [
         colors.hue_helper(y, self.height, 0) for y in range(self.height)
     ]
     self.frequency_limits = self.rec.calculate_channel_frequency(
         minFrequency, maxFrequency, self.width)
     self.sensitivity = sensitivity
Esempio n. 13
0
    def step(self, amt=1):
        for i in range(self._size):
            #color = (i * (384 / self._size) + self._step) % 384
            #c = colors.wheel_helper(i, self._size, self._step)
            c = colors.hue_helper(i, self._size, self._step)
            self._led.set(self._start + i, c)

        self._step += amt
        overflow = self._step - 256
        if overflow >= 0:
            self._step = overflow
Esempio n. 14
0
    def step(self, amt = 1):
        for i in range(self._size):
            #color = (i * (384 / self._size) + self._step) % 384
            #c = colors.wheel_helper(i, self._size, self._step)
            c = colors.hue_helper(i, self._size, self._step)
            self._led.set(self._start + i, c)

        self._step += amt
        overflow = self._step - 256
        if overflow >= 0:
            self._step = overflow
    def step(self, amt):
        self._led.setTexture([[colors.hue_helper(y, self.height, self._step*2)]*self.width for y in range(self.height)])
        self._led.all_off()
        t = time.localtime()
        hrs = str(t.tm_hour).zfill(2)
        mins = str(t.tm_min).zfill(2)
        sec = str(t.tm_sec).zfill(2)
        self._led.drawText(hrs, x = 2, y = 2, size = 2)
        self._led.drawText(mins, x = 2, y = 18, size = 2)
        self._led.drawText(sec, x = 2, y = 34, size = 2)

        self._step += amt
Esempio n. 16
0
    def step(self, amt):
        self._led.setTexture([[colors.hue_helper(y, self.height, self._step*2)]*self.width for y in range(self.height)])
        self._led.all_off()
        t = time.localtime()
        hrs = str(t.tm_hour).zfill(2)
        mins = str(t.tm_min).zfill(2)
        sec = str(t.tm_sec).zfill(2)
        self._led.drawText(hrs, x = 2, y = 2, size = 2)
        self._led.drawText(mins, x = 2, y = 18, size = 2)
        self._led.drawText(sec, x = 2, y = 34, size = 2)

        self._step += amt
        self._led.setTexture(tex=None)
Esempio n. 17
0
    def step(self, amt):
        if self._dir:
            s = 255 - self._step
        else:
            s = self._step

        pos = 0
        cX, cY = self._center
        for x in range(self.width):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, x, 0, c)
            pos += 1

        for y in range(self.height):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, self.width-1, y, c)
            pos += 1

        for x in range(self.width-1, -1, -1):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, x, self.height-1, c)
            pos += 1

        for y in range(self.height-1, -1, -1):
            c = colors.hue_helper(pos, self._len, s)
            self._led.drawLine(cX, cY, 0, y, c)
            pos += 1
	    
	# this modifies the _let.buffer directly
	self._rotatebuffer()

        self._step += amt
        if(self._step >= 255):
            self._step = 0
	    self._shiftamt += 1
            if self._shiftamt > 15:
	        self._shiftamt = 0
    def step(self, amt):
        self._led.setTexture([[colors.hue_helper(self.height-y, self.height, self._step*2)]*self.width for y in range(self.height)])
        self._led.all_off()
        hrs, mins, sec = self.getRemaining()
        if(hrs+mins+sec==0):
            self.animComplete = True

        hrs = str(hrs).zfill(2)
        mins = str(mins).zfill(2)
        sec = str(sec).zfill(2)
        self._led.drawText(hrs, x = 2, y = 2, size = 2)
        self._led.drawText(mins, x = 2, y = 18, size = 2)
        self._led.drawText(sec, x = 2, y = 34, size = 2)

        self._step += amt
Esempio n. 19
0
    def step(self, amt=8):
        if self._dir:
            s = 255 - self._step
        else:
            s = self._step

        # this respects master brightness but is slower
        for y in range(self._led.height):
            for x in range(self._led.width):
                c = colors.hue_helper(self._vector[y][x], self._led.height, s)
                self._led.set(x, y, c)

        self._step += amt
        if (self._step >= 255):
            self._step = 0
Esempio n. 20
0
    def step(self, amt=8):
        if self._dir:
            s = 255 - self._step
        else:
            s = self._step

        # this respects master brightness but is slower
        for z in range(self.z):
            for y in range(self.y):
                for x in range(self.x):
                    c = colors.hue_helper(self._vector[x][y][z], self.y, s)
                    self.layout.set(x, y, z, c)

        self._step += amt
        if (self._step >= 255):
            self._step = 0
Esempio n. 21
0
    def step(self, amt = 1):
        for i in range(self._size):
            c = colors.hue_helper(i, self._size, self._step)
            d = self.decibels
            d -= 68
            d = max(0, d)
            percentage = d / 20
            percentage = min(percentage, 1.0)
            brightness = int(round(percentage * 255))
	    final = min(max(brightness, 25), 175)
            self._led.set(self._start + i, colors.color_scale(c, final))

        self._step += amt
        overflow = self._step - 256
        if overflow >= 0:
            self._step = overflow
    def step(self, amt):
        self.layout.setTexture(
            [[colors.hue_helper(y, self.height, self._step * 2)] * self.width
             for y in range(self.height)])
        self.layout.all_off()
        t = time.localtime()
        hrs = str(t.tm_hour).zfill(2)
        mins = str(t.tm_min).zfill(2)
        secs = str(t.tm_sec).zfill(2)
        self.layout.drawText(hrs, x=0, y=0, font_scale=2)
        self.layout.drawText(mins, x=0, y=18, font_scale=2)
        self.layout.drawText(secs[0], x=24, y=8)
        self.layout.drawText(secs[1], x=24, y=17)

        self._step += amt
        self.layout.setTexture(tex=None)
Esempio n. 23
0
    def step(self, amt = 1):
        for i in range(self._size):
            c = colors.hue_helper(i, self._size, self._step)
            decibels = 20 * math.log10(self.volume)
            decibels -= 68
            decibels = max(0, decibels)
            percentage = decibels / 20
            percentage = min(percentage, 1.0)
            brightness = int(round(percentage * 255))
            self._led.setMasterBrightness(brightness)
            self._led.set(self._start + i, c)

        self._step += amt
        overflow = self._step - 256
        if overflow >= 0:
            self._step = overflow
Esempio n. 24
0
    def step(self, amt):
        self._led.setTexture([[colors.hue_helper(
            self.height - y, self.height, self._step * 2)] * self.width for y in range(self.height)])
        self._led.all_off()
        hrs, mins, sec = self.getRemaining()
        if(hrs + mins + sec == 0):
            self.animComplete = True

        hrs = str(hrs).zfill(2)
        mins = str(mins).zfill(2)
        sec = str(sec).zfill(2)
        self._led.drawText(hrs, x=2, y=2, font_scale=2)
        self._led.drawText(mins, x=2, y=18, font_scale=2)
        self._led.drawText(sec, x=2, y=34, font_scale=2)

        self._step += amt
        self._led.setTexture(tex=None)
    def step(self, amt=1):
        if self._dir:
            s = 255 - self._step
        else:
            s = self._step

        offset_total = 0
        for z in range(self.z):
            for i in range(self.spiral_len):
                c = colors.hue_helper(i, self.spiral_len, s + offset_total)
                x, y = self.spiral[i]
                self.layout.set(x, y, z, c)
            offset_total += self.offset

        self._step += amt
        if (self._step >= 255):
            self._step = 0
    def step(self, amt=1):
        for i in range(self._size):
            chunk_size = MidiTransform.remap_cc_value(self.count_control, 1,
                                                      20)
            chunks = self._size / chunk_size
            color = bp_colors.hue_helper(i, chunks, self._step)
            brightness_level = MidiTransform.remap_cc_value(
                self.brightness_control, 0, 256)
            color = bp_colors.color_scale(color, brightness_level)
            self.layout.set(self._start + i, color)

        self._step += amt
        overflow = self._step - 256
        if overflow >= 0:
            self._step = overflow

        delay_time = MidiTransform.remap_cc_value(self.delay_control, 0, 1)
        time.sleep(delay_time)
Esempio n. 27
0
 def __init__(self, led, xleft=None, xright=None, minFrequency=50, maxFrequency=2000):
     super(EQ, self).__init__(led)
     if xleft is None:
         self.xleft = 0
     else:
         self.xleft = xleft
     if xright is None:
         self.xright = self.width
     else:
         self.xright = xright
         
     self.rec = Recorder()
     self.rec.setup()
     self.rec.continuousStart()
     self.colors = [colors.hue_helper(y, self.height, 200) for y in range(self.height)]
     #self.colors = [colors.hue_helper(x, self.width, 0) for x in range(self.width)]
     self.frequency_limits = self.rec.calculate_channel_frequency(minFrequency, maxFrequency, self.xright - self.xleft)
     self.minlevels = 100
     self.maxlevels = -100
Esempio n. 28
0
    def run(self):
        try:
            color_position = 0
            while True:
                # Read and write the data
                data = self.io_manager.read()
                self.io_manager.write(data)

                if len(data):
                    brightness = self.audio_processor.get_visualizer_array(
                        data, self.io_manager.chunk, self.io_manager.rate)
                    color_arr = colors.hue_helper(color_position, 20, 2)

                    for i in np.arange(0, 20):
                        self.matrix.drawLine(x0=0,
                                             y0=i,
                                             x1=brightness[i]**7,
                                             y1=i,
                                             color=color_arr[i])
                        self.matrix.drawLine(x0=brightness[i]**7,
                                             y0=i,
                                             x1=7,
                                             y1=i,
                                             color=(0, 0, 0))
                    self.matrix.update()

                    if color_position >= 255:
                        color_position = 0
                    else:
                        color_position += 1
                else:
                    # If we didn't get any data, blank out the screen so residual data is not left there.
                    self.matrix.fill((0, 0, 0), 0, -1)

                    if not self.io_manager.is_input_alive():
                        self.io_manager.start_shairport_sync()

        except KeyboardInterrupt:
            print("Goodbye :)")
Esempio n. 29
0
    def step(self, amt = 8):
        if self._dir:
            s = 255 - self._step
        else:
            s = self._step

        h = self._led.height
        w = self._led.width

        #this ignores master brightness in the interest of speed
        # buf = [colors.hue_helper(self._vector[y][x], h, s) for y in range(h) for x in range(w)]
        # buf = [i for sub in buf for i in sub]
        # self._led.setBuffer(buf)

        #this respects master brightness but is slower
        for y in range(self._led.height):
           for x in range(self._led.width):
               c = colors.hue_helper(self._vector[y][x], self._led.height, s)
               self._led.set(x, y, c)

        self._step += amt
        if(self._step >= 255):
            self._step = 0
Esempio n. 30
0
    def step(self, amt=8):
        if self._dir:
            s = 255 - self._step
        else:
            s = self._step

        h = self._led.height
        w = self._led.width

        #this ignores master brightness in the interest of speed
        # buf = [colors.hue_helper(self._vector[y][x], h, s) for y in range(h) for x in range(w)]
        # buf = [i for sub in buf for i in sub]
        # self._led.setBuffer(buf)

        #this respects master brightness but is slower
        for y in range(self._led.height):
            for x in range(self._led.width):
                c = colors.hue_helper(self._vector[y][x], self._led.height, s)
                self._led.set(x, y, c)

        self._step += amt
        if (self._step >= 255):
            self._step = 0
Esempio n. 31
0
    def step(self, amt = 1):
        self._color = colors.hue_helper(0, self._size, self._step)
        #self._color = colors.hue2rgb_rainbow((self._step * (256 / self._size)) % 256)

        super(LarsonRainbow, self).step(amt)
    def step(self, amt=1):
        self._color = colors.hue_helper(0, self._size, self._step)

        super(LarsonRainbow, self).step(amt)
Esempio n. 33
0
 def drawPipes(self):
     for p in self._pipes:
         self._led.drawLine(p[0], 0, p[0], p[1], colorFunc=lambda pos: colors.hue_helper(p[1]-pos, p[1], self._speedStep*2))
         self._led.drawLine(p[0], p[1]+self.height/3, p[0], self.height-1, colorFunc=lambda pos: colors.hue_helper(pos, self.height-p[1]+self.height/3, self._speedStep*2))
Esempio n. 34
0
 def init(self):
     self.items = [colors.hue_helper(x, self._size, 0) for x in range(self._size)]
     random.shuffle(self.items)
Esempio n. 35
0
 def __init__(self, led):
     super(EQ, self).__init__(led)
     self.rec = Recorder()
     self.rec.setup()
     self.rec.continuousStart()
     self.colors = [colors.hue_helper(y, self.height, 0) for y in range(self.height)]
Esempio n. 36
0
    def write_matrix(self, pin_list):
        if self.update_skip != 0:
            self.update_skip -= 1
            if self.update_skip >= 0:
                return

        if len(self.led_config.matrix_pattern_type) == 1:
            self.p_type = self.led_config.matrix_pattern_type[0]
        else:
            for pin in range(len(pin_list)):
                self.beats += pin_list[pin] * (len(pin_list) /
                                               (pin + 1)) * 0.002
            if self.beats > self.led_config.beats and self._bstep == 0:
                self._bstep = 0
                self.beats = 0
                self.p_num += 1
                if self.p_num >= len(self.led_config.matrix_pattern_type):
                    self.p_num = 0
            self.p_type = self.led_config.matrix_pattern_type[self.p_num]

        self.mmcm(self.p_type)
        self.led.all_off()

        h = self.led_config.matrix_height
        w = self.led_config.matrix_width

        if self.p_type == 'SBARS':
            for y in range(h):
                y_ind = int((float(len(pin_list)) / h) * y)
                for x_cord in range(int(pin_list[y_ind] * float(w))):
                    rgb = color_map[int(255.0 * float(x_cord) / float(w))]
                    self.led.set(y_ind, x_cord, rgb)

        if self.p_type == 'MBARS':
            norm_arr = [int(x * 255) for x in pin_list]
            self.drops.append(norm_arr)
            for y_cord in range(w):
                for x in range(h):
                    x_ind = int((float(len(pin_list)) / h) * x)
                    if self.drops[y_cord][x_ind] > 64:
                        rgb = scale(color_map[255 - self.drops[y_cord][x_ind]],
                                    int(self.drops[y_cord][x_ind] * 0.5))
                        self.led.set(x, w - 1 - y_cord, rgb)
            del self.drops[0]

        elif self.p_type == 'IMAGE':
            complete_image = self.base_image
            for pin in range(len(pin_list)):
                if pin_list[pin] > 0.55:
                    complete_image = ImageChops.add_modulo(
                        complete_image,
                        ImageEnhance.Brightness(self.images[pin]).enhance(
                            pin_list[pin]))

            image.showImage(
                self.led, "",
                ImageEnhance.Brightness(complete_image).enhance(
                    self.max_brightness * 0.5))

        elif self.p_type == 'PINWHEEL':
            amt = 0

            for pin in range(len(pin_list)):
                amt += pin_list[pin] * (len(pin_list) / (pin + 1)) * 0.25
            amt = int(amt)

            pos = 0
            for x in range(h):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self.midxa, self.midya, x, 0, c)
                pos += 1

            for y in range(w):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self.midxb, self.midyb, h - 1, y, c)
                pos += 1

            for x in range(h - 1, -1, -1):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self.midxb, self.midyb, x, w - 1, c)
                pos += 1

            for y in range(w - 1, -1, -1):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self.midxa, self.midya, 0, y, c)
                pos += 1

            self._step += amt
            if (self._step >= 255):
                self._step = 0

        elif self.p_type == 'CBARS':
            for y in range(w):
                level = pin_list[int(
                    (y / float(w)) * float(self.led_config.led_channel_count))]
                brightness = int(255 * level)
                rgb = scale(color_map[brightness], brightness)
                mlvl = int(level * self.midxa)
                self.led.drawLine(self.midxa - mlvl, y, self.midxb + mlvl, y,
                                  rgb)

        elif self.p_type == 'CIRCLES':
            for pin in range(self.led_config.led_channel_count):
                rgb = self.rgb[pin]
                c = scale(rgb, int((pin_list[pin]) * 255))
                self.led.drawCircle(
                    self.midxa, self.midyb,
                    int(pin * ((w / 2) / self.led_config.led_channel_count)),
                    c)

        elif self.p_type == 'BANNER':
            rgb = self.rgb[list(pin_list).index(max(list(pin_list)))]
            # fit 4 characters into width
            text = self.led_config.banner_text[int(self._bstep
                                                   ):int(self._bstep) + 4]
            # fonts : 6x4 8x6 16x8
            self.led.drawText(text,
                              x=1,
                              y=1,
                              color=rgb,
                              bg=colors.Off,
                              font='6x4',
                              font_scale=1)
            # scroll speed 0.1
            self._bstep += 0.1
            # scroll with beats
            #            self._bstep += (pin_list[0] * 0.2) + (pin_list[1] * 0.1)
            if (self._bstep >= len(self.led_config.banner_text)):
                self._bstep = 0

        self.led.push_to_driver()
        self.update_skip = self.skip
Esempio n. 37
0
    def step(self, amt=1):
        if (
            (self.levelUp or self.gameover or self.win)
            and (self._lastKeys != self._keys)
            and any(v == True for v in self._keys.itervalues())
        ):
            self.doStart = True
        if self.doStart:
            if not any(v == True for v in self._keys.itervalues()):
                if self.levelUp:
                    self.clearLevelUp()
                elif self.gameover or self.win:
                    self.start_game()
            else:
                return

        if not self.doStart:
            self.handleKeys()

        self._led.all_off()
        if self.gameover:
            self._led.all_off()
            self._led.drawText("GAME", self.width / 2 - 11, self.height / 2 - 8, color=colors.Green)
            self._led.drawText("OVER", self.width / 2 - 11, self.height / 2 + 1, color=colors.Green)
            s = "{}".format(self.score)
            self._led.drawText(
                s, self.width / 2 - (len(s) * 4) / 2 + 1, self.height / 2 + 9, size=0, color=colors.Green
            )
        elif self.win:
            for x in range(self.width):
                c = colors.hue_helper(self.width - x, self.width, self._speedStep * 2)
                self._led.drawLine(self.width / 2, self.height / 2, x, 0, c)
                self._led.drawLine(self.width / 2, self.height / 2, self.width - 1 - x, self.height - 1, c)
            for y in range(self.height):
                c = colors.hue_helper(y, self.height, self._speedStep * 2)
                self._led.drawLine(self.width / 2, self.height / 2, 0, y, c)
                self._led.drawLine(self.width / 2, self.height / 2, self.width - 1, self.height - 1 - y, c)

            self._led.drawText("YOU", self.width / 2 - 9, self.height / 2 - 8, color=colors.Black, bg=None)
            self._led.drawText("WIN!", self.width / 2 - 10, self.height / 2 + 1, color=colors.Black, bg=None)
        else:
            if self.paused:
                self._led.all_off()
                if self.levelUp:
                    self._led.drawText("LVL", self.width / 2 - 8, self.height / 2 - 8, color=colors.Green)
                    l = "{}".format(self.level)
                    self._led.drawText(
                        l, self.width / 2 - (len(l) * 6) / 2 + 1, self.height / 2 + 1, color=colors.Green
                    )
                else:
                    x = self.width / 2 - 2
                    y = 1
                    self._led.drawText("P", x, y + 0, color=colors.White)
                    self._led.drawText("A", x, y + 8, color=colors.White)
                    self._led.drawText("U", x, y + 16, color=colors.White)
                    self._led.drawText("S", x, y + 24, color=colors.White)
                    self._led.drawText("E", x, y + 32, color=colors.White)
                    self._led.drawText("D", x, y + 40, color=colors.White)

            else:
                self.disp_msg("{}".format(self.score), 1, 1)

                lines_left = self.level * self.lines_per_level - self.lines
                for l in range(lines_left):
                    self._led.set(0, self.height - 1 - l * 2, colors.Red)

                # draw rainbow border
                self._led.drawLine(
                    2, 8, cols + 3, 8, colorFunc=lambda pos: colors.hue_helper(pos, cols + 2, self._speedStep * 2)
                )
                self._led.drawLine(
                    2,
                    self.height - 1,
                    cols + 3,
                    self.height - 1,
                    colorFunc=lambda pos: colors.hue_helper(cols + 2 - pos, cols + 2, self._speedStep * 2),
                )
                self._led.drawLine(
                    2,
                    9,
                    2,
                    self.height - 2,
                    colorFunc=lambda pos: colors.hue_helper(rows + 2 - pos, rows, self._speedStep * 2),
                )
                self._led.drawLine(
                    cols + 3,
                    9,
                    cols + 3,
                    self.height - 2,
                    colorFunc=lambda pos: colors.hue_helper(pos, rows, self._speedStep * 2),
                )

                # draw current board state
                self.draw_matrix(self.board, (3, 9))
                # draw current block
                self.draw_matrix(self.stone, (self.stone_x + 3, self.stone_y + 9))
                # draw next block
                self.draw_matrix(self.next_stone, (self.width - 6, 1))
                # drop block
                if self.checkSpeed("drop"):
                    self.drop(False)

        self._step += amt
Esempio n. 38
0
    def step(self, amt=1):
        if (self.levelUp or self.gameover
                or self.win) and (self._lastKeys != self._keys) and any(
                    v is True for v in self._keys.itervalues()):
            self.doStart = True
        if self.doStart:
            if not any(v is True for v in self._keys.itervalues()):
                if self.levelUp:
                    self.clearLevelUp()
                elif self.gameover or self.win:
                    self.start_game()
            else:
                return

        if not self.doStart:
            self.handleKeys()

        self.layout.all_off()
        if self.gameover:
            self.layout.all_off()
            self.layout.drawText("GAME",
                                 self.width // 2 - 11,
                                 self.height // 2 - 8,
                                 color=colors.Green)
            self.layout.drawText("OVER",
                                 self.width // 2 - 11,
                                 self.height // 2 + 1,
                                 color=colors.Green)
            s = "{}".format(self.score)
            self.layout.drawText(s,
                                 self.width // 2 - (len(s) * 4) // 2 + 1,
                                 self.height // 2 + 9,
                                 font_scale=1,
                                 font='6x4',
                                 color=colors.Green)
        elif self.win:
            for x in range(self.width):
                c = colors.hue_helper(self.width - x, self.width,
                                      self._speedStep * 2)
                self.layout.drawLine(self.width // 2, self.height // 2, x, 0,
                                     c)
                self.layout.drawLine(self.width // 2, self.height // 2,
                                     self.width - 1 - x, self.height - 1, c)
            for y in range(self.height):
                c = colors.hue_helper(y, self.height, self._speedStep * 2)
                self.layout.drawLine(self.width // 2, self.height // 2, 0, y,
                                     c)
                self.layout.drawLine(self.width // 2, self.height // 2,
                                     self.width - 1, self.height - 1 - y, c)

            self.layout.drawText("YOU",
                                 self.width // 2 - 9,
                                 self.height // 2 - 8,
                                 color=colors.Black,
                                 bg=None)
            self.layout.drawText("WIN!",
                                 self.width // 2 - 10,
                                 self.height // 2 + 1,
                                 color=colors.Black,
                                 bg=None)
        else:
            if self.paused:
                self.layout.all_off()
                if self.levelUp:
                    self.layout.drawText("LVL",
                                         self.width // 2 - 8,
                                         self.height // 2 - 8,
                                         color=colors.Green)
                    l = "{}".format(self.level)
                    self.layout.drawText(l,
                                         self.width // 2 - (len(l) * 6) // 2 +
                                         1,
                                         self.height // 2 + 1,
                                         color=colors.Green)
                else:
                    x = self.width // 2 - 2
                    y = 1
                    self.layout.drawText("P", x, y + 0, color=colors.White)
                    self.layout.drawText("A", x, y + 8, color=colors.White)
                    self.layout.drawText("U", x, y + 16, color=colors.White)
                    self.layout.drawText("S", x, y + 24, color=colors.White)
                    self.layout.drawText("E", x, y + 32, color=colors.White)
                    self.layout.drawText("D", x, y + 40, color=colors.White)

            else:
                self.disp_msg("{}".format(self.score), 1, 1)

                lines_left = self.level * self.lines_per_level - self.lines
                for l in range(lines_left):
                    self.layout.set(0, self.height - 1 - l * 2, colors.Red)

                # draw rainbow border
                self.layout.drawLine(2,
                                     8,
                                     cols + 3,
                                     8,
                                     colorFunc=lambda pos: colors.hue_helper(
                                         pos, cols + 2, self._speedStep * 2))
                self.layout.drawLine(
                    2,
                    self.height - 1,
                    cols + 3,
                    self.height - 1,
                    colorFunc=lambda pos: colors.hue_helper(
                        cols + 2 - pos, cols + 2, self._speedStep * 2))
                self.layout.drawLine(
                    2,
                    9,
                    2,
                    self.height - 2,
                    colorFunc=lambda pos: colors.hue_helper(
                        rows + 2 - pos, rows, self._speedStep * 2))
                self.layout.drawLine(cols + 3,
                                     9,
                                     cols + 3,
                                     self.height - 2,
                                     colorFunc=lambda pos: colors.hue_helper(
                                         pos, rows, self._speedStep * 2))

                # draw current board state
                self.draw_matrix(self.board, (3, 9))
                # draw current block
                self.draw_matrix(self.stone,
                                 (self.stone_x + 3, self.stone_y + 9))
                # draw next block
                self.draw_matrix(self.next_stone, (self.width - 6, 1))
                # drop block
                if self.checkSpeed("drop"):
                    self.drop(False)

        self._step += amt
Esempio n. 39
0
    def step(self, amt = 1):
        self._color = colors.hue_helper(0, self._size, self._step)

        super(LarsonRainbow, self).step(amt)
    def __init__(self, led, start=0, end=-1):
        super(RainbowCycle, self).__init__(led, start, end)
        print(self._size)
#        self.frames = [[colors.hue_helper(c, self._size, i) for c in range(self._size)] for i in range(255)]
        frames = [    list(sum([colors.hue_helper(c, self._size, i) for c in range(self._size)], ()))     for i in range(255)]
        self.frames = map(lambda x: colors.color_scale(x, 175), frames)
Esempio n. 41
0
    def write_matrix(self, pin_list):
        if self.update_skip != 0:
            self.update_skip -= 1
            if self.update_skip >= 0:
                return

        if len(self.led_config.matrix_pattern_type) == 1:
            self.p_type = self.led_config.matrix_pattern_type[0]
        else:
            for pin in xrange(len(pin_list)):
                self.beats += pin_list[pin] * (len(pin_list) /
                                               (pin + 1)) * 0.002
            if self.beats > self.led_config.beats:
                self.beats = 0
                self.p_num += 1
                if self.p_num >= len(self.led_config.matrix_pattern_type):
                    self.p_num = 0
            self.p_type = self.led_config.matrix_pattern_type[self.p_num]

        self.led.all_off()

        h = self.led_config.matrix_height
        w = self.led_config.matrix_width

        if self.p_type == 'SBARS':
            for y in range(h):
                y_ind = int((float(len(pin_list)) / h) * y)
                for x_cord in range(int(pin_list[y_ind] * float(w))):
                    rgb = color_map[int(255.0 * float(x_cord) / float(w))]
                    self.led.set(y_ind, x_cord, rgb)

        if self.p_type == 'MBARS':
            norm_arr = [int(x * 255) for x in pin_list]
            self.drops.append(norm_arr)
            for y_cord in range(w):
                for x in range(h):
                    x_ind = int((float(len(pin_list)) / h) * x)
                    if self.drops[y_cord][x_ind] > 64:
                        rgb = scale(color_map[255 - self.drops[y_cord][x_ind]],
                                    int(self.drops[y_cord][x_ind] * 0.5))
                        self.led.set(x, w - 1 - y_cord, rgb)
            del self.drops[0]

        elif self.p_type == 'IMAGE':
            complete_image = self.base_image
            for pin in xrange(len(pin_list)):
                if pin_list[pin] > 0.55:
                    complete_image = ImageChops.add_modulo(
                        complete_image,
                        ImageEnhance.Brightness(self.images[pin]).enhance(
                            pin_list[pin]))

            image.showImage(
                self.led, "",
                ImageEnhance.Brightness(complete_image).enhance(
                    self.max_brightness * 0.5))

        elif self.p_type == 'PINWHEEL':
            amt = 0

            for pin in xrange(len(pin_list)):
                amt += pin_list[pin] * (len(pin_list) / (pin + 1)) * 0.25
            amt = int(amt)

            pos = 0
            for x in range(h):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self._cX, self._cY, x, 0, c)
                pos += 1

            for y in range(w):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self._cX, self._cY, h - 1, y, c)
                pos += 1

            for x in range(h - 1, -1, -1):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self._cX, self._cY, x, w - 1, c)
                pos += 1

            for y in range(w - 1, -1, -1):
                c = colors.hue_helper(pos, self._len, self._step)
                self.led.drawLine(self._cX, self._cY, 0, y, c)
                pos += 1

            self._step += amt
            if (self._step >= 255):
                self._step = 0

        elif self.p_type == 'CBARS':
            midl = int(h / 2)
            for y in range(w):
                level = pin_list[int(
                    (y / float(w)) * float(self.led_config.led_channel_count))]
                brightness = int(255 * level)
                rgb = scale(color_map[brightness], brightness)
                mlvl = int(level * midl)
                self.led.drawLine(midl - mlvl, y, midl + mlvl, y, rgb)

        elif self.p_type == 'CIRCLES':
            for pin in xrange(len(pin_list)):
                rgb = self.rgb[pin]
                c = scale(rgb, int((pin_list[pin]) * 255))
                self.led.drawCircle(self._cX, self._cY, pin, c)

        self.led.update()
        self.update_skip = self.skip