From b67a37ad06fa4c97dcdb32cecc71c7f492b12840 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 16:29:36 -0500 Subject: Picking up some files that were lost. --- behaviors/ControllerOSC.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++ behaviors/Sink.py | 42 +++++++++++++++++++++++++++++ behaviors/SynchTest.py | 12 +++++++++ 3 files changed, 121 insertions(+) create mode 100644 behaviors/ControllerOSC.py create mode 100644 behaviors/Sink.py create mode 100644 behaviors/SynchTest.py (limited to 'behaviors') diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py new file mode 100644 index 0000000..ce2cf26 --- /dev/null +++ b/behaviors/ControllerOSC.py @@ -0,0 +1,67 @@ +from operationscore.Behavior import * +from logger import main_log +#import util.ColorOps as color +import colorsys +from numpy import array +import pdb +import util.ComponentRegistry as compReg + +speedfactor = 15 +vel_decay = .00 + +def constrainLocation(v,c): + if v[0] > c[0]: + v[0] = c[0] + elif v[0]<0: + v[0] = 0 + + if v[1] > c[1]: + v[1] = c[1] + elif v[1]<0: + v[1] = 0 + + return v + +class ControllerOSC(Behavior): + def behaviorInit(self): + self.xy = array((0,0)) + self.v_xy = array((0,0)) + self.v_decay = vel_decay + + self.start_hsv = [0,1,1] + self.dest_hsv = [0,1,1] + self.ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310 + + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + if sensorInputs: + data = sensorInputs[-1]#for data in sensorInputs: + if data['Path'] == '/sixaxis/xy': + #try: + x = data['Value'][0] + y = data['Value'][1] + main_log.error(str(x)) + if y < 0: + self.start_hsv[1] = 1.0+y #s + else: + self.start_hsv[2] = 1.0-y + self.start_hsv[0] = (x+1) * 180.0 + elif data['Path'] == '/sixaxis/lrud': + val=data['Value'] + vy = val[3]-val[2] + vx = val[1]-val[0] + #pdb.set_trace() + #self.v_xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1]) + self.v_xy = array((vx, vy)) * speedfactor + else: + main_log.error('Sensor Inputs: ' + str(sensorInputs)) + self.xy = self.xy + self.v_xy + constrainLocation(self.xy,self.ssize) + self.v_xy -= self.v_decay + if self.v_xy[0] < 0: + self.v_xy[0] = 0 + if self.v_xy[1] < 0: + self.v_xy[1] = 0 + ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))}) + + return (ret, []) diff --git a/behaviors/Sink.py b/behaviors/Sink.py new file mode 100644 index 0000000..52d0be2 --- /dev/null +++ b/behaviors/Sink.py @@ -0,0 +1,42 @@ + +from operationscore.Behavior import * +import math +import util.TimeOps as timeOps +#Required Args: +#Period (ms), MaxHeight, Width +class Sink(Behavior): + """RiseFall is a behavior that creates a rising and falling column of light. Specify: + -- the maximum height that it rises to. + -- the width of the column OR and + -- the period of oscillation in ms + + Designed to be used as part of a recursive hook. + """ + + def processResponse(self, sensorInputs, recurInputs): + ret = [] + for data in sensorInputs: + #first time with behavior: + data = dict(data) + if not 'StartTime' in data: + data['StartTime'] = timeOps.time() + data['Period'] = self['Period'] + data['MaxHeight'] = self['MaxHeight'] #Consider just using += + if not 'Bottom' in data: + data['Bottom'] = data['Location'][1] + if 'Width' in self: #TODO: improve + data['Width'] = self['Width'] + data['Left'] = data['Location'][0]-data['Width']/2. + data['Right'] = data['Location'][0]+data['Width']/2. + currentTime = timeOps.time() + deltaTime = currentTime-data['StartTime'] + data['Height'] = data['MaxHeight']*math.cos(deltaTime/data['Period']*(math.pi*2)) + + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ + "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ + {y}>"+str(data['Bottom']-data['Height']) + + ret.append(data) + return (ret, []) + + diff --git a/behaviors/SynchTest.py b/behaviors/SynchTest.py new file mode 100644 index 0000000..e7b8acc --- /dev/null +++ b/behaviors/SynchTest.py @@ -0,0 +1,12 @@ +from operationscore.Behavior import * +from pixelevents.SynchTestEvent import * +import pdb +class SynchTest(Behavior): + def behaviorInit(self): + self.rendered = False + def processResponse(self, sensorInputs, recurs): + if not self.rendered: + self.rendered = True + print 'here1' + return ([{'Location':'True', 'PixelEvent':SynchTestEvent({'Color':(255,0,0)})}], []) + return ([], []) -- cgit v1.2.3