Package SmootLight :: Package layouts :: Module ZigzagLayout
[hide private]
[frames] | no frames]

Source Code for Module SmootLight.layouts.ZigzagLayout

 1  from operationscore.PixelAssembler import * 
 2  import pdb 
3 -class ZigzagLayout(PixelAssembler):
4 """ZigZagLayout is a slightly more complex layout class that makes a zig-Zag Led Pattern 5 Inheriting classes must specify zigLength, the length in lights of a of a zig 6 and zig Axis, the direction of the long X axis (X or Y). 7 EG: zig length = 4, zig Axis = X would give: 8 X-X-X-X 9 | 10 X-X-X-X 11 | 12 X-X-X-X etc."""
13 - def initLayout(self):
14 if not 'zigLength' in self.argDict: 15 raise Exception('zigLength must be defined in argDict') 16 if not 'zigAxis' in self.argDict: 17 raise Exception('zigAxis must be defined in argDict') 18 if not 'xDirection' in self.argDict: 19 self.argDict['xDirection'] = 1 #right 20 if not 'yDirection' in self.argDict: 21 self.argDict['yDirection'] = 1 #down
22 - def layoutFunc(self, lastLocation):
23 if not 'buildQueue' in self.argDict: 24 self.argDict['buildQueue'] = self.argDict['zigLength'] 25 26 newLoc = list(lastLocation) 27 if self.argDict['buildQueue'] > 1: 28 if self.argDict['zigAxis'] == 'X': 29 newLoc[0] += self.argDict['spacing'] * self.argDict['xDirection'] 30 else: 31 newLoc[1] += self.argDict['spacing'] * self.argDict['yDirection'] 32 self.argDict['buildQueue'] -= 1 33 else: 34 self.argDict['buildQueue'] = self.argDict['zigLength'] 35 if self.argDict['zigAxis'] == 'X': 36 newLoc[1] += self.argDict['spacing'] * self.argDict['yDirection'] 37 else: 38 newLoc[0] += self.argDict['spacing'] * self.argDict['xDirection'] 39 if self.argDict['zigAxis'] == 'X': 40 self.argDict['xDirection'] *= -1 41 else: 42 self.argDict['yDirection'] *= -1 43 return newLoc
44