diff options
author | Russell Cohen <rcoh@mit.edu> | 2010-11-24 01:09:12 -0500 |
---|---|---|
committer | Russell Cohen <rcoh@mit.edu> | 2010-11-24 01:09:12 -0500 |
commit | b042647b68abdc82490ca6e059993b8eba28904c (patch) | |
tree | a9ee95a38e98b377c251b7b2e9af9cbd8056cf7c /layouts | |
parent | 407ac922fc4178021cf3a16dfb1bd875b6083ac4 (diff) |
Refactoring complete! Made modules/packages as appropriate. Finally.
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/LineLayout.py | 5 | ||||
-rw-r--r-- | layouts/ZigzagLayout.py | 45 | ||||
-rw-r--r-- | layouts/__init__.py | 0 |
3 files changed, 50 insertions, 0 deletions
diff --git a/layouts/LineLayout.py b/layouts/LineLayout.py new file mode 100644 index 0000000..3a8b747 --- /dev/null +++ b/layouts/LineLayout.py @@ -0,0 +1,5 @@ +from operationscore.LayoutEngine import * +#Simple layout class that simply makes a line of LEDs +class LineLayout(LayoutEngine): + def layoutFunc(self, lastLocation): + return (lastLocation[0]+self.argDict['spacing'], lastLocation[1]) diff --git a/layouts/ZigzagLayout.py b/layouts/ZigzagLayout.py new file mode 100644 index 0000000..26b27d8 --- /dev/null +++ b/layouts/ZigzagLayout.py @@ -0,0 +1,45 @@ +from operationscore.LayoutEngine import * +import pdb +#Slightly more complex layout class that makes a zig-Zag Led Pattern +#Inheriting classes must specify zigLength, the length in lights of a of a zig +#and zig Axis, the direction of the long X axis (X or Y). +#EG: zig length = 4, zig Axis = X would give: +# X-X-X-X +# | +# X-X-X-X +# | +# X-X-X-X etc. +class ZigzagLayout(LayoutEngine): + def initLayout(self): + if not 'zigLength' in self.argDict: + raise Exception('zigLength must be defined in argDict') + if not 'zigAxis' in self.argDict: + raise Exception('zigAxis must be defined in argDict') + if not 'xDirection' in self.argDict: + self.argDict['xDirection'] = 1 #right + if not 'yDirection' in self.argDict: + self.argDict['yDirection'] = 1 #down + def layoutFunc(self, lastLocation): + if not 'buildQueue' in self.argDict: + self.argDict['buildQueue'] = self.argDict['zigLength'] + + newLoc = list(lastLocation) + if self.argDict['buildQueue'] > 1: + if self.argDict['zigAxis'] == 'X': + newLoc[0] += self.argDict['spacing'] * self.argDict['xDirection'] + else: + newLoc[1] += self.argDict['spacing'] * self.argDict['yDirection'] + self.argDict['buildQueue'] -= 1 + else: + self.argDict['buildQueue'] = self.argDict['zigLength'] + if self.argDict['zigAxis'] == 'X': + newLoc[1] += self.argDict['spacing'] * self.argDict['yDirection'] + else: + newLoc[0] += self.argDict['spacing'] * self.argDict['xDirection'] + if self.argDict['zigAxis'] == 'X': + self.argDict['xDirection'] *= -1 + else: + self.argDict['yDirection'] *= -1 + return newLoc + + diff --git a/layouts/__init__.py b/layouts/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/layouts/__init__.py |