This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
boards:knight_s_tour:python [2014/09/14 23:27] Ozyman created |
boards:knight_s_tour:python [2014/09/14 23:28] (current) Ozyman |
||
---|---|---|---|
Line 22: | Line 22: | ||
def addChainContinents(self, | def addChainContinents(self, | ||
''' | ''' | ||
- | # this function adds continent chains. | + | # this function adds continent chains. |
''' | ''' | ||
chains = set() | chains = set() | ||
Line 75: | Line 75: | ||
return ret | return ret | ||
</ | </ | ||
+ | | ||
+ | ===Creating the PNGs=== | ||
+ | |||
+ | <code python> | ||
+ | def createPNGs(self, | ||
+ | xOrigin, yOrigin, territoriesDeleted): | ||
+ | ''' | ||
+ | Creates a PNG of a chessboard w/knights in dead squares.. | ||
+ | ''' | ||
+ | imBoard = Image.new(" | ||
+ | imFill = Image.new(" | ||
+ | imFog = Image.new(" | ||
+ | | ||
+ | #print " | ||
+ | | ||
+ | # create fill image | ||
+ | borderSize = 1; #borderSize = 3; #borders are actually twice this. | ||
+ | for x in range(self.cols*colWidth): | ||
+ | for y in range(self.rows*rowHeight): | ||
+ | row = floor(y/ | ||
+ | col = floor(x/ | ||
+ | #print x,y | ||
+ | #print im.getpixel((x, | ||
+ | #print " | ||
+ | if ((row+col) % 2 == 0): #black square | ||
+ | if (x - col*colWidth) >= borderSize and (y - row*rowHeight) >= borderSize and ((col+1)*colWidth - x) > borderSize and ((row+1)*rowHeight - y) > borderSize: | ||
+ | imFill.putpixel((x, | ||
+ | else: | ||
+ | imFill.putpixel((x, | ||
+ | else: #white square | ||
+ | if (x - col*colWidth) >= borderSize and (y - row*rowHeight) >= borderSize and ((col+1)*colWidth - x) > borderSize and ((row+1)*rowHeight - y) > borderSize: | ||
+ | imFill.putpixel((x, | ||
+ | else: | ||
+ | imFill.putpixel((x, | ||
+ | |||
+ | |||
+ | print " | ||
+ | #paste in the un/deleted territories to the Board Image | ||
+ | knightBorder=0 | ||
+ | print " | ||
+ | for col in range(self.cols): | ||
+ | for row in range(self.rows): | ||
+ | print territoriesDeleted | ||
+ | print [ (r,c) for (r,c) in territoriesDeleted] | ||
+ | found = [(r,c) for (r,c) in territoriesDeleted if r == row if c == col] | ||
+ | print " | ||
+ | if found: | ||
+ | print "found hole!" | ||
+ | if ((row+col) % 2 == 0): #black square | ||
+ | tileImage = self.holeDarkImage | ||
+ | else: | ||
+ | tileImage = self.holeLightImage | ||
+ | else: | ||
+ | if ((row+col) % 2 == 0): #black square | ||
+ | tileImage = self.playerDarkImage | ||
+ | #tileFImage = self.playerDarkFogImage | ||
+ | else: | ||
+ | tileImage = self.playerLightImage | ||
+ | #tileFImage = self.playerLightFogImage | ||
+ | | ||
+ | px = col*colWidth + knightBorder | ||
+ | py = row*rowHeight + knightBorder | ||
+ | imBoard.paste(tileImage, | ||
+ | | ||
+ | | ||
+ | | ||
+ | #fog now | ||
+ | for col in range(self.cols): | ||
+ | for row in range(self.rows): | ||
+ | if ((row+col) % 2 == 0): #black square | ||
+ | tileImage = self.darkFogImage | ||
+ | else: | ||
+ | tileImage = self.lightFogImage | ||
+ | | ||
+ | px = col*colWidth | ||
+ | py = row*rowHeight | ||
+ | |||
+ | imFog.paste(tileImage, | ||
+ | |||
+ | |||
+ | imBoard.save(filePath + " | ||
+ | imFill.save(filePath + " | ||
+ | imFog.save(filePath+ " | ||
+ | </ | ||