aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-02-13 16:04:36 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-02-13 16:04:36 -0500
commit938a4e8b26d79b3f1935e03bde319c6d1d42e2cd (patch)
treeb96d6e6fc2f3567761a34e6bbcdd6c079249256d
parent6e0e6869a5ee1e4963071a18f24aa4dfdd442689 (diff)
parent2f0fa768ddbcc9eb7b4637d888a89d148c5cd7bf (diff)
Merge branch 'conner5' of github.com:dxiao/SmootLight into conner5
-rw-r--r--config/C5Sign.xml1
-rw-r--r--pixelmappers/C5SignMapper.py63
2 files changed, 64 insertions, 0 deletions
diff --git a/config/C5Sign.xml b/config/C5Sign.xml
index 23a823a..02bd0a2 100644
--- a/config/C5Sign.xml
+++ b/config/C5Sign.xml
@@ -210,6 +210,7 @@
<ChainedBehaviors>
<Id>colorchange</Id>
<Id>mover</Id>
+ <!--<Id>square</Id>-->
<Id>decay</Id>
</ChainedBehaviors>
<RecursiveHooks>{'mover':'movebounce'}</RecursiveHooks>
diff --git a/pixelmappers/C5SignMapper.py b/pixelmappers/C5SignMapper.py
new file mode 100644
index 0000000..b310c59
--- /dev/null
+++ b/pixelmappers/C5SignMapper.py
@@ -0,0 +1,63 @@
+from operationscore.PixelMapper import *
+import util.Geo as Geo
+import sys
+class C5SignMapper(PixelMapper):
+ """C5SignMapper is a modification to SimpleMapper which maps events to the
+ nearest Pixel. In addtion, it also maps sign artifacts (letters, logo, etc)
+ to their representative locations if given in the form "ts rs :: conditions"
+ It also supports strings of the form: {x}>5, {y}<10, {x}*{y}<{x}, etc.
+ (Conditons, separated by commas. and and or may also be used)."""
+
+ signPosition = {
+ "ls" : [(2,8), (2,14), (2,20)],
+ "ts" : [(4,22), (10,22), (16,22), (22,22), (27, 22), (33, 22), (39,22),
+ (44, 22)],
+ "rs" : [(45,2), (45, 8), (45,14), (45,20)],
+ "bs" : [(4,2), (10,2), (16,2), (22, 2), (27,2), (34,2), (39,2), (44,2)],
+ "wt" : [(12,5), (13, 5), (16,5), (18,5), (21,5), (23,5), (26,5), (27,5),
+ (30,5), (34,5), (37,5)],
+ "cl" : [(17,8), (21,10), (24,10), (26,12), (31,12)],
+ "c5" : [(6,17), (11,17), (15,17), (19,17), (22, 17), (27,17), (33,16),
+ (34, 16), (38,17), (42,17)]}
+
+ def mappingFunction(self, eventLocation, screen):
+ if type(eventLocation) == type(tuple()):
+ bestDist = sys.maxint
+ bestPixel = None
+ [x,y] = eventLocation
+ for (x,pixel) in screen.pixelsInRange(x-self['CutoffDist'], \
+ x+self['CutoffDist']):
+ pixelDist = Geo.dist(pixel.location, eventLocation)
+ if pixelDist < bestDist:
+ bestPixel = pixel
+ bestDist = pixelDist
+ if bestPixel != None:
+ return [(bestPixel,1)]
+ else:
+ return []
+ elif type(eventLocation) == type
+ else:
+ eventLocSplit = eventLocation.split(' :: ')
+ if len(eventLocSplit) == 2:
+ [signPart, eventLocation] = eventLocSplit
+ signParts = [signPosition[x] for x in signPart.split(' ')]
+
+ #{x}>5,{y}<k
+ ret = []
+ eventLocation = eventLocation.replace('{x}', 'pixel.location[0]')
+ eventLocation = eventLocation.replace('{y}', 'pixel.location[1]')
+ conditions = eventLocation.split(',')
+ conditionLambdas = [eval('lambda pixel:'+condition) for condition in conditions]
+ for pixel in screen:
+ try:
+ pixelValid = True
+ for p in conditionLambdas:
+ if p(pixel) == False:
+ pixelValid = False
+ continue
+ if pixelValid:
+ ret.append((pixel, 1))
+ except Exception as exp:
+ raise Exception('Bad event condition')
+ return ret
+