aboutsummaryrefslogtreecommitdiff
path: root/behaviors
diff options
context:
space:
mode:
Diffstat (limited to 'behaviors')
-rw-r--r--behaviors/AddPixelEvent.py26
-rw-r--r--behaviors/BehaviorChain.py5
-rw-r--r--behaviors/PixelDecay.xml11
-rw-r--r--behaviors/Square.py11
4 files changed, 50 insertions, 3 deletions
diff --git a/behaviors/AddPixelEvent.py b/behaviors/AddPixelEvent.py
index bf3cfff..7f134e1 100644
--- a/behaviors/AddPixelEvent.py
+++ b/behaviors/AddPixelEvent.py
@@ -1,4 +1,26 @@
from operationscore.Behavior import *
+import util.Strings as Strings
+from logger import main_log
class AddPixelEvent(Behavior):
- def initBehavior(self):
- className = self['Class']
+ def behaviorInit(self):
+ [module, className] = self['Class'].split('.')
+ try:
+ exec('from ' + module+'.'+className + ' import *', globals())
+ except Exception as inst:
+ main_log.error('Error importing ' + module+'.'+className+ '. Component not\
+ initialized.')
+ main_log.error(str(inst))
+ self.eventGenerator = eval('lambda args:'+className+'(args)')
+
+ #^lambda function to do generate new event (takes args)
+
+ def processResponse(self, sensors, recurses):
+ ret = []
+ for sensory in sensors:
+ outDict = {}
+ outDict[Strings.LOCATION] = sensory[Strings.LOCATION]
+ settingsDict = dict(self.argDict)
+ settingsDict['Color'] = sensory['Color']
+ outDict['PixelEvent'] = self.eventGenerator(settingsDict)
+ ret.append(outDict)
+ return (ret, recurses)
diff --git a/behaviors/BehaviorChain.py b/behaviors/BehaviorChain.py
index 0170fa8..e15bd23 100644
--- a/behaviors/BehaviorChain.py
+++ b/behaviors/BehaviorChain.py
@@ -32,3 +32,8 @@ yourself or bug russell')
self.feedback[behaviorId] = recurrence
return response
+ def appendBehavior(behavior):
+ bid = compReg.registerComponent(behavior) #register behavior (will make
+ #a new id if there isn't one)
+ self['ChainedBehaviors'].append(bid)
+
diff --git a/behaviors/PixelDecay.xml b/behaviors/PixelDecay.xml
index f9eee0d..bfe84ca 100644
--- a/behaviors/PixelDecay.xml
+++ b/behaviors/PixelDecay.xml
@@ -1,4 +1,4 @@
-<Behavior>
+<!--<Behavior>
<Class>behaviors.DecayBehavior</Class>
<Args>
<DecayType>Exponential</DecayType>
@@ -6,4 +6,13 @@
<z-index>0</z-index>
<RenderToScreen>False</RenderToScreen>
</Args>
+</Behavior>-->
+<Behavior>
+ <Class>behaviors.AddPixelEvent</Class>
+ <Args>
+ <Class>pixelevents.DecayEvent</Class>
+ <DecayType>Exponential</DecayType>
+ <Coefficient>.01</Coefficient>
+ <z-index>0</z-index>
+ </Args>
</Behavior>
diff --git a/behaviors/Square.py b/behaviors/Square.py
new file mode 100644
index 0000000..a6e9401
--- /dev/null
+++ b/behaviors/Square.py
@@ -0,0 +1,11 @@
+from operationscore.Behavior import *
+class Square(Behavior):
+ def processResponse(self, sensorInputs, recursiveInputs):
+ for sensory in sensorInputs:#TODO: consider replicating the dict
+ xLoc = sensory['Location'][0]
+ yLoc = sensory['Location'][1]
+ width = self['Width']
+ sensory['Location'] =\
+ '{x}<'+str(xLoc+width)+',{x}>'+str(xLoc-width)+\
+ ',{y}<'+str(yLoc+width)+',{y}>'+str(yLoc-width)
+ return (sensorInputs, recursiveInputs)