예제 #1
0
    def makeSurf(self,size):#size is the size of the base square
        outSize = size * 5/4
        holeStart = size/4
        holeEnd = size/4 * 3

        self.offset = ( -size/4 , -size/4 )

        self.baseSurf = pygame.Surface( (outSize,outSize) , SRCALPHA)
        self.staticSurf = None
        pointsTop = [ #borders around
                      (0,0) ,
                      (size,0) ,
                      (size,size),
                      (0,size) ,
                      (0,0) ,
                      #hole in the middle
                      (holeStart,holeStart),
                      (holeStart,holeEnd),
                      (holeEnd,holeEnd),
                      (holeEnd,holeStart),
                      (holeStart,holeStart)]
        pointsRight = [ (size,0) ,
                        (outSize,outSize-size) ,
                        (outSize,outSize),
                        (size,size) ]
        pointsFront = [ (0,size) ,
                        (outSize-size,outSize) ,
                        (outSize,outSize),
                        (size,size) ]
        pointsHoleLeft = [ (holeStart,holeStart) ,
                           (holeEnd,holeEnd) ,
                           (holeStart,holeEnd) ]
        pointsHoleTop = [ (holeStart,holeStart) ,
                           (holeEnd,holeEnd) ,
                           (holeEnd,holeStart) ]
        
        baseArrowPoints = [ (size/4+size/16,0),
                            (size/2-size/16,size/4),
                            (size/2-size/16,-size/4)]
        pointsArrow = util.translatePoints( util.rotatePoints( baseArrowPoints , self.orient*math.pi/2 ) , (size/2,size/2) )
        
        #colors
        colBase  = g.color.getForCell(self.color,"base")
        colRight = g.color.getForCell(self.color,"right")
        colFront = g.color.getForCell(self.color,"front")
        colArrow = g.color.getForCell(self.color,"arrow")
        #shadow inside the hole
        pygame.draw.polygon( self.baseSurf , colRight , pointsHoleLeft )
        pygame.draw.polygon( self.baseSurf , colFront , pointsHoleTop )
        #draw the basic shape
        pygame.draw.polygon( self.baseSurf , colBase  , pointsTop )
        pygame.draw.polygon( self.baseSurf , colRight , pointsRight )
        pygame.draw.polygon( self.baseSurf , colFront , pointsFront )
        #draw inputting arrow
        if self.orient == -1:
            for i in range(4):
                pointsArrow = util.translatePoints( util.rotatePoints( baseArrowPoints , i*math.pi/2 ) , (size/2,size/2) )
                pygame.draw.polygon( self.baseSurf , colArrow , pointsArrow )
        else:
            pygame.draw.polygon( self.baseSurf , colArrow , pointsArrow )
예제 #2
0
 def makeAnimSurf(self,size,adjCell = [None,None,None,None]):
     #detect adjacent cells
     nextPresent = False
     prevPresent = False
     
     if isinstance( adjCell[self.orient] , cell.belt.Belt ):
         if adjCell[self.orient].orient == self.orient:
             nextPresent = True
     if isinstance( adjCell[(self.orient+2)%4] , cell.belt.Belt ):
         if adjCell[(self.orient+2)%4].orient == self.orient:
             prevPresent = True
             
     xSubOffset = size*0.1
     ySubOffset = size*0.1
     
     if ((self.orient == 0 and prevPresent) or (self.orient == 2 and nextPresent)):
         xSubOffset = 0
     if ((self.orient == 1 and prevPresent) or (self.orient == 3 and nextPresent)):
         ySubOffset = 0
     
     
     #build surfaces
     outSize = size * 5/4
     
     self.animSurf = pygame.Surface( (outSize,outSize) , SRCALPHA )
     
     subSurf = pygame.Surface( (size,size) , SRCALPHA )
     
     #recalculate positions
     baseArrowPoints = [ ( size* 1/18,0),
                         ( size* 5/18,size*0.15),
                         ( size* 5/18,-size*0.15)]
     listArrowsPoints=[]
     for i in range(4):
         arrow = util.translatePoints(baseArrowPoints,(size/3 * (i - self.iterAnim/50) - size/2,0) )
         arrow = util.rotatePoints(arrow, self.orient*math.pi/2 +math.pi)
         arrow = util.translatePoints(arrow, (size/2,size/2) )
         listArrowsPoints.append(arrow)
         
     #drawing arrows
     colArrow = g.color.getForCell("any","arrow")
     for i in range(4):
         pygame.draw.polygon( subSurf , colArrow , listArrowsPoints[i] )
     
     #blitting
     subSize = int(size*(0.8 + 0.1*nextPresent + 0.1*prevPresent))+1
     self.animSurf.blit( subSurf, (xSubOffset,ySubOffset) , (xSubOffset,ySubOffset,subSize,subSize) )
예제 #3
0
    def makeSurf(self,size):#size is the size of the base square
        outSize = size * 5/4
        
        self.offset = ( -size/4 , -size/4 )

        self.baseSurf = pygame.Surface( (outSize,outSize) , SRCALPHA)
        self.staticSurf = pygame.Surface( (outSize,outSize) , SRCALPHA)
        pointsTop = [ #borders around
                      (0,0) ,
                      (size,0) ,
                      (size,size),
                      (0,size) ]
        pointsRight = [ (size,0) ,
                        (outSize,outSize-size) ,
                        (outSize,outSize),
                        (size,size) ]
        pointsFront = [ (0,size) ,
                        (outSize-size,outSize) ,
                        (outSize,outSize),
                        (size,size) ]
        baseArrowPoints = [ ( size* 1/18,0),
                            ( size* 5/18,size*0.15),
                            ( size* 5/18,-size*0.15)]
        listArrowsPoints=[]
        for i in range(3):
            arrow = util.translatePoints(baseArrowPoints,(size/3 * i - size/2,0) )
            arrow = util.rotatePoints(arrow, self.orient*math.pi/2 +math.pi)
            arrow = util.translatePoints(arrow, (size/2,size/2) )
            listArrowsPoints.append(arrow)

        #colors
        colBase  = g.color.getForCell("any","base")
        colRight = g.color.getForCell("any","right")
        colFront = g.color.getForCell("any","front")
        colArrow = g.color.getForCell("any","arrow")
        #draw the basic shape
        pygame.draw.polygon( self.baseSurf , colBase  , pointsTop   )
        pygame.draw.polygon( self.baseSurf , colRight , pointsRight )
        pygame.draw.polygon( self.baseSurf , colFront , pointsFront )
        #draw outputting arrow
        for i in range(3):
            pygame.draw.polygon( self.staticSurf , colArrow , listArrowsPoints[i] )
예제 #4
0
 def makeAnimSurf(self,size,adjCell = [None,None,None,None]):
     
     outSize = size * 5/4
     self.animSurf = pygame.Surface( (outSize,outSize) , SRCALPHA )
     
     dim1 = size/2
     dim2 = size/8
     points = [ (-dim1     ,-dim1     ) ,
                (-dim1+dim2,-dim1     ) ,
                (-dim1+dim2,-dim1+dim2) ,
                (-dim1     ,-dim1+dim2) ]
         
     #colors
     col  = g.color.getForCell(self.color,"activeDetector")
     
     for i in range(4):
         pts = util.translatePoints( util.rotatePoints( points, i*math.pi/2) , (dim1,dim1) )
         pygame.draw.polygon( self.animSurf , col , pts )
예제 #5
0
    def makeSurf(self,size):#size is the size of the base square
        outSize = size * 5/4
        
        self.offset = ( -size/4 , -size/4 )

        self.baseSurf   = pygame.Surface( (outSize,outSize) , SRCALPHA)
        self.staticSurf = self.baseSurf
        self.dispSurf   = self.baseSurf
        
        dim1 = size/2
        dim2 = size/8
        points = [ (-dim1     ,dim1     ) ,
                   (-dim1+dim2,dim1-dim2) ,
                   ( dim1-dim2,dim1-dim2) ,
                   ( dim1     ,dim1     ) ]
            
        #colors
        col  = g.color.getForCell(self.color,"detector")
        
        for i in range(4):
            pts = util.translatePoints( util.rotatePoints( points, i*math.pi/2) , (dim1,dim1) )
            pygame.draw.polygon( self.baseSurf , col , pts )