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)
Example #2
0
### interesting rules
# 30 is sort of random, breaks as things stack up in a 101010101 pattern
# 18 serpinski triangle

# connect to OPC server
IP_PORT = '127.0.0.1:7890'
client = opc.Client(IP_PORT)
if client.can_connect():
    print '    connected to %s' % IP_PORT
else:
    # can't connect, but keep running in case the server appears later
    print '    WARNING: could not connect to %s' % IP_PORT

fader_filter = FaderFilter(N_LEDS, 0.6)
color_pallette = ColorPallette.colors(ColorPallette.WATER)

phase = 0
while True:
  fader_filter.stimulate(simulation.array)
  
  led_colors = [ColorHelper.color_from_intensity(excitement, color_pallette) for excitement in fader_filter.excitements]
  phase = phase+0.3 % 4

  #led_colors = [ColorHelper.rainbow(excitement, index, N_LEDS, phase) for index, excitement in enumerate(fader_filter.excitements)]
  led_colors = DimmerHelper.dim(led_colors, .5)
  client.put_pixels(SixtyToSixtyFourHelper.transform(led_colors), channel=0)

  time.sleep(.2)
  simulation.step()