aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Util.py5
-rw-r--r--pixelmappers/SimpleMapper.py32
2 files changed, 26 insertions, 11 deletions
diff --git a/Util.py b/Util.py
index 07ce545..6b01a81 100644
--- a/Util.py
+++ b/Util.py
@@ -94,10 +94,13 @@ def find_ge(a, x):
return bisect_left(a, x)
def safeColor(c):
return [min(channel,255) for channel in c]
+def convertToInt(c):
+ return [int(channel) for channel in c]
def combineColors(c1,c2):
return safeColor([c1[i]+c2[i] for i in range(min(len(c1),len(c2)))])
def multiplyColor(color, percent):
- return safeColor([channel*(percent) for channel in color])
+ color = convertToInt(color)
+ return convertToInt(safeColor([channel*(percent) for channel in color]))
#parses arguments into python objects if possible, otherwise leaves as strings
def generateArgDict(parentNode, recurse=False):
args = {}
diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py
index 7d730f1..45082b5 100644
--- a/pixelmappers/SimpleMapper.py
+++ b/pixelmappers/SimpleMapper.py
@@ -2,13 +2,25 @@ from operationscore.PixelMapper import *
import Util
class SimpleMapper(PixelMapper):
def mappingFunction(self, eventLocation, screen):
- bestDist = 10**10 #don't kill me, I'm lazy
- bestPixel = None
- for pixel in screen:
- pixelDist = Util.dist(pixel.location, eventLocation)
- if pixelDist < bestDist:
- bestPixel = pixel
- bestDist = pixelDist
- return [(bestPixel,1)]
-
-
+ if type(eventLocation) == type(tuple()):
+ bestDist = 10**10 #don't kill me, I'm lazy
+ bestPixel = None
+ for pixel in screen:
+ pixelDist = Util.dist(pixel.location, eventLocation)
+ if pixelDist < bestDist:
+ bestPixel = pixel
+ bestDist = pixelDist
+ return [(bestPixel,1)]
+ elif type(type(str)):
+ #[{x}>5,{y}<k]
+ #TODO: we should probably encapsulate this somewhere
+ ret = []
+ eventLocation = eventLocation.replace('{x}', 'pixel.location[0]')
+ eventLocation = eventLocation.replace('{y}', 'pixel.location[1]')
+ for pixel in screen:
+ try:
+ pixelValid = sum(eval(eventLocation)) == len(eventLocation)
+ ret.append((pixel, 1))
+ except:
+ raise Exception('Bad event condition')
+ return ret