示例#1
0
 def get_rain_bow(i2, i15, x, y, offset=30):
     r = (math.cos((x+i2)/2.0) + math.cos((y+i2)/2.0)) * 64.0 + 128.0
     g = (math.sin((x+i15)/1.5) + math.sin((y+i2)/2.0)) * 64.0 + 128.0
     b = (math.sin((x+i2)/2.0) + math.cos((y+i15)/1.5)) * 64.0 + 128.0
     r = max(0, min(255, r+offset))
     g = max(0, min(255, g+offset))
     b = max(0, min(255, b+offset))
     return npxp.get_colour(int(r), int(g), int(b))
示例#2
0
def get_randomness(width, height):
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    colour = npxp.get_colour(r, g, b)

    x = random.randint(0, (width-1))
    y = random.randint(0, (height-1))
    position = (x, y)

    return position, colour
示例#3
0
 def _rainbow_blinky_blink(self, z):
     for y in range(self.height):
         for x in range(self.width):
             if self.height<=self.width:
                 delta = 0
                 v = z[x,y+delta]
             else:
                 delta = 2
                 v = z[x+delta,y]
             h = 1.0/(x + y + delta + 1)
             s = 0.8
             rgb = [int(i*255.0) for i in colorsys.hsv_to_rgb(h, s, v)]
             self.set_pixel_colour((x, y), npxp.get_colour(*rgb))
示例#4
0
    def _init_custom_patterns(self):
        self.width = len(SQUARE_LED_MAP[0])
        self.height = len(SQUARE_LED_MAP)

        self.bucket_heights = [0] * (self.width - 2)
        self.bucket_contour_colour = npxp.get_colour(255, 255, 255)
        self.bucket_state = "drop"  # "clean"

        self.rainbow_wave_state_2 = 0.0
        self.rainbow_wave_state_15 = 0.0

        # TODO: pre-compute -- numpy i snot a requirement anymore
        z = list(range(1, 10)[::-1]) + list(range(1, 10))
        z_fwhm = [5.0/i for i in z]
        gauss = [gaussian(fwhm) for fwhm in z_fwhm]
        self.rainbow_blinky_gauss = itertools.cycle(gauss)
        self.rainbow_blinky_z = next(self.rainbow_blinky_gauss)

        self.cross_points = []
        self.cross_Point = collections.namedtuple("Point", "position colour direction")

        self.figlet_text = "GLASS-BOX"
        self.figlet_scroll = -3
        self.figlet_text_colour = npxp.get_colour(0, 255, 0)

        self.ascii_pic = "        \n        \n  X  X  \n        \nX      X\n XXXXXX \n        \n        \n        "
        self.ascii_colour = npxp.get_colour(0, 255, 0)
        self.ascii_scroll = 0

        custom_patterns_map = {"random_flicker": self._random_flicker,
                "bucket": self._bucket, "rainbow": self._rainbow,
                "cross": self._cross, "ascii": self._ascii}
        self.pattern_map.update(custom_patterns_map)
        if NUMPY:
            self.pattern_map.update({"rainbow_blinky": self._rainbow_blinky})
        if PYFIGLET:
            self.pattern_map.update({"figlet": self._figlet})
示例#5
0
    def _cross_new_point(self):
        direction = random.randint(1, 4)
        if direction == 1:
            point = [0, random.randint(0, self.width - 1)]
        elif direction == 2:
            point = [random.randint(0, self.height - 1), 0]
        elif direction == 3:
            point = [self.height-1, random.randint(0, self.width - 1)]
        else:
            point = [random.randint(0, self.height - 1), self.width - 1]

        colour = []
        for i in range(0, 3):
            colour.append(random.randint(100, 255))
        colour = npxp.get_colour(*colour)

        self.cross_points.append(self.cross_Point(position=point, colour=colour, direction=direction))
示例#6
0
    def _init_custom_patterns(self):
        custom_patterns_map = {
            "rainbow": self._rainbowCycle,
            "shake": self._shake_four,
            "bounce": self._bounce,
            "wave": self._wave
        }
        self.pattern_map.update(custom_patterns_map)

        # Rainbow
        self.rainbow_state = 0
        self.rainbow_clockwise = False
        # Shake
        self.shake_state = 1
        self.shake_red = npxp.get_colour(217, 80, 64)
        self.shake_green = npxp.get_colour(88, 165, 92)
        self.shake_blue = npxp.get_colour(79, 134, 237)
        self.shake_yellow = npxp.get_colour(243, 189, 66)
        self.shake_one = 0
        self.shake_two = 4
        self.shake_three = 8
        self.shake_four = 12
        self.shake_pattern = [(self.shake_one, self.shake_red), \
                              (self.shake_two, self.shake_green), \
                              (self.shake_three, self.shake_blue), \
                              (self.shake_four, self.shake_yellow)]
        # Bounce
        self.bounce_state = 0
        self.bounce_bg = npxp.get_colour(0, 0, 0)
        self.bounce_fg = npxp.get_colour(0, 0, 128)
        # Wave
        self.wave_origin = {"one": 0, "two": 8}
        self.wave_state = {"one": 0, "two": 0}
        self.wave_queue = {"one": [], "two": []}
        self.wave_colour = {
            "one": npxp.get_colour(127, 0, 127),
            "two": npxp.get_colour(0, 127, 127)
        }
        self.wave_colour_current = {"one": 0, "two": 0}
示例#7
0
 def ball_colour():
     r = random.randint(100, 255)
     g = random.randint(100, 255)
     b = random.randint(100, 255)
     return npxp.get_colour(r, g, b)
示例#8
0
SQUARE_LED_CHANNEL    = 1       # set to '1' for GPIOs 13, 19, 41, 45 or 53
SQUARE_LED_COUNT      = 64      # Number of LED pixels.

SQUARE_LED_MAP = [
    [ 0,  1,  2,  3,  4,  5,  6,  7],
    [ 8,  9, 10, 11, 12, 13, 14, 15],
    [16, 17, 18, 19, 20, 21, 22, 23],
    [24, 25, 26, 27, 28, 29, 30, 31],
    [32, 33, 34, 35, 36, 37, 38, 39],
    [40, 41, 42, 43, 44, 45, 46, 47],
    [48, 49, 50, 51, 52, 53, 54, 55],
    [56, 57, 58, 59, 60, 61, 62, 63]
]

SQUARE_COLOURS = {
    'red':npxp.get_colour(255,0,0),
    'lime':npxp.get_colour(0,255,0),
    'blue':npxp.get_colour(0,0,255),
    'yellow':npxp.get_colour(255,255,0),
    'magenta':npxp.get_colour(255,0,255),
    'cyan':npxp.get_colour(0,255,255),
    'black':npxp.get_colour(0,0,0),
    'white':npxp.get_colour(255,255,255),
    'gray':npxp.get_colour(127,127,127),
    'grey':npxp.get_colour(127,127,127),
    'silver':npxp.get_colour(192,192,192),
    'maroon':npxp.get_colour(128,0,0),
    'olive':npxp.get_colour(128,128,0),
    'green':npxp.get_colour(0,128,0),
    'purple':npxp.get_colour(128,0,128),
    'teal':npxp.get_colour(0,128,128),