def start(self): self.rainbow = Rainbow(self.app.ipcon) self.update_frame_rate() self.update_step() self.rainbow.frame_rendered(0)
def create_rainbow(ai_settings, screen, rainbows, rainbow_number, row_number): rainbow = Rainbow(ai_settings, screen) rainbow_width = rainbow.rect.width rainbow.x = rainbow_width + 2 * rainbow_width * rainbow_number rainbow.rect.x = rainbow.x rainbow.rect.y = rainbow.rect.height + 2 * rainbow.rect.height * row_number rainbows.add(rainbow)
def renderBestMatches(self, fileName, weighted=False): """make an image of where best matches lie set weighted to use a heatmap view of where they map """ img_points = np.zeros((self.weights.rows,self.weights.columns)) try: img = Image.new("RGB", (self.weights.columns, self.weights.rows)) if(weighted): # color points by bestmatch density max = 0 for point in self.bestMatchCoords: img_points[point[0],point[1]] += 1 if(max < img_points[point[0],point[1]]): max = img_points[point[0],point[1]] max += 1 resolution = 200 if(max < resolution): resolution = max - 1 max = self.transColour(max) rainbow = Rainbow(0, max, resolution, "gbr") for point in self.bestMatchCoords: img.putpixel((point[1],point[0]), rainbow.getColour(self.transColour(img_points[point[0],point[1]]))) else: # make all best match points white for point in self.bestMatchCoords: img.putpixel((point[1],point[0]), (255,255,255)) img = img.resize((self.weights.columns*10, self.weights.rows*10),Image.NEAREST) img.save(fileName) except: print sys.exc_info()[0] raise
def main(): # Setup flags parser = argparse.ArgumentParser(description='Bridge Contentful and Hugo') parser.add_argument('store-id') parser.add_argument('access-token') parser.add_argument('content-directory') args = vars(parser.parse_args()) rainbow = Rainbow(args['store-id'], args['access-token'], args['content-directory']) rainbow.save_posts()
def run(pattern): patterns = [] for r, p in enumerate(pattern): patterns.append( Pattern(pattern=p[0], fgcolor=p[1], style=p[3], bgcolor=p[2], rank=r)) r = Rainbow(patterns) for line in sys.stdin: line = r.process_line(line) print(line, end='')
def thread_body(queue): pixels = NeoPixel(DATA_PIN, N_PIXELS, brightness=BRIGHTNESS, auto_write=False) updates = {'RAINBOW': Rainbow(pixels), 'ANT': Ant(pixels), 'OCD': Ocd(pixels), 'FLASH': Flash(pixels), 'IMPLODE': Implode(pixels), 'ERROR': Error(pixels), 'QUIT': Quit(pixels)} assert set(updates.keys()) == MODES mode = "OCD" while True: try: new_mode = queue.get_nowait() assert new_mode in MODES, "unknown mode %s" % mode if new_mode != mode: updates[new_mode].setup() mode = new_mode except: pass sleep = updates[mode].exec_update() if mode == "QUIT": break time.sleep(sleep)
def button_handler(self, event): """Button action handler. Currently differentiates between exit, rc, rainbow and other buttons only""" logger.debug("%s button pressed", event.label) if event.label is "RC": logger.info("launching RC challenge") new_challenge = RC(timeout=self.timeout, screen=self.screen, joystick=self.joystick) return new_challenge elif event.label is "Rainbow": logger.info("launching Rainbow challenge") new_challenge = Rainbow(timeout=self.timeout, screen=self.screen, joystick=self.joystick) return new_challenge elif event.label is "Maze": logger.info("launching Maze challenge") new_challenge = Maze(timeout=self.timeout, screen=self.screen, joystick=self.joystick, markers = self.markers) return new_challenge elif event.label is "Speed": logger.info("launching Speed challenge") new_challenge = StraightLineSpeed(timeout=self.timeout, screen=self.screen, joystick=self.joystick, markers = self.markers) return new_challenge elif event.label == "Pi Noon": logger.info("launching Pi Noon challenge") new_challenge = PiNoon(timeout=self.timeout, screen=self.screen, joystick=self.joystick) return new_challenge elif event.label is "Exit": logger.info("Exit button pressed. Exiting now.") return "Exit" else: logger.info("unsupported button selected (%s)", event.label) return "Other"
def loadScripts(self, dir): import sys sys.path.insert(0, "./scripts") from Script import Script s = Script(self, "test") from loading import Loading l = Loading(self.segments[0]) self.scripts.append(l) from TheaterChase import TheaterChase t = TheaterChase(self.segments[0]) self.scripts.append(t) from rainbow import Rainbow r = Rainbow(self.segments[0]) self.scripts.append(r) from LeftToRightRandom import LeftToRightRandom lr = LeftToRightRandom(self.segments[0]) self.scripts.append(lr) from RandomLed import RandomLed r = RandomLed(self.segments[0]) self.scripts.append(r) from Light import Light self.scripts.append(Light(self.segments[0])) from Test import Test self.scripts.append(Test(self.segments[0])) from Cycle import Cycle self.scripts.append(Cycle(self.segments[0])) from SingleColor import SingleColor self.scripts.append(SingleColor(self.segments[0]))
def create_fleet(ai_settings, screen, unicorn, rainbows): rainbow = Rainbow(ai_settings, screen) number_rainbows_x = get_number_rainbows_x(ai_settings, rainbow.rect.width) number_rows = get_number_rows(ai_settings, unicorn.rect.height, rainbow.rect.height) for row_number in range(number_rows): for rainbow_number in range(number_rainbows_x): create_rainbow(ai_settings, screen, rainbows, rainbow_number, row_number)
def main(): pygame.init() pygame.display.set_caption("Nyan Cat") DISPLAY_SURFACE = pygame.display.set_mode((320, 240)) BACKGROUND_COLOR = pygame.Color(15, 77, 143) DISPLAY_SURFACE.fill(BACKGROUND_COLOR) FPS = 12 CLOCK = pygame.time.Clock() #Create objects. cat = Nyancat() #cat = Nyancat(pygame.Rect(0, 0, 100, 100)) #cat = Nyancat(pygame.Rect(0, 0, 200, 200)) cat.rect.center = DISPLAY_SURFACE.get_rect().center rainbow = Rainbow(cat.rect, cat.cellSize) starManager = StarManager(DISPLAY_SURFACE.get_rect(), cat.cellSize, 20, -5) while True: DISPLAY_SURFACE.fill(BACKGROUND_COLOR) for e in pygame.event.get(): if e.type == pygame.QUIT: pygame.quit() sys.exit() #Draw the objects. #The objects will be drawn on the same surface object in the order they get called. rainbow.draw(DISPLAY_SURFACE) cat.draw(DISPLAY_SURFACE) starManager.draw(DISPLAY_SURFACE) #Update the animation state of the objects. rainbow.update() cat.update() starManager.update() pygame.display.update() CLOCK.tick(FPS)
class RainbowWidget(QWidget, Ui_Rainbow): rainbow = None def __init__(self, parent, app): super(QWidget, self).__init__() self.app = app self.setupUi(self) self.slider_frame_rate.valueChanged.connect(self.slider_frame_rate_changed) self.slider_step.valueChanged.connect(self.slider_step_changed) self.spinbox_frame_rate.valueChanged.connect(self.spinbox_frame_rate_changed) self.spinbox_step.valueChanged.connect(self.spinbox_step_changed) self.button_default.pressed.connect(self.default_pressed) self.update_frame_rate_timer = QTimer(self) self.update_frame_rate_timer.timeout.connect(self.update_frame_rate) self.default_pressed() def start(self): self.rainbow = Rainbow(self.app.ipcon) self.update_frame_rate() self.update_step() self.rainbow.frame_rendered(0) def stop(self): if self.rainbow: self.rainbow.stop_rendering() self.rainbow = None def spinbox_frame_rate_changed(self, frame_rate): self.slider_frame_rate.setValue(frame_rate) self.update_frame_rate_timer.start(100) def spinbox_step_changed(self, step): self.slider_step.setValue(step * 10) self.update_step() def slider_frame_rate_changed(self, frame_rate): self.spinbox_frame_rate.setValue(frame_rate) def slider_step_changed(self, step): self.spinbox_step.setValue(step / 10.0) def default_pressed(self): self.spinbox_frame_rate.setValue(50) self.spinbox_step.setValue(0.2) def update_frame_rate(self): self.update_frame_rate_timer.stop() config.RAINBOW_FRAME_RATE = self.spinbox_frame_rate.value() if self.rainbow: self.rainbow.update_frame_rate() def update_step(self): config.RAINBOW_STEP = self.spinbox_step.value() / 100.0
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()] if len(devices) == 0: print('No input devices are found. Waiting for next detection') time.sleep(1) for device in devices: key = 0 print(device.fn, device.name, device.phys) if 'keyboard' in device.name.lower(): print('Keyboard device {} is found.'.format(device.name)) else: print('Waiting for keyboard device') time.sleep(1) continue device = evdev.InputDevice(device.fn) rainbow = Rainbow() for event in device.read_loop(): print('type={}, code={}, value={}'.format(event.type, event.code, event.value)) if event.type == evdev.ecodes.EV_KEY: if event.value != 2: key = event.code evdev_code = evdev.ecodes.KEY[key] modkey_element = keymap.modkey(evdev_code) if modkey_element > 0: if event.value == 1: modkey[modkey_element] = 1 else: modkey[modkey_element] = 0 continue
from matrix import Matrix from power import Power from weird1 import Weird1 from weird2 import Weird2 from weird3 import Weird3 from flash import Flash from lighthouse import Lighthouse lenx = 7 leny = 21 strip2D = Strip2D(lenx, leny) effects = [ [Police1(strip2D), 3], [Rainbow(strip2D), 10], [Police2(strip2D), 3], [Bump1(strip2D), 3], [Police3(strip2D), 3], [Lemmings1(strip2D), 10], [CMorph(strip2D), 7], [Plasma(strip2D), 30], [Fire(strip2D), 30], [Fire2(strip2D), 30], [Night(strip2D), 30], [Fade1(strip2D), 3], [Fade2(strip2D), 3], [Stars1(strip2D), 15], [Stars2(strip2D), 10], [Hourglass(strip2D), 30], [Matrix(strip2D), 20],
class RainbowWidget(QWidget, Ui_Rainbow): rainbow = None def __init__(self, parent, app): super(QWidget, self).__init__() self.app = app self.setupUi(self) self.slider_frame_rate.valueChanged.connect( self.slider_frame_rate_changed) self.slider_step.valueChanged.connect(self.slider_step_changed) self.spinbox_frame_rate.valueChanged.connect( self.spinbox_frame_rate_changed) self.spinbox_step.valueChanged.connect(self.spinbox_step_changed) self.button_default.pressed.connect(self.default_pressed) self.update_frame_rate_timer = QTimer(self) self.update_frame_rate_timer.timeout.connect(self.update_frame_rate) self.default_pressed() def start(self): self.rainbow = Rainbow(self.app.ipcon) self.update_frame_rate() self.update_step() self.rainbow.frame_rendered(0) def stop(self): if self.rainbow: self.rainbow.stop_rendering() self.rainbow = None def spinbox_frame_rate_changed(self, frame_rate): self.slider_frame_rate.setValue(frame_rate) self.update_frame_rate_timer.start(100) def spinbox_step_changed(self, step): self.slider_step.setValue(step * 10) self.update_step() def slider_frame_rate_changed(self, frame_rate): self.spinbox_frame_rate.setValue(frame_rate) def slider_step_changed(self, step): self.spinbox_step.setValue(step / 10.0) def default_pressed(self): self.spinbox_frame_rate.setValue(50) self.spinbox_step.setValue(0.2) def update_frame_rate(self): self.update_frame_rate_timer.stop() config.RAINBOW_FRAME_RATE = self.spinbox_frame_rate.value() if self.rainbow: self.rainbow.update_frame_rate() def update_step(self): config.RAINBOW_STEP = self.spinbox_step.value() / 100.0