User Tools

Site Tools


boards:knight_s_tour:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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,baseIDSet,value=1): #,length=2):   def addChainContinents(self,baseIDSet,value=1): #,length=2):
     '''     '''
-    # this function adds continent chains.  Just works for length=2 now+    # this function adds continent chains.
     '''     '''
     chains = set()     chains = set()
Line 75: Line 75:
     return ret     return ret
   </code>   </code>
 +  
 +===Creating the PNGs===
 +
 +<code python>
 +  def createPNGs(self, filePath, rowHeight, colWidth, 
 +                          xOrigin, yOrigin, territoriesDeleted):
 +    '''
 +    Creates a PNG of a chessboard w/knights in dead squares..
 +    '''
 +    imBoard = Image.new("RGBA", ( self.cols*colWidth,self.rows*rowHeight), (0, 0, 0, 0))
 +    imFill = Image.new("RGB", ( self.cols*colWidth,self.rows*rowHeight), "white")
 +    imFog = Image.new("RGB", ( self.cols*colWidth,self.rows*rowHeight), "white")
 +    
 +    #print "create new RGB image:", self.cols*colWidth,self.rows*rowHeight
 +    
 +    # 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/rowHeight)
 +        col = floor(x/colWidth)
 +        #print x,y
 +        #print im.getpixel((x,y))
 +        #print "putpixel",x,y
 +        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,y), (1, 1, 1)) #off color centers
 +          else:
 +            imFill.putpixel((x, y), (0, 0, 0)) 
 +        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,y), (254, 254, 254)) #off color centers
 +          else:
 +            imFill.putpixel((x, y), (255, 255, 255)) 
 +
 +
 +    print "pasting"
 +    #paste in the un/deleted territories to the Board Image
 +    knightBorder=0
 +    print "territoriesDeleted", territoriesDeleted
 +    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 "found",found
 +        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, (px, py))
 +        
 +    
 +        
 +    #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, (px, py))    
 +
 +
 +    imBoard.save(filePath + "-BOARD.png")
 +    imFill.save(filePath + "-FILLFOG.png")
 +    imFog.save(filePath+ "-FOG.png")
 +</code>
  
boards/knight_s_tour/python.1410751624.txt.gz ยท Last modified: 2014/09/14 23:27 by Ozyman