Exemple #1
0
 async def end_to_end(self):
     for pixel_rgb_tuple in self.active_snake.pattern_base:
         red, green, blue = rgb_tuple_split(pixel_rgb_tuple)
         for final_pixel in reversed(range(0, self.count)):
             for pixel_number in range(0, final_pixel + 1):
                 initial_pixel_color = self.get_pixel_color(pixel_number)
                 initial_red, initial_green, initial_blue = rgb_tuple_split(
                     initial_pixel_color)
                 self.set_pixel_color(pixel_number, red, green, blue)
                 self.pixels.show()
                 await asyncio.sleep(0.005)
                 if pixel_number != final_pixel:
                     self.set_pixel_color(pixel_number, initial_red,
                                          initial_green, initial_blue)
Exemple #2
0
 async def oneline(self):
     for pixel_rgb_tuple in self.active_snake.pattern_base:
         red, green, blue = rgb_tuple_split(pixel_rgb_tuple)
         for pixel_number in range(self.count):
             self.set_pixel_color(pixel_number, red, green, blue)
             self.pixels.show()
             await asyncio.sleep(0.1)
Exemple #3
0
 async def randblink(self):
     for pixel_rgb_tuple in self.active_snake.pattern:
         red, green, blue = rgb_tuple_split(pixel_rgb_tuple)
         for pixel_number in range(self.count):
             if getrandbits(1):
                 self.set_pixel_color(pixel_number, red, green, blue)
         self.pixels.show()
         await asyncio.sleep(1)
Exemple #4
0
 async def subset_color_wheel(self):
     for pixel_number in range(self.count):
         color_position = (pixel_number + self.active_snake.counter) % len(
             self.active_snake.pattern)
         red, green, blue = rgb_tuple_split(
             self.active_snake.pattern[color_position])
         self.set_pixel_color(pixel_number, red, green, blue)
     self.pixels.show()
     self.active_snake.counter += 1
     await asyncio.sleep(0.08)
Exemple #5
0
 async def random_walk(self):
     random_step = randint(0, 5)
     for pixel_number in range(self.count):
         color_position = abs(
             (pixel_number + random_step) % len(self.active_snake.pattern))
         red, green, blue = rgb_tuple_split(
             self.active_snake.pattern[color_position])
         self.set_pixel_color(pixel_number, red, green, blue)
     self.pixels.show()
     await asyncio.sleep(random_step * 0.1 + 0.1)
Exemple #6
0
    async def mid_meet(self):
        for pixel_rgb_tuple in self.active_snake.pattern_base:
            red, green, blue = rgb_tuple_split(pixel_rgb_tuple)
            for pixel_number in range(0, self.count // 2):

                left_pixel = pixel_number
                right_pixel = self.count - pixel_number - 1
                self.set_pixel_color(left_pixel, red, green, blue)
                self.set_pixel_color(right_pixel, red, green, blue)
                self.pixels.show()
                await asyncio.sleep(0.02)
Exemple #7
0
 async def rand_one_by_one(self):
     pixel_range = range(0, self.count)
     for pixel_rgb_tuple in self.active_snake.pattern_base:
         red, green, blue = rgb_tuple_split(pixel_rgb_tuple)
         included_list = [*pixel_range]
         for count in range(self.count):
             rand_pixel = choice(included_list)
             included_list.remove(rand_pixel)
             self.set_pixel_color(rand_pixel, red, green, blue)
             self.pixels.show()
             await asyncio.sleep(1)
     if len(self.active_snake.pattern_base) == 1:
         self.turn_off_all_pixels()
Exemple #8
0
 async def multicolor_snake(self, crawl_length: int = 120):
     for background_rgb in self.active_snake.pattern_base:
         # can comment if snake fills entire
         self.set_range_of_pixels(
             self.active_snake.start,
             self.active_snake.start + len(self.active_snake.pattern),
             rgb_tuple_split(background_rgb),
             inside=False,
         )
         for i in range(crawl_length):
             background_red, background_green, background_blue = rgb_tuple_split(
                 background_rgb)
             self.set_pixel_color(
                 self.active_snake.start,
                 background_red,
                 background_green,
                 background_blue,
             )
             self.active_snake.move(1)
             self.active_snake.iteration(self.move_pattern)
             self.pixels.show()
             await asyncio.sleep(0.02)
Exemple #9
0
 def full_color_wheel(self):
     color_dict_list = read_to_dict_list("resources/colors.csv")
     color_tuples = [
         tuple(color["rgb"].split(",")) for color in color_dict_list
     ]
     for color in color_tuples:
         for pixel_number in reversed(range(1, self.count)):
             red, green, blue = self.get_pixel_rgb(pixel_number - 1)
             self.set_pixel_color(pixel_number, red, green, blue)
         red, green, blue = rgb_tuple_split(color)
         self.set_pixel_color(0, red, green, blue)
         self.pixels.show()
         time.sleep(0.05)
Exemple #10
0
 def snake(self, color: Tuple[str, str, str], length: int):
     red, green, blue = rgb_tuple_split(color)
     loop_count = 80  # TODO make a while loop
     start = 0
     end = length
     for pixel in range(start, length + 1):
         self.set_pixel_color(pixel, red, green, blue)
     self.pixels.show()
     time.sleep(0.1)
     for i in range(loop_count):
         self.turn_off_pixel(start)
         start = (start + 1) % self.count
         end = (end + 1) % self.count
         self.set_pixel_color(end, red, green, blue)
         self.pixels.show()
         time.sleep(0.1)
Exemple #11
0
 def set_range_of_pixels(self,
                         start: int,
                         stop: int,
                         color: Tuple[str, str, str],
                         inside: bool = True):
     red, green, blue = rgb_tuple_split(color)
     if inside:
         for pixel_number in range(start, stop + 1):
             self.set_pixel_color(
                 modulo_position_in_count(pixel_number, self.count), red,
                 green, blue)
     else:
         for pixel_number in range(0, start):
             self.set_pixel_color(
                 modulo_position_in_count(pixel_number, self.count), red,
                 green, blue)
         for pixel_number in range(stop, self.count):
             self.set_pixel_color(
                 modulo_position_in_count(pixel_number, self.count), red,
                 green, blue)
Exemple #12
0
 async def fader(self):
     fade_steps = 100
     for rgb in self.active_snake.pattern:
         red_max, green_max, blue_max = rgb_tuple_split(rgb)
         for step in range(fade_steps):
             red = int(min(red_max, red_max / fade_steps * step))
             green = int(min(green_max, green_max / fade_steps * step))
             blue = int(min(blue_max, blue_max / fade_steps * step))
             for pixel_number in range(self.count):
                 self.set_pixel_color(pixel_number, red, green, blue)
             self.pixels.show()
             await asyncio.sleep(0.01)
         for step in reversed(range(fade_steps)):
             red = int(max(0, red_max / fade_steps * step))
             green = int(max(0, green_max / fade_steps * step))
             blue = int(max(0, blue_max / fade_steps * step))
             for pixel_number in range(self.count):
                 self.set_pixel_color(pixel_number, red, green, blue)
             self.pixels.show()
             await asyncio.sleep(0.01)
Exemple #13
0
 def move_pattern(self, pattern, position, pixel):
     current_pixel = pixel if pixel < self.count else (pixel +
                                                       1) % self.count
     red, green, blue = rgb_tuple_split(pattern[position])
     self.set_pixel_color(current_pixel, red, green, blue)
Exemple #14
0
 async def blink_pattern(self):
     for pixel_rgb_tuple in self.active_snake.pattern:
         red, green, blue = rgb_tuple_split(pixel_rgb_tuple)
         await self.blink(red, green, blue)