Example #1
0
 def generate(self):
     plane = Vector2(*self.icon_pos)
     angle = self.tag.angle
     r = self.tag.rect
     if 0 <= angle < 90:
         corner = Vector2(*r.bottomleft)
     elif 90<= angle < 180:
         corner = Vector2(*r.bottomright)
     elif 180 <= angle < 270:
         corner = Vector2(*r.topright)
     elif 270 <= angle < 360:
         corner = Vector2(*r.topleft)
     else:
         msg = 'Something very fishy with then angles is going on...'
         raise BaseException(msg)
     placement = Vector2(min(plane.x, corner.x), min(plane.y, corner.y))
     flip_x = True if corner.x > plane.x else False
     flip_y = True if corner.y > plane.y else False
     diff = plane-corner
     image = pygame.surface.Surface((abs(diff.x) or 3, abs(diff.y)) or 3,
                                     SRCALPHA)
     self.rect = image.get_rect()
     color = self.tag.color
     pygame.draw.aaline(image, color, (1,1), (self.rect.width-1,
                                              self.rect.height-1))
     if flip_x != flip_y:  #both flips == no flip
         image = pygame.transform.flip(image, flip_x, flip_y)
     self.image = image
     self.rect.move_ip(placement)
Example #2
0
 def rotoscale(cls, image, angle=0, factor=1, px_limit=1):
     '''
     Return an image that has been rotated CCW of 'angle' degrees, scaled
     of a 'factor' factor. If 'factor' would imply having the y axis of the
     original non-rotated image < to 'px_limit', factor is re-calculated
     to match the limit.
     '''
     #TODO: calculating the ratio should go in the initialisation code
     x, y = image.get_rect().width, image.get_rect().height
     factor = max(factor, 1.0*px_limit/y)
     if angle:
         image = pygame.transform.rotate(image, angle)
         # The rotation can potentially enlarge the bounding rectangle of
         # the sprite, filling the extra other space with alpha=0
         image = cls.crop(image, image.get_bounding_rect())
     # Calculate the actual ratio that allows not to exceed px_limit
     x, y = [int(round(v*factor)) for v in (x,y)]
     # Finally, scaling down as last operation guarantees anti-aliasing
     return pygame.transform.smoothscale(image, (x,y))
Example #3
0
def load(path, name):
    p = os.path.join(path, name)
    g_logger.info("Loading %s" % p)

    if not os.path.exists(p):
        raise error.NoImageFound(p)

    image = pygame.image.load(p).convert()

    return image, image.get_rect()
Example #4
0
def load_img(name):
    """Load an image as surface and convert it. 
	Return an image and rect object"""
    path = os.path.join(IMG_DIR, name)
    image = pygame.image.load(path)
    if image.get_alpha is None:
        image = image.convert()
    else:
        image = image.convert_alpha()
    image_rect = image.get_rect()
    return image, image_rect
Example #5
0
    def __init__(self, m_f, m_f_d, image):
        """ Custom init 
        /!\ TODO : Some check

        """
        image = pygame.image.load(image).convert_alpha()
        super(BaseAnimation,self).__init__(image.get_size(),pygame.SRCALPHA, 32)
        self.convert_alpha()
        self.blit(
            image,
            image.get_rect()
        )
        self.max_frame = m_f
        self.max_frame_delay = m_f_d
        self.frame = 0 
        self.frame_delay = 0
Example #6
0
       
# following function and class are used for the displaying of the pointer
#functions to create our resources
def load_image(name, colorkey=None):
    #fullname = os.path.join('c:\\program files\\pygame-docs\\examples\\data', name)
    fullname=name
    try:
        image = pygame.image.load(fullname).convert()
    except pygame.error, message:
        print 'Cannot load image:', name
        raise SystemExit, message
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, RLEACCEL)
    return image, image.get_rect()

def main():
    """this function is called when the program starts.
       it initializes everything it needs, then runs in
       a loop until the function returns."""
    #Initialize Everything
    #this calls the 'main' function when this script is executed
    s = Animation()
    s.initio()
    #s.imagedir = IMAGEDIR
    #s.imagedir = r'C:\_research_cleath\Documents-By-Date-and-Study\2002-09-30-Animation-project\images\bmpSmall'
    #s.imagedir = r'X:\test_label_bug\bmpLarge'
    s.imagedir = r'X:\test_label_bug\bmpSmall'
    s._initimagelist()
    #s.convertImages()
    def __init__(self, image):
        """Initialize object image and calculate rectangle"""

        self.image = image
        self.rectangle = image.get_rect()
Example #8
0
 def __init__( self, image ):
    """Initialize object image and calculate rectangle"""
    
    self.image = image
    self.rectangle = image.get_rect()
Example #9
0
WINSCORE = 4

def load_png(name):
    """ Load image and return image object"""
    fullname = os.path.join('images', name)
    try:
        image = pygame.image.load(fullname)
        if image.get_alpha() is None:
            image = image.convert()
        else:
            image = image.convert_alpha()
    except pygame.error, message:
        print 'Cannot load image:', fullname
        raise SystemExit, message
    return image, image.get_rect()

def load_snd(name):
    """ Load sound and return sound object"""
    fullname = os.path.join('sounds', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.error, message:
        print 'Cannot load sound:', fullname
        raise SystemExit, message
    return sound

class Court(pygame.Surface):
    def __init__(self, (width, height)):
        pygame.Surface.__init__(self, (width, height))