diff options
author | eugue <eug.sun@gmail.com> | 2011-01-27 20:27:12 -0500 |
---|---|---|
committer | eugue <eug.sun@gmail.com> | 2011-01-27 20:27:12 -0500 |
commit | 6341992254c837b1d814b3eaa24b2ab3e729c8e2 (patch) | |
tree | 4cdf2f65e7a5b1d0a4be0f667754e73053af8493 | |
parent | f103e47da5d563d1b8448bc021676ed7db0f529d (diff) |
Added HTMLInput, SmootWind behavior, and a config file for testing.
-rwxr-xr-x | behaviors/SmootWind.py | 32 | ||||
-rw-r--r-- | behaviors/XYMove.py | 2 | ||||
-rwxr-xr-x | config/HTMLTest.xml | 58 | ||||
-rwxr-xr-x | config/SmootWindTest.xml | 166 | ||||
-rwxr-xr-x | inputs/HTMLInput.py | 29 | ||||
-rwxr-xr-x | pixelmappers/WindGaussianMapper.py | 18 | ||||
-rw-r--r-- | util/Geo.py | 6 |
7 files changed, 310 insertions, 1 deletions
diff --git a/behaviors/SmootWind.py b/behaviors/SmootWind.py new file mode 100755 index 0000000..bf05ab2 --- /dev/null +++ b/behaviors/SmootWind.py @@ -0,0 +1,32 @@ +from operationscore.Behavior import * +import util.ComponentRegistry as compReg + +class SmootWind(Behavior): + def behaviorInit(self): + self.mapper = None + self.xFor = None + + def processResponse(self, sensorInputs, recursiveInputs): + if self.mapper == None: + try: + self.mapper = compReg.getComponent('windgaussmap') + except KeyError: + pass + if self.xFor == None: + try: + self.xFor = compReg.getComponent('xfor') + except KeyError: + pass + + for sensory in sensorInputs: + #print sensory + # input[0] is windspeed, [1] is dir + windSpeed = sensory[0] + windDir = sensory[1] + + #print self.mapper.argDict + self.mapper.argDict['Width'] = float(windSpeed) ** 3 + self.xFor.argDict['ParamOp'] = float(windSpeed) ** 2 + #print 'Width: ' + str(self.mapper.argDict['Width']) + #print 'xFor: ' + str(self.xFor.argDict['ParamOp']) + return (sensorInputs, recursiveInputs) diff --git a/behaviors/XYMove.py b/behaviors/XYMove.py index 0ba3baf..44a93bb 100644 --- a/behaviors/XYMove.py +++ b/behaviors/XYMove.py @@ -13,7 +13,7 @@ class XYMove(Behavior): for loc in sensor: oploc = dict(loc) self.insertStepIfMissing(oploc) - print oploc['YStep'] + #print oploc['YStep'] oploc['Location'] = Geo.addLocations((oploc['XStep'], oploc['YStep']), oploc['Location']) ret.append(oploc) return (ret, []) diff --git a/config/HTMLTest.xml b/config/HTMLTest.xml new file mode 100755 index 0000000..159cec4 --- /dev/null +++ b/config/HTMLTest.xml @@ -0,0 +1,58 @@ +<LightInstallation> + <InstallationConfiguration> + <Defaults> + <PixelMapper>simplemap</PixelMapper> + </Defaults> + </InstallationConfiguration> + <PixelConfiguration> + <InheritsFrom>layouts/BasicSixStrip.xml</InheritsFrom> + </PixelConfiguration> + <PixelMapperConfiguration> + <PixelMapper> + <Class>pixelmappers.SimpleMapper</Class> + <Args> + <Id>simplemap</Id> + <CutoffDist>20</CutoffDist> + </Args> + </PixelMapper> + <PixelMapper> + <Class>pixelmappers.GaussianMapper</Class> + <Args> + <Id>gaussmap</Id> + <CutoffDist>30</CutoffDist> + <MinWeight>0.1</MinWeight> + <Width>10</Width> + <Height>1</Height> + </Args> + </PixelMapper> + </PixelMapperConfiguration> + <RendererConfiguration> + <Renderer> + <InheritsFrom>renderers/Pygame.xml</InheritsFrom> + </Renderer> + </RendererConfiguration> + <InputConfiguration> + <InputElement> + <Class>inputs.HTMLInput</Class> + <Args> + <Id>weatherinput</Id> + <Src>'http://sailing.mit.edu/weather/'</Src> + <!--<Regex>'rtWindSpeed = (\d+).*rtWindDir = (\d+)'</Regex>--> + <Regex>'rtWindSpeed = (\d+).*\s.*\s.*rtWindDir = (\d+)'</Regex> + <!--<RefreshInterval>60000</RefreshInterval>--> + </Args> + </InputElement> + </InputConfiguration> + <BehaviorConfiguration> + <Behavior> + <Class>behaviors.EchoBehavior</Class> + <Args> + <Inputs> + <Id>weatherinput</Id> + </Inputs> + <Id>echo</Id> + <RenderToScreen>False</RenderToScreen> + </Args> + </Behavior> + </BehaviorConfiguration> +</LightInstallation> diff --git a/config/SmootWindTest.xml b/config/SmootWindTest.xml new file mode 100755 index 0000000..a494720 --- /dev/null +++ b/config/SmootWindTest.xml @@ -0,0 +1,166 @@ +<!---All configuration items contain a "Class" tag specifying the python class they represent, and an "Args" tag specifying the args to be passed in.--> +<LightInstallation> + <InstallationConfiguration> + <Defaults> + <PixelMapper>simplemap</PixelMapper> + </Defaults> + </InstallationConfiguration> + <PixelConfiguration> + <InheritsFrom>layouts/60StripLayout.xml</InheritsFrom> + <!--<InheritsFrom>layouts/BasicSixStrip.xml</InheritsFrom--> + </PixelConfiguration> + <PixelMapperConfiguration> + <PixelMapper> + <Class>pixelmappers.SimpleMapper</Class> + <Args> + <Id>simplemap</Id> + <CutoffDist>20</CutoffDist> + </Args> + </PixelMapper> + <PixelMapper> + <Class>pixelmappers.GaussianMapper</Class> + <Args> + <Id>gaussmap</Id> + <CutoffDist>10</CutoffDist> + <MinWeight>0.1</MinWeight> + <Width>10</Width> + <Height>5</Height> + </Args> + </PixelMapper> + <PixelMapper> + <Class>pixelmappers.WindGaussianMapper</Class> + <Args> + <Id>windgaussmap</Id> + <CutoffDist>150</CutoffDist> + <MinWeight>0.005</MinWeight> + <Width>30</Width> + <Height>10</Height> + </Args> + </PixelMapper> + </PixelMapperConfiguration> + <RendererConfiguration> + <!--<Renderer> + <InheritsFrom>renderers/60StripSeq.xml</InheritsFrom> + </Renderer>--> + <Renderer> + <InheritsFrom>renderers/Pygame.xml</InheritsFrom> + </Renderer> + </RendererConfiguration> + <InputConfiguration> + <InputElement> + <Class>inputs.PygameInput</Class> + <Args><!--Passed as a dictionary--> + <Id>pygame</Id> + <RefreshInterval>1</RefreshInterval> + </Args> + </InputElement> + <InputElement> + <Class>inputs.HTMLInput</Class> + <Args> + <Id>weatherinput</Id> + <Src>'http://sailing.mit.edu/weather/'</Src> + <!--<Regex>'rtWindSpeed = (\d+).*rtWindDir = (\d+)'</Regex>--> + <Regex>'rtWindSpeed = (\d+).*\s.*\s.*rtWindDir = (\d+)'</Regex> + <!--<RefreshInterval>60000</RefreshInterval>--> + </Args> + </InputElement> + <InputElement> + <Class>inputs.RandomLocs</Class> + <Args> + <Id>randomLoc</Id> + </Args> + </InputElement> + </InputConfiguration> + <BehaviorConfiguration> + <Behavior Id="colorchange"> + <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom> + </Behavior> + <Behavior Id="staticcolor"> + <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom> + <Args> + <ColorList> + <Val>(100,200,255)</Val> + <Val>(50,200,255)</Val> + <Val>(0,200,255)</Val> + <Val>(0,150,255)</Val> + </ColorList> + </Args> + </Behavior> + <Behavior Id="decay"> + <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom> + </Behavior> + <Behavior> + <Class>behaviors.XYMove</Class> + <Args> + <Id>xymove</Id> + <XStep>0</XStep> + <YStep>0</YStep> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.BehaviorChain</Class> + <Args> + <Id>movebounce</Id> + <ChainedBehaviors> + <Id>xymove</Id> + <Id>yfor</Id> + <Id>xfor</Id> + </ChainedBehaviors> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.ModifyParam</Class> + <Args> + <Id>yfor</Id> + <ParamName>YStep</ParamName> + <ParamType>Sensor</ParamType> + <ParamOp>10*(2*math.sin({x}/float(100))+math.sin({x}/float(50)))</ParamOp> + </Args> + </Behavior> + + <Behavior> + <Class>behaviors.ModifyParam</Class> + <Args> + <Id>xfor</Id> + <ParamName>XStep</ParamName> + <ParamType>Sensor</ParamType> + <!--<ParamOp>75</ParamOp>--> + <ParamOp>25</ParamOp> + </Args> + </Behavior> + + <Behavior> + <Class>behaviors.SmootWind</Class> + <Args> + <Id>smootwind</Id> + <Inputs> + <Id>weatherinput</Id> + </Inputs> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.ResponseMover</Class> + <Args> + <Id>mover</Id> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.BehaviorChain</Class> + <Args> + <Id>xymover</Id> + <Inputs> + <Id>pygame</Id> + <Id>randomLoc</Id> + </Inputs> + <ChainedBehaviors> + <Id>staticcolor</Id> + <Id>mover</Id> + <Id>decay</Id> + </ChainedBehaviors> + <RecursiveHooks>{'mover':'movebounce'}</RecursiveHooks> + <RenderToScreen>True</RenderToScreen> + <Mapper>windgaussmap</Mapper> + </Args> + </Behavior> + </BehaviorConfiguration> +</LightInstallation> diff --git a/inputs/HTMLInput.py b/inputs/HTMLInput.py new file mode 100755 index 0000000..9697a32 --- /dev/null +++ b/inputs/HTMLInput.py @@ -0,0 +1,29 @@ +from operationscore.Input import * +import urllib, re + +""" +HTML Input, which takes 2 arguments: +- 'Src': a URL to a web page, and +- 'Regex': a Regex to parse data out of the web page. +The input parses the source code of the web page according to the regex, and processes the parsed regex groups. +""" +class HTMLInput(Input): + def inputInit(self): + self.src = self.argDict['Src'] + self.regex = self.argDict['Regex'] + + def getHTML(self): + self.sock = urllib.urlopen(self.src); + self.html = self.sock.read() + self.sock.close() + + def sensingLoop(self): + self.getHTML() + self.dataList = [] + + pattern = re.compile(self.regex) + matchObj = pattern.search(self.html) + self.dataList = matchObj.groups() + + self.respond(self.dataList) + diff --git a/pixelmappers/WindGaussianMapper.py b/pixelmappers/WindGaussianMapper.py new file mode 100755 index 0000000..c5d77ca --- /dev/null +++ b/pixelmappers/WindGaussianMapper.py @@ -0,0 +1,18 @@ +from operationscore.PixelMapper import * +import util.Geo as Geo +import math +class WindGaussianMapper(PixelMapper): + def mappingFunction(self, eventLocation, screen): + returnPixels = [] #TODO: consider preallocation and trimming + [x,y] = eventLocation + potentialPixels = screen.pixelsInRange(x-self.CutoffDist, x) + for (xloc,pixel) in screen.pixelsInRange(x-self.CutoffDist, x): + pixelDistx = math.fabs(pixel.location[0] - x) + pixelDisty = math.fabs(pixel.location[1] - y) + if pixelDistx < self.CutoffDist: + if pixelDisty < 30: + w = Geo.windtrail(pixelDistx, pixelDisty, self.Height, 0, self.Width) + if w > self.MinWeight: + returnPixels.append((pixel, w)) + + return returnPixels diff --git a/util/Geo.py b/util/Geo.py index 05ea9fe..0dde80b 100644 --- a/util/Geo.py +++ b/util/Geo.py @@ -26,3 +26,9 @@ def randomLoc(boundingBox): #TODO: make less shitty def approxexp(x): """Approximates exp with a 3 term Taylor Series.""" return 1+x+x**2/2+x**3/6 + +def windtrail(x,y,height,center,width): + a=height + b=center + c=width + return a*((math.exp(-((x-b))/(c)))**2)*(math.exp(-((y))/(0.2*c)))**2 |