aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-01-28 09:50:38 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-01-28 09:50:38 -0500
commit3319a58ecc391f9aac092ade45f9f50dc2af5aa6 (patch)
tree14a10dfef67608e1759f0a5c49b0057a1addec0b
parentf103e47da5d563d1b8448bc021676ed7db0f529d (diff)
Finishing up for the demo
-rw-r--r--behaviors/Accelerate.xml2
-rw-r--r--behaviors/DimColor.xml2
-rw-r--r--behaviors/Expand.py3
-rw-r--r--behaviors/MITDoors.py7
-rw-r--r--behaviors/ResponseMover.py8
-rw-r--r--behaviors/XYMove.py1
-rw-r--r--config/6thFloor.xml2
-rw-r--r--inputs/PygameInput.py2
-rw-r--r--pixelcore/Screen.py19
9 files changed, 21 insertions, 25 deletions
diff --git a/behaviors/Accelerate.xml b/behaviors/Accelerate.xml
index f9de077..c78195b 100644
--- a/behaviors/Accelerate.xml
+++ b/behaviors/Accelerate.xml
@@ -3,6 +3,6 @@
<Args>
<ParamType>Sensor</ParamType>
<ParamName>StepSize</ParamName>
- <ParamOp>{val}*1.1</ParamOp>
+ <ParamOp>{val}*1.01</ParamOp>
</Args>
</Behavior>
diff --git a/behaviors/DimColor.xml b/behaviors/DimColor.xml
index 58b0673..ef98fee 100644
--- a/behaviors/DimColor.xml
+++ b/behaviors/DimColor.xml
@@ -3,6 +3,6 @@
<Args>
<ParamType>Sensor</ParamType>
<ParamName>Color</ParamName>
- <ParamOp>[chan*.95 for chan in {val}]</ParamOp>
+ <ParamOp>[chan*.98 for chan in {val}]</ParamOp>
</Args>
</Behavior>
diff --git a/behaviors/Expand.py b/behaviors/Expand.py
index 323e71f..f017c16 100644
--- a/behaviors/Expand.py
+++ b/behaviors/Expand.py
@@ -15,7 +15,8 @@ class Expand(Behavior):
data = dict(data)
data['Left'] -= data['ExpandRate']
data['Right'] += data['ExpandRate']
- data['Location'] = "{x}>" + str(data['Left']) + ", {x}<" + str(data['Right'])
+ data['Location'] = "{x}>" + str(data['Left']) + ", {x}<" +\
+ str(data['Right'])+", {y}<50"
ret.append(data)
return (ret, [])
diff --git a/behaviors/MITDoors.py b/behaviors/MITDoors.py
index d602a55..03bef6d 100644
--- a/behaviors/MITDoors.py
+++ b/behaviors/MITDoors.py
@@ -1,4 +1,6 @@
from operationscore.Behavior import *
+import math
+import util.ComponentRegistry as compReg
class MITDoors(Behavior):
"""MITDoors is a case-specific behavior to map keypresses to specific locations. Written for
Kuan 1/26/11 by RCOH"""
@@ -6,6 +8,11 @@ class MITDoors(Behavior):
def behaviorInit(self):
self.keymapping = {'q':[2,19], 'w':[22,36], 'e':[37,49], 'r':[52,69], 't':[76,91], 'y':[94,105],
'u':[106,117], 'i':[123,154], 'o':[158,161], 'p':[164,167], '[':[172,184]}
+ screenWidth = compReg.getComponent('Screen').getSize()[2] #(minx, miny,maxx, maxy)
+ maxKey = max([max(self.keymapping[v]) for v in self.keymapping])
+ mult = screenWidth / float(maxKey)
+ for k in self.keymapping:
+ self.keymapping[k] = [int(val*mult) for val in self.keymapping[k]]
def processResponse(self, sensorInputs, recursiveInputs):
ret = []
for data in sensorInputs:
diff --git a/behaviors/ResponseMover.py b/behaviors/ResponseMover.py
index 59e353a..3d559df 100644
--- a/behaviors/ResponseMover.py
+++ b/behaviors/ResponseMover.py
@@ -7,11 +7,5 @@ class ResponseMover(Behavior):
modulates the location."""
def processResponse(self, sensorInputs, recursiveInputs):
- newResponses = sensorInputs
- ret = []
- for recurInput in recursiveInputs:
- outDict = dict(recurInput)
- ret.append(outDict)
- ret += newResponses
- return (ret, ret)
+ return (recursiveInputs, recursiveInputs+sensorInputs)
diff --git a/behaviors/XYMove.py b/behaviors/XYMove.py
index 0ba3baf..11cee96 100644
--- a/behaviors/XYMove.py
+++ b/behaviors/XYMove.py
@@ -13,7 +13,6 @@ class XYMove(Behavior):
for loc in sensor:
oploc = dict(loc)
self.insertStepIfMissing(oploc)
- print oploc['YStep']
oploc['Location'] = Geo.addLocations((oploc['XStep'], oploc['YStep']), oploc['Location'])
ret.append(oploc)
return (ret, [])
diff --git a/config/6thFloor.xml b/config/6thFloor.xml
index 81f0c9f..ef195ec 100644
--- a/config/6thFloor.xml
+++ b/config/6thFloor.xml
@@ -186,7 +186,7 @@
<Behavior>
<Class>behaviors.BehaviorChain</Class>
<Args>
- <Id>inpexpanddim</Id>
+ <Id>doors</Id>
<Inputs>
<Id>pygamekey</Id>
</Inputs>
diff --git a/inputs/PygameInput.py b/inputs/PygameInput.py
index 399a77e..18f463d 100644
--- a/inputs/PygameInput.py
+++ b/inputs/PygameInput.py
@@ -23,7 +23,7 @@ class PygameInput(Input):
if event.key == 27:
self.die()
if self['Keyboard']:
- self.respond({'Key': event.key})
+ self.respond({'Key': event.key, 'KeyChar': chr(event.key)})
return
else:
pygame.event.post(event)
diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py
index 9a81df7..ada8d4a 100644
--- a/pixelcore/Screen.py
+++ b/pixelcore/Screen.py
@@ -22,14 +22,14 @@ class Screen:
sizeValid = False
self.pixelsSorted = False
- def addStrip(self, lS):
- self.pixelStrips.append(lS)
+ def addStrip(self, strip):
+ self.pixelStrips.append(strip)
self.sizeValid = False #keep track of whether or not our screen size has
self.pixelsSorted = False
#been invalidated by adding more pixels
def pixelsInRange(self, minX, maxX):
- """Returns (pixelIndex, pixel). Does a binary search."""
+ """Returns (pixelIndex, pixel). Does a binary search. Sorts first if neccesary."""
if not self.pixelsSorted:
self.computeXSortedPixels()
minIndex = Search.find_ge(self.xPixelLocs, minX)
@@ -48,12 +48,11 @@ class Screen:
return itertools.chain(*[strip.__iter__() for strip in \
self.pixelStrips]) #the * operator breaks the list into args
- #increment time -- This processes all queued responses. Responses generated
- #during this period are added to the queue that will be processed on the next
- #time step.
#SUBVERTING DESIGN FOR EFFICIENCY 1/24/11, RCOH -- It would be cleaner to store the time on the responses
#themselves, however, it is faster to just pass it in.
def timeStep(self, currentTime=None):
+ """Increments time -- This processes all queued responses, adding that to a queue that will
+ be processed on the next time step."""
if currentTime == None:
currentTime = timeops.time()
tempQueue = list(self.responseQueue)
@@ -66,6 +65,7 @@ class Screen:
self.responseQueue.append(responseInfo)
def getSize(self):
+ """Returns the size of the screen in the form: (minx, miny, maxx, maxy)"""
if self.sizeValid:
return self.size
(minX, minY, maxX, maxY) = (sys.maxint,sys.maxint,-sys.maxint,-sys.maxint)
@@ -79,24 +79,19 @@ class Screen:
maxY = max(y, maxY)
self.size = (0,0, maxX, maxY)
self.sizeValid = True
- print self.size
- return (0, 0, maxX+100, maxY+100) #TODO: cleaner
+ return (0, 0, maxX, maxY)
#private
def processResponse(self, responseInfo, currentTime=None): #we need to make a new dict for
#each to prevent interference
- #[strip.respond(dict(responseInfo)) for strip in self.pixelStrips]
if currentTime == None:
currentTime = timeops.time()
- print 'cachetime fail'
if type(responseInfo) != type(dict()):
pass
if 'Mapper' in responseInfo:
mapper = compReg.getComponent(responseInfo['Mapper'])
else:
mapper = compReg.getComponent(Strings.DEFAULT_MAPPER)
- #if type(mapper) != type(PixelMapper):
- # raise Exception('No default mapper specified.')
pixelWeightList = mapper.mapEvent(responseInfo['Location'], self)
main_log.debug('Screen processing response. ' + str(len(pixelWeightList)) + ' events\
generated')