def behaviorInit(self): action = self['Action'] modifyParamArgs = { 'ParamType': 'Sensor', 'ParamName': self['ParamName'], 'ParamOp': self['Action'] } self.locBounds = self['LocationRestriction'] self.paramModifier = ModifyParam(modifyParamArgs) xmin, ymin, xmax, ymax = compReg.getComponent('Screen').getSize() replacementDict = { '{x}': 'l[0]', '{y}': 'l[1]', '{xmin}': str(xmin), '{xmax}': str(xmax), '{ymin}': str(ymin), '{ymax}': str(ymax) } if isinstance(self.locBounds, str): for key in replacementDict: self.locBounds = self.locBounds.replace( key, replacementDict[key]) self.locEval = eval('lambda l:' + self.locBounds) elif isinstance(self.locBounds, tuple): if len(self.locBounds) != 4: raise Exception('Must be in form (xmin,yin,xmax,ymax)') else: self.locEval = lambda l:Geo.pointWithinBoundingBox(l,\ self.LocBounds)
def recalc(self): self.locBounds = self['LocationRestriction'] xmin,ymin,xmax,ymax = compReg.getComponent('Screen').size replacementDict = {'{x}':'l[0]','{y}':'l[1]', '{xmin}':str(xmin), '{xmax}':str(xmax), '{ymin}':str(ymin),'{ymax}':str(ymax)} if isinstance(self.locBounds, str) or isinstance(self.locBounds, unicode): for key in replacementDict: self.locBounds = self.locBounds.replace(key, replacementDict[key]) self.locEval = eval('lambda l:'+self.locBounds) elif isinstance(self.locBounds, tuple): if len(self.locBounds) != 4: raise Exception('Must be in form (xmin,yin,xmax,ymax)') else: self.locEval = lambda l:Geo.pointWithinBoundingBox(l,\ self.LocBounds)
def behaviorInit(self): action = self['Action'] modifyParamArgs = {'ParamType': 'Sensor', 'ParamName':self['ParamName'],'ParamOp':self['Action']} self.locBounds = self['LocationRestriction'] self.paramModifier = ModifyParam(modifyParamArgs) if isinstance(self.locBounds, str): self.locBounds = self.locBounds.replace('{x}', 'l[0]') self.locBounds = self.locBounds.replace('{y}', 'l[1]') self.locEval = eval('lambda l:'+self.locBounds) elif isinstance(self.locBounds, tuple): if len(self.locBounds) != 4: raise Exception('Must be in form (xmin,yin,xmax,ymax)') else: self.locEval = lambda l:Geo.pointWithinBoundingBox(l,\ self.LocBounds)
def behaviorInit(self): modifyParamArgs = {'ParamType': 'Sensor', 'ParamName':self['ParamName'],'ParamOp':self['Action']} self.locBounds = self['LocationRestriction'] self.paramModifier = ModifyParam(modifyParamArgs) xmin,ymin,xmax,ymax = compReg.getComponent('Screen').size replacementDict = {'{x}':'l[0]','{y}':'l[1]', '{xmin}':str(xmin), '{xmax}':str(xmax), '{ymin}':str(ymin),'{ymax}':str(ymax)} if isinstance(self.locBounds, str): for key in replacementDict: self.locBounds = self.locBounds.replace(key, replacementDict[key]) self.locEval = eval('lambda l:'+self.locBounds) elif isinstance(self.locBounds, tuple): if len(self.locBounds) != 4: raise Exception('Must be in form (xmin,yin,xmax,ymax)') else: self.locEval = lambda l:Geo.pointWithinBoundingBox(l,\ self.LocBounds)
def processResponse(self, sensorInputs, recursiveInputs): newResponses = sensorInputs ret = [] ret += newResponses for recurInput in recursiveInputs: outDict = dict(recurInput) if not 'Dir' in outDict: outDict['Dir'] = 1 #to the right if not 'StepSize' in outDict: outDict['StepSize'] = self['StepSize'] outDict['Location']= Geo.addLocations(outDict['Location'], (outDict['StepSize']*outDict['Dir'],0)) if not Geo.pointWithinBoundingBox(outDict['Location'], \ compReg.getComponent('Screen').getSize()): outDict['Dir'] *= -1 ret.append(outDict) ret += newResponses return (ret, ret)
def processResponse(self, sensorInputs, recursiveInputs): newResponses = sensorInputs ret = [] ret += newResponses for recurInput in recursiveInputs: outDict = dict(recurInput) if not 'Dir' in outDict: outDict['Dir'] = 1 #to the right if not 'StepSize' in outDict: outDict['StepSize'] = self['StepSize'] outDict['Location']= Geo.addLocations(outDict['Location'], (outDict['StepSize']*outDict['Dir'],0)) if not Geo.pointWithinBoundingBox(outDict['Location'], \ compReg.getComponent('Screen').size): outDict['Dir'] *= -1 ret.append(outDict) ret += newResponses return (ret, ret)
def recalc(self): self.locBounds = self['LocationRestriction'] xmin, ymin, xmax, ymax = compReg.getComponent('Screen').size replacementDict = { '{x}': 'l[0]', '{y}': 'l[1]', '{xmin}': str(xmin), '{xmax}': str(xmax), '{ymin}': str(ymin), '{ymax}': str(ymax) } if isinstance(self.locBounds, str) or isinstance( self.locBounds, unicode): for key in replacementDict: self.locBounds = self.locBounds.replace( key, replacementDict[key]) self.locEval = eval('lambda l:' + self.locBounds) elif isinstance(self.locBounds, tuple): if len(self.locBounds) != 4: raise Exception('Must be in form (xmin,yin,xmax,ymax)') else: self.locEval = lambda l:Geo.pointWithinBoundingBox(l,\ self.LocBounds)