예제 #1
0
def load_image(filename, transparent=False):
    image = pygame.image.load(filename)
    image = image.convert()
    if transparent:
        color = image.get_at((0, 0))
        image.set_colorkey(color)
    return image
예제 #2
0
	def __init__(self,image,x,y):
		pygame.sprite.Sprite.__init__(self)

		# set the rotation cycle if it hasn't been already
		if self.rot_cycle is None:
			self.rot_cycle = [3]*10 + [-3]*10
		self.rot_cycle_pos = randint(0,len(self.rot_cycle)-1)
		self.rotation = randint(-30,30)

		# set the scale cycle if it hasn't been already
		if self.scale_cycle is None:
			steps = 5.
			self.scale_cycle = [i/steps for i in range(int(steps))] + [1.05, 1.1, 1.15, 1.1, 1.05, 1]
		self.scale_pos = 0

		# need to store original image so quality stays the same and rect doesn't get huge
		self.orig_image = image

		# make a copy of the original image that the sprite uses to draw on
		self.image = image.convert()

		self.scale = uniform(0.1,0.75)
		self.image = pygame.transform.rotozoom(self.image,self.rotation,self.scale*self.scale_pos)
		self.rect = self.image.get_rect()
		self.x = x
		self.y = y
		self.orig_center = (x,y)
예제 #3
0
 def render(self):
     screen_rect = self.get_screen_rect()
     gctx = PebbleGraphicsContext(self, None, None)
     self.harness.render(gctx)
     image = gctx.get_image()
     surface = pygame.image.fromstring(
         image.convert("RGBA").tostring(), image.size, "RGBA")
     if self.mult != 1:
         surface = pygame.transform.scale(surface, screen_rect.size)
     self.display.blit(surface.convert_alpha(self.display), screen_rect)
예제 #4
0
def load_png(path):
    """Load an image and return the image object.

    Args:
        path (str): The image file path to load.

    Returns:
        Surface: The loaded image.
    """
    try:
        image = pygame.image.load(path)
        if image.get_alpha() is None:
            image.convert()
        else:
            image.convert_alpha()
    except pygame.error as message:
        print('Cannot load image: ', path)
        raise SystemExit(message)
    return image
예제 #5
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
예제 #6
0
파일: udpong.py 프로젝트: aturley/uvd
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
예제 #7
0
def read_training(format_size=(16, 16),
                  dir_name="lane_images",
                  label_file="labels.json",
                  extrapolate=True,
                  grayscale=False):
    """
	read_training will go into dir_name and look for a file called 
	labels.json. It will then open all the images named in labels.json
	and convert them to images of size format_size.

	If extrapolate is True, then each image will be duplicated to its mirror version.
		- The mirrors of images labelled left or right will be labelled with their opposite
		direction
		- The mirrors of images labelled forward or backward will be labelled with the same
		direction.
	"""
    pathname = path.join(dir_name, label_file)
    with open(pathname, 'r') as lab:
        labels = json.load(lab)

    image_list = []
    label_list = []
    for image_name, label in labels.items():
        # First open the image in the right format
        image_file_name = path.join(dir_name, image_name)
        image = Image.open(image_file_name)
        # Resize it and adapt it to our network
        image = image.resize(format_size)
        if grayscale:
            image = image.convert("L")
        image_list.append(list(image.getdata()))
        label_list.append(label)

        if extrapolate:
            mirror_image = image.transpose(method=Image.FLIP_LEFT_RIGHT)
            image_list.append(list(mirror_image.getdata()))
            if label == 'B' or label == 'F':
                label_list.append(label)
            elif label == 'L':
                label_list.append('R')
            elif label == 'R':
                label_list.append('L')
            else:
                raise Exception("Label unknown")

    return np.array(image_list), np.array(label_list)
예제 #8
0
    def __init__(self,
                 image,
                 position,
                 startalpha,
                 endalpha,
                 playtime,
                 delay=0):
        #self.image = pygame.Surface( (image.get_width(),image.get_height()),pygame.locals.SRCALPHA)
        #self.image.blit(image,(0,0))
        self.image = image.convert()

        self.startalpha = startalpha
        self.endalpha = endalpha
        self.playtime = playtime
        if startalpha < endalpha:
            self.delta = (endalpha - startalpha) / float(playtime)
        else:
            self.delta = (startalpha - endalpha) / float(playtime)
        self.delay = delay
        self.position = position
예제 #9
0
    txt = font.render(message, True, (0, 0, 0))
    return txt.get_width()


# ------------------------------------------------------- #
#	 Loads an image and converts it to the right bit depth	#
# ------------------------------------------------------- #
def loadImage(name):
    name = os.path.join('images', name)
    try:
        image = pygame.image.load(name)
    except pygame.error, message:
        print "Failed loading image '%s', reason: '%s'" % (name, message)
        raise SystemExit, message

    image = image.convert()
    return image


screen = None
sound = None
soundsEnabled = 1
testLevelname = ""


def setScreenMode(flags, bpp):
    global screen
    screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), flags, bpp)


def enableSounds(enable):
예제 #10
0
    def __init__(self, image=None):

        if isinstance(image, Surface):
            image = Image.fromarray(surfarray.pixels3d(transform.flip(transform.rotate(image, 90), False, True)), mode="RGB")

        self.image = image.convert(mode="RGBA") if image else None
예제 #11
0
	def load(self):
		self._image = pygame.image.load(self._name)
		if self._image.get_alpha() is None:
			self._image = image.convert()
		else:
			self._image = image.convert_alpha()
예제 #12
0
파일: base.py 프로젝트: rjzaar/Speckpater
    font = pygame.font.Font(FONT_FILENAME, fontsize)    
    txt = font.render(message, True, (0,0,0))
    return txt.get_width()
	
# ------------------------------------------------------- #
#	 Loads an image and converts it to the right bit depth	#
# ------------------------------------------------------- #
def loadImage(name):
		name = os.path.join('images', name)
		try:
				image = pygame.image.load(name)
		except pygame.error, message:
				print "Failed loading image '%s', reason: '%s'" % (name, message)
				raise SystemExit, message

		image = image.convert()
		return image
				
screen = None
sound = None
soundsEnabled = 1
testLevelname = ""

def setScreenMode(flags,bpp):
		global screen
		screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), flags, bpp)
		
		
def enableSounds(enable):
		global soundsEnabled
		soundsEnabled = enable