def __init__(self, wall, nocam=False, effects=Effects, effect_order="random"): """ wall: Wall object nocam: boolean indicating if a camera is being used effects: list of Effect classes effect_order: string describing the order in which effects will be displayed. The supported options are 'random' and 'serial'. """ self.wall = wall self.nocam = nocam if not self.nocam: self.watcher = Watcher() else: self.watcher = DebugWatcher() # Filter out effects that won't run with this wall's dimensions. self.effects = filter(lambda effect: effect.run_on_wall( self.wall.width, self.wall.height), effects) if not len(self.effects): print "None of the provided effects can run on this %d x %d wall." % ( self.wall.width, self.wall.height) sys.exit(1) self.effect_order = effect_order if self.effect_order == "serial": self.current_effect = 0
def __init__(self, wall, nocam=False, effects=Effects, effect_order="random"): """ wall: Wall object nocam: boolean indicating if a camera is being used effects: list of Effect classes effect_order: string describing the order in which effects will be displayed. The supported options are 'random' and 'serial'. """ self.wall = wall self.nocam = nocam if not self.nocam: self.watcher = Watcher() else: self.watcher = DebugWatcher() # Filter out effects that won't run with this wall's dimensions. self.effects = filter( lambda effect: effect.run_on_wall(self.wall.width, self.wall.height ), effects) if not len(self.effects): print "None of the provided effects can run on this %d x %d wall." % ( self.wall.width, self.wall.height) sys.exit(1) self.effect_order = effect_order if self.effect_order == "serial": self.current_effect = 0
class WatchAndEffect(object): def __init__(self, wall, nocam=False, effects=Effects, effect_order="random"): """ wall: Wall object nocam: boolean indicating if a camera is being used effects: list of Effect classes effect_order: string describing the order in which effects will be displayed. The supported options are 'random' and 'serial'. """ self.wall = wall self.nocam = nocam if not self.nocam: self.watcher = Watcher() else: self.watcher = DebugWatcher() # Filter out effects that won't run with this wall's dimensions. self.effects = filter(lambda effect: effect.run_on_wall( self.wall.width, self.wall.height), effects) if not len(self.effects): print "None of the provided effects can run on this %d x %d wall." % ( self.wall.width, self.wall.height) sys.exit(1) self.effect_order = effect_order if self.effect_order == "serial": self.current_effect = 0 def run(self): while 1: vector = self.watcher.vector() if vector[0] in (1, -1): speed = vector[1] / 8 speed = min(1, speed) direction = vector[0] # simul elif vector[0] == 2: speed = random.random() / 32 dir_stack = [1, -1] direction = random.choice(dir_stack) # timeout elif vector[0] == 0: speed = random.random() / 8 direction = vector[1] effect = self.pick_effect() effect = effect(self.wall, speed=speed, direction=direction) print effect effect.run() self.wall.clear(True) def pick_effect(self): """ Returns an Effect (sub)class based on the effect_order. """ if self.effect_order == "serial": effect = self.effects[self.current_effect] self.current_effect += 1 if self.current_effect > len(self.effects) - 1: self.current_effect = 0 return effect elif self.effect_order == "random": return random.choice(self.effects) else: print "Unknown effect order: choosing random" return random.choice(self.effects)
class WatchAndEffect(object): def __init__(self, wall, nocam=False, effects=Effects, effect_order="random"): """ wall: Wall object nocam: boolean indicating if a camera is being used effects: list of Effect classes effect_order: string describing the order in which effects will be displayed. The supported options are 'random' and 'serial'. """ self.wall = wall self.nocam = nocam if not self.nocam: self.watcher = Watcher() else: self.watcher = DebugWatcher() # Filter out effects that won't run with this wall's dimensions. self.effects = filter( lambda effect: effect.run_on_wall(self.wall.width, self.wall.height ), effects) if not len(self.effects): print "None of the provided effects can run on this %d x %d wall." % ( self.wall.width, self.wall.height) sys.exit(1) self.effect_order = effect_order if self.effect_order == "serial": self.current_effect = 0 def run(self): while 1: vector = self.watcher.vector() if vector[0] in (1, -1): speed = vector[1] / 8 speed = min(1, speed) direction = vector[0] # simul elif vector[0] == 2: speed = random.random() / 32 dir_stack = [1, -1] direction = random.choice(dir_stack) # timeout elif vector[0] == 0: speed = random.random() / 8 direction = vector[1] effect = self.pick_effect() effect = effect(self.wall, speed=speed, direction=direction) print effect effect.run() self.wall.clear(True) def pick_effect(self): """ Returns an Effect (sub)class based on the effect_order. """ if self.effect_order == "serial": effect = self.effects[self.current_effect] self.current_effect += 1 if self.current_effect > len(self.effects) - 1: self.current_effect = 0 return effect elif self.effect_order == "random": return random.choice(self.effects) else: print "Unknown effect order: choosing random" return random.choice(self.effects)