diff options
author | rcoh <rcoh@mit.edu> | 2011-02-13 16:03:39 -0500 |
---|---|---|
committer | rcoh <rcoh@mit.edu> | 2011-02-13 16:03:39 -0500 |
commit | 6e0e6869a5ee1e4963071a18f24aa4dfdd442689 (patch) | |
tree | 59dfe233e69f331afe3be9137fe5638f359e1f56 /pixelmappers | |
parent | f6dd5ab92949843d2fb163e2d84f19e824a291dc (diff) |
Added a circle behavior to make circles. Added ContinuousCenterInput to do what it says. Modified
SimpleMapper a bit.
Diffstat (limited to 'pixelmappers')
-rw-r--r-- | pixelmappers/SimpleMapper.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py index 1568de3..6603c98 100644 --- a/pixelmappers/SimpleMapper.py +++ b/pixelmappers/SimpleMapper.py @@ -1,11 +1,13 @@ from operationscore.PixelMapper import * import util.Geo as Geo +import math import sys class SimpleMapper(PixelMapper): """SimpleMapper is a PixelMapper which maps events to the nearest Pixel. 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).""" + {x}>5, {y}<10, {x}*{y}<{x}, etc. (Conditions, separated by commas. Standard python syntax such + as and and or may also be + used). You may use 'math.' functions such as math.sqrt, etc. It also accepts lists of strings""" def mappingFunction(self, eventLocation, screen): if type(eventLocation) == type(tuple()): bestDist = sys.maxint @@ -24,10 +26,14 @@ class SimpleMapper(PixelMapper): else: #{x}>5,{y}<k ret = [] - eventLocation = eventLocation.replace('{x}', 'pixel.location[0]') - eventLocation = eventLocation.replace('{y}', 'pixel.location[1]') - conditions = eventLocation.split(',') + if not isinstance(eventLocation, list): + eventLocation = eventLocation.replace('{x}', 'pixel.location[0]') + eventLocation = eventLocation.replace('{y}', 'pixel.location[1]') + conditions = eventLocation.split(',') + else: + conditions = eventLocation #TODO: check for lists of strings conditionLambdas = [eval('lambda pixel:'+condition) for condition in conditions] + for pixel in screen: try: pixelValid = True @@ -38,6 +44,7 @@ class SimpleMapper(PixelMapper): if pixelValid: ret.append((pixel, 1)) except Exception as exp: + import pdb; pdb.set_trace() raise Exception('Bad event condition') return ret |