Esempio n. 1
0
 def dim(cls, colors, alpha):
     return [ColorHelper.proportional_mix_colors(color, (0,0,0), alpha) for color in colors]
Esempio n. 2
0
while True:
  for event in pygame.event.get():
    if event.type == pygame.QUIT: sys.exit()
  
  if numpy.random.random() < 0.01:
    simulation.addComet()

  ### Update physics
  fps = 50
  iterations = 25
  dt = 1.0/float(fps)/float(iterations)
  for x in range(iterations): # 10 iterations to get a more stable simulation
      simulation.space.step(dt)

  ### Clear screen
  screen.fill(pygame.color.THECOLORS["black"])

  simulation.project_to_pygame_screen(screen)

  fader_filter.stimulate(simulation.project_to_intensity_list(N_LEDS))

  color_pallette = ColorPallette.colors(ColorPallette.WATER)
  led_colors = [ColorHelper.color_from_intensity(excitement, color_pallette) for excitement in fader_filter.excitements]

  client.put_pixels(SixtyToSixtyFourHelper.transform(led_colors), channel=0)

  screen.blit(font.render("fps: " + str(clock.get_fps()), 1, pygame.color.THECOLORS["white"]), (0,0))
  
  pygame.display.flip()
  clock.tick(fps)
Esempio n. 3
0
  for event in pygame.event.get():
    if event.type == pygame.QUIT: sys.exit()
  
  ### Update physics
  fps = 50
  iterations = 25
  dt = 1.0/float(fps)/float(iterations)
  for x in range(iterations): # 10 iterations to get a more stable simulation
    simulation.space.step(dt)

  ### Draw screen
  screen.fill(pygame.color.THECOLORS["black"])
  simulation.project_to_pygame_screen(screen)

  ### Actually do some LED animations
  couch = simulation.get_couch()
  min_couch_position = min(min_couch_position, couch.position[1])
  max_couch_position = max(max_couch_position, couch.position[1])

  dim = 1 - (couch.position[1] - min_couch_position) / (max_couch_position - min_couch_position)

  led_colors = [ColorHelper.rainbow(float(a)/256, index, 128) for index, a in enumerate(range(N_LEDS))]
  led_colors = DimmerHelper.dim(led_colors, dim)

  client.put_pixels(led_colors, channel=0)

  ### Service the loop
  screen.blit(font.render("fps: " + str(clock.get_fps()), 1, pygame.color.THECOLORS["white"]), (0,0))
  pygame.display.flip()
  clock.tick(fps)