Ejemplo n.º 1
0
def pattern_2():
  global p2_color, p2_delta, p2_direction, p2_length, p2_x, p2_y

  if p2_length == 0:
    p2_length = urandom.randint(int(led.length_x / 4), int(led.length_x * 3/4))

    while True:                                        # avoid 180 degree turns
      direction = urandom.randint(0, 3)
      if direction != (p2_direction + 2) % 4:
        p2_direction = direction
        break

    color = led.random_color()                         # smooth transition
    delta_red   = (color[0] - p2_color[0]) / p2_length
    delta_green = (color[1] - p2_color[1]) / p2_length
    delta_blue  = (color[2] - p2_color[2]) / p2_length
    p2_delta = (delta_red, delta_green, delta_blue)

  if p2_direction == 0: p2_x = (p2_x + 1) % led.length_x
  if p2_direction == 1: p2_y = (p2_y + 1) % led.length_x
  if p2_direction == 2: p2_x = (p2_x - 1) % led.length_x
  if p2_direction == 3: p2_y = (p2_y - 1) % led.length_x

  red   = p2_color[0] + p2_delta[0]
  green = p2_color[1] + p2_delta[1]
  blue  = p2_color[2] + p2_delta[2]
  p2_color = (red, green, blue)

  led.pixel_xy(p2_color, p2_x, p2_y, write=True)
  p2_length -= 1
Ejemplo n.º 2
0
def pattern_0():
  global p0_setup, p0_index, p0_colors, p0_color, p0_time_next
  if p0_setup:
    p0_setup = False
    led.dim = 1.0
  for p0_x in range(led.length):
    p0_y = 0
    led.pixel_xy(p0_color, p0_x, p0_y, write=True)
  if ticks_ms() > p0_time_next:
    p0_time_next = ticks_ms() + 1000
    p0_index = (p0_index + 1) % len(p0_colors)
    p0_color = led.colors[p0_colors[p0_index]]