Example #1
0
 def state(self, currentTime=None): 
     """Combines all PixelEvents currently active and computes the current color of
     the pixel."""
     if currentTime == None:
         currentTime = timeops.time()
     if currentTime-self.lastRenderTime < 5:
         return self.lastRender
     if self.events == []:
         self.lastRenderTime = currentTime
         return (0,0,0)
     deadEvents = []
     resultingColor = (0,0,0)
     colors = []
     for eventObj in self.events: #TODO: right color weighting code
         if len(self.events) > 50:
             main_log.error('High pixel event count!  Investigate!')
         eventTime, zindex, scale, pixelEvent = eventObj
         eventResult = pixelEvent.state(currentTime-eventTime)
         if eventResult != None:
             scaledEvent = color.multiplyColor(eventResult,scale)
             if (scaledEvent[0] + scaledEvent[1] + scaledEvent[2]) < 5:
                 pass
                 #deadEvents.append(eventObj)
             else:
                 colors.append(scaledEvent)
         else:
             deadEvents.append(eventObj)
     
     resultingColor = color.combineColors(colors)
     [self.events.remove(event) for event in deadEvents]
     resultingColor = [int(round(c)) for c in resultingColor]
     self.lastRender = tuple(resultingColor)
     self.lastRenderTime = currentTime
     return tuple(resultingColor)
Example #2
0
 def processResponse(self, sensorInputs, recursiveInputs):
     ret = []
     for sensory in sensorInputs:
         newDict = dict(sensory) 
         if self['ColorList'] != None:
             if isinstance(self['ColorList'], list):
                 newDict['Color'] = color.chooseRandomColor(self['ColorList'])  #Pick randomly
             else:
                 newDict['Color'] = self['ColorList'] #Unless there is only one
         else:
             newDict['Color'] = color.randomColor() 
         ret.append(newDict)
     return (ret, [])
Example #3
0
 def processResponse(self, sensorInputs, recursiveInputs):
     ret = []
     for sensory in sensorInputs:
         newDict = dict(sensory) 
         if self['ColorList'] != None:
             if isinstance(self['ColorList'], list):
                 newDict['Color'] = color.chooseRandomColor(self['ColorList'])  #Pick randomly
             else:
                 newDict['Color'] = self['ColorList'] #Unless there is only one
         else:
             newDict['Color'] = color.randomColor() 
         ret.append(newDict)
     #print ret
     return (ret, [])
Example #4
0
 def processResponse(self, sensorInputs, recursiveInputs):
     ret = []
     for sensory in sensorInputs:
         newDict = dict(sensory)
         newDict['Color'] = color.randomDimColor(self.argDict['Dimness'])
         ret.append(newDict)
     return (ret, [])
 def processResponse(self, sensorInputs, recursiveInputs):
     ret = []
     for sensory in sensorInputs:
         newDict = dict(sensory)
         newDict["Color"] = color.randomBrightColor()
         ret.append(newDict)
     return (ret, [])
Example #6
0
    def processResponse(self, sensorInputs, recursiveInputs):
        ret = []
        for response in sensorInputs:
            # Get the multiplier
            if self['Factor'] != None:
                factor = self['Factor']
            else:
                factor = 0.95
            # Initialize the first time
            if not 'FireflyStartColor' in response:
                response['FireflyValue'] = 1.0
                response['FireflyDir'] = 1
                response['FireflyStartColor'] = response['Color']
            else:
                # Update the current value
                if response['FireflyDir'] == 1:
                    response[
                        'FireflyValue'] = response['FireflyValue'] * factor
                    if response['FireflyValue'] <= 0.01:
                        response['FireflyValue'] = 0.01
                        response['FireflyDir'] = 0
                else:
                    response[
                        'FireflyValue'] = response['FireflyValue'] / factor
                    if response['FireflyValue'] >= 1.0:
                        response['FireflyValue'] = 1.0
                        response['FireflyDir'] = 1

            # Compute the color
            response['Color'] = colorops.multiplyColor(
                response['FireflyStartColor'], response['FireflyValue'])
            ret.append(response)
        return (ret, [])  #no direct ouput
Example #7
0
    def processResponse(self, sensorInputs, recursiveInputs):
        ret = []
        for response in sensorInputs:
            # Get the multiplier
            if self["Factor"] != None:
                factor = self["Factor"]
            else:
                factor = 0.95
            # Initialize the first time
            if not "FireflyStartColor" in response:
                response["FireflyValue"] = 1.0
                response["FireflyDir"] = 1
                response["FireflyStartColor"] = response["Color"]
            else:
                # Update the current value
                if response["FireflyDir"] == 1:
                    response["FireflyValue"] = response["FireflyValue"] * factor
                    if response["FireflyValue"] <= 0.01:
                        response["FireflyValue"] = 0.01
                        response["FireflyDir"] = 0
                else:
                    response["FireflyValue"] = response["FireflyValue"] / factor
                    if response["FireflyValue"] >= 1.0:
                        response["FireflyValue"] = 1.0
                        response["FireflyDir"] = 1

            # Compute the color
            response["Color"] = colorops.multiplyColor(response["FireflyStartColor"], response["FireflyValue"])
            ret.append(response)
        return (ret, [])  # no direct ouput
Example #8
0
    def processResponse(self, sensorInputs, recursiveInputs):
        ret = []
	index = 0
        for sensory in sensorInputs:
            newDict = dict(sensory) 
            newDict['Color'] = color.cycleColor(newDict['Location'][0], self['Increments'])
            ret.append(newDict)
	    index += 1
        return (ret, [])
Example #9
0
    def processResponse(self, sInputs, rInputs):
        simpleOut = []
        recurOut = []
        
        for data in rInputs:
            if data['Radius'] > self['MaxRadius']:
                continue
            
            data['Radius'] += self['StepSize']
            xLoc = data['CenterLoc'][0]
            yLoc = data['CenterLoc'][1]
            rad = data['Radius']
            cond = '>=' if self['Outside'] else '<='
            circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2))'+cond+str(rad)
            data['Location'] = circleStr

            simpleOut.append(data)            
            recurOut.append(data)
                        
        for data in sInputs:
            data['Radius'] = 1
            #import pdb; pdb.set_trace()
            if 'CenterLoc' in data:
                xLoc = data['CenterLoc'][0]
                yLoc = data['CenterLoc'][1]
            else:
                data['CenterLoc'] = tuple(data['Location'])
                xLoc = data['Location'][0]
                yLoc = data['Location'][1]

            #if not self['Id']+'Radius' in data:
            #    data[self['Id']+'Radius'] = self['Radius']
                
            rad = data['Radius']
            cond = '>=' if self['Outside'] else '<='
            circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2))'+cond+str(rad)
            data['Location'] = circleStr
            data['Color'] = color.randomColor() 

            simpleOut.append(data)
            recurOut.append(data)
            
        return (simpleOut, recurOut)
Example #10
0
 def scale(self,c):
     if c == 1:
         return self
     newDict = dict(self.argDict) 
     newDict['Color'] = color.multiplyColor(newDict['Color'], c)
     return self.__class__(newDict)
Example #11
0
 def scale(self, c):
     if c == 1:
         return self
     newDict = dict(self.argDict)
     newDict['Color'] = color.multiplyColor(newDict['Color'], c)
     return self.__class__(newDict)