diff options
author | dan <dmtaub@gmail.com> | 2011-01-28 16:31:58 -0500 |
---|---|---|
committer | dan <dmtaub@gmail.com> | 2011-01-28 16:31:58 -0500 |
commit | b11a72afece56dc138aac5400057668e8388f43d (patch) | |
tree | b779455122ee1987d3fcd9b51fcffa8d03057b86 /behaviors | |
parent | 6a0bfdfb00944ae0bcc6215a194c3290b4a085f2 (diff) | |
parent | b67a37ad06fa4c97dcdb32cecc71c7f492b12840 (diff) |
Merge branch 'fridaydemo' of github.com:rcoh/SmootLight into osc
Conflicts:
behaviors/ControllerOSC.py
Diffstat (limited to 'behaviors')
-rw-r--r-- | behaviors/ControllerOSC.py | 19 | ||||
-rw-r--r-- | behaviors/ExpandingColorZones.py | 7 | ||||
-rw-r--r-- | behaviors/MITDoors.py | 1 | ||||
-rw-r--r-- | behaviors/MobileShakeBehavior.py | 29 | ||||
-rw-r--r-- | behaviors/MoveBehavior.py | 7 | ||||
-rw-r--r-- | behaviors/RiseFall.py | 6 | ||||
-rw-r--r-- | behaviors/Sink.py | 42 | ||||
-rwxr-xr-x | behaviors/SmootWind.py | 24 | ||||
-rw-r--r-- | behaviors/SynchTest.py | 12 |
9 files changed, 124 insertions, 23 deletions
diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py index 0dd1b12..37102ed 100644 --- a/behaviors/ControllerOSC.py +++ b/behaviors/ControllerOSC.py @@ -7,7 +7,11 @@ import pdb import util.ComponentRegistry as compReg speedfactor = 15 +<<<<<<< HEAD vel_decay = .01 +======= +vel_decay = .00 +>>>>>>> b67a37ad06fa4c97dcdb32cecc71c7f492b12840 def constrainLocation(v,c): if v[0] > c[0]: @@ -40,11 +44,16 @@ class ControllerOSC(Behavior): #try: x = data['Value'][0] y = data['Value'][1] +<<<<<<< HEAD +======= + main_log.error(str(x)) +>>>>>>> b67a37ad06fa4c97dcdb32cecc71c7f492b12840 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 +<<<<<<< HEAD # if self.start_hsv[0] >= 360: # self.start_hsv[0] = 0 # if self.start_hsv[0] <=0: @@ -57,6 +66,12 @@ class ControllerOSC(Behavior): val=data['Value'] vy = val[3] if val[3] else -val[2] vx = -val[0] if val[0] else val[1] +======= + elif data['Path'] == '/sixaxis/lrud': + val=data['Value'] + vy = val[3]-val[2] + vx = val[1]-val[0] +>>>>>>> b67a37ad06fa4c97dcdb32cecc71c7f492b12840 #pdb.set_trace() #self.v_xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1]) self.v_xy = array((vx, vy)) * speedfactor @@ -69,7 +84,11 @@ class ControllerOSC(Behavior): self.v_xy[0] = 0 if self.v_xy[1] < 0: self.v_xy[1] = 0 +<<<<<<< HEAD ret.append({'Color':[i*256 for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))}) +======= + ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))}) +>>>>>>> b67a37ad06fa4c97dcdb32cecc71c7f492b12840 return (ret, []) diff --git a/behaviors/ExpandingColorZones.py b/behaviors/ExpandingColorZones.py index 345851e..75be761 100644 --- a/behaviors/ExpandingColorZones.py +++ b/behaviors/ExpandingColorZones.py @@ -2,13 +2,14 @@ from operationscore.Behavior import * from logger import main_log class ExpandingColorZones(Behavior): def behaviorInit(self): - self.mapping = {'r':[(132,0),(255,0,0)], 'g':[(400,0), (0,255,0)], - 'b':[(668,0), + self.mapping = {'s001':[(132,0),(255,0,0)], 's002':[(400,0), (0,255,0)], + 's003':[(668,0), (0,0,255)]} - self.mappingkey = 'KeyChar' + self.mappingkey = 'data' def processResponse(self, sensorInputs, recursiveInputs): ret = [] for data in sensorInputs: + print data data = dict(data) if self.mappingkey in data: try: diff --git a/behaviors/MITDoors.py b/behaviors/MITDoors.py index 03bef6d..cee47f0 100644 --- a/behaviors/MITDoors.py +++ b/behaviors/MITDoors.py @@ -23,5 +23,6 @@ class MITDoors(Behavior): data['Left'], data['Right'] = bounds data['Bottom'] = self['Bottom'] data['Location'] = (sum(bounds) / 2., self['Bottom']) + data['Oscillate'] = False ret.append(data) return (ret, []) diff --git a/behaviors/MobileShakeBehavior.py b/behaviors/MobileShakeBehavior.py index e25e929..b05cb5f 100644 --- a/behaviors/MobileShakeBehavior.py +++ b/behaviors/MobileShakeBehavior.py @@ -1,17 +1,26 @@ from operationscore.Behavior import * +import util.ComponentRegistry as compReg import util.Strings as Strings class MobileShakeBehavior(Behavior): + def behaviorInit(self): + self.mapper = None + def processResponse(self, sensorInputs, recursiveInputs): + if self.mapper == None: + try: + self.mapper = compReg.getComponent('mobilegaussmap') + except KeyError: + pass + #print sensorInputs - ret = [] for sInput in sensorInputs: - outDict = dict(sInput) - if 'type' in sInput and sInput['type'] == 2: - outDict['Location'] = '{x}>' + str(0) + ',{y}>' + str(0) - outDict['Color'] = [sInput['r'], sInput['g'], sInput['b']] - else: # dumb invisible pixel - outDict['Location'] = (-1, -1) - outDict['Color'] = [0, 0, 0] - ret.append(outDict) - return (ret, recursiveInputs) + if 'Shake' in sInput and sInput['Shake'] == 1: + #print 'increase!' + self.mapper.argDict['Width'] += 30 + #self.mapper.argDict['CutoffDist'] += 20 + sInput['Shake'] = 0 + print 'Width:' + str(compReg.getComponent('mobilegaussmap').argDict['Width']) + #print 'CutoffDist: '+ str(compReg.getComponent('mobilegaussmap').argDict['CutoffDist']) + + return (sensorInputs, recursiveInputs) diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index e504ca9..6e7fc6a 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -19,12 +19,13 @@ class MoveBehavior(Behavior): currDict = dict(currRecLoc) for sensorInput in sensorInputs: if 'type' in sensorInput and sensorInput['type'] == 1: + currDict['Shake'] = 0 currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ currDict['Location'][1] + sensorInput['y'] * self['YStep']) currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] - #elif sensorInput['type'] == 2: - # currDict['Shake'] = 1 - # currDict['Force'] = sensorInput['force'] + elif sensorInput['type'] == 2: + currDict['Shake'] = 1 + #currDict['Force'] = sensorInput['force'] ret.append(currDict) #print ret return (ret, ret) diff --git a/behaviors/RiseFall.py b/behaviors/RiseFall.py index 109cd10..eea2283 100644 --- a/behaviors/RiseFall.py +++ b/behaviors/RiseFall.py @@ -29,7 +29,13 @@ class RiseFall(Behavior): data['Right'] = data['Location'][0]+data['Width']/2. currentTime = timeOps.time() deltaTime = currentTime-data['StartTime'] + #if data['Oscillate'] == True: data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2)) + #else: + # data['Height'] = data['MaxHeight'] + #if (currentTime-data['StartTime']) > data['Period']: + # del data['StartTime'] + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ {y}>"+str(data['Bottom']-data['Height']) 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: + <MaxHeight> -- the maximum height that it rises to. + <Width> -- the width of the column OR <Left> and <Right> + <Period> -- 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/SmootWind.py b/behaviors/SmootWind.py index 347e2fc..804183c 100755 --- a/behaviors/SmootWind.py +++ b/behaviors/SmootWind.py @@ -22,12 +22,22 @@ class SmootWind(Behavior): for sensory in sensorInputs:
print sensory
# input[0] is windspeed, [1] is dir
- windSpeed = sensory[0]
- windDir = sensory[1]
+ if 0 in sensory and 1 in sensory:
+ windSpeed = sensory[0]
+ windDir = sensory[1]
+ #print self.mapper.argDict
+ self.mapper.argDict['Width'] = self.mapper.argDict['Width']+float(windSpeed)*2+20
+ self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+float(windSpeed)*3+10*random.random();
+ #print 'Width: ' + str(self.mapper.argDict['Width'])
+ #print 'xFor: ' + str(self.xFor.argDict['ParamOp'])
+
+ elif 'Key' in sensory:
+ if sensory['Key'] == 273:
+ self.mapper.argDict['Width'] = self.mapper.argDict['Width']+10;
+ self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+5;
+
+ elif sensory['Key'] == 274:
+ self.mapper.argDict['Width'] = self.mapper.argDict['Width']-10;
+ self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']-5;
- #print self.mapper.argDict
- self.mapper.argDict['Width'] = float(windSpeed)*2+20
- self.xFor.argDict['ParamOp'] = float(windSpeed)*3+10*random.random();
- #print 'Width: ' + str(self.mapper.argDict['Width'])
- #print 'xFor: ' + str(self.xFor.argDict['ParamOp'])
return (sensorInputs, recursiveInputs)
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 ([], []) |