Beispiel #1
0
def test_y_smoothscale(surface):
    """Scale y axis only"""
    obj = _make_object()

    transform.set_smoothscale_backend('GENERIC')

    surface.blit(obj, (20, 20))
    obj1 = transform.smoothscale(obj, (20, 25))
    surface.blit(obj1, (80, 80))
    obj2 = transform.smoothscale(obj, (20, 35))
    surface.blit(obj2, (160, 160))
    obj3 = transform.smoothscale(obj, (20, 55))
    surface.blit(obj3, (240, 160))
    obj4 = transform.smoothscale(obj, (20, 15))
    surface.blit(obj4, (240, 240))
    obj5 = transform.smoothscale(obj, (20, 100))
    surface.blit(obj5, (320, 320))
Beispiel #2
0
def render(text, font, background, color, left, top, width, height) : 
		text_rendered = font.render(text, 1, color)
		text_height = font.get_ascent()
		text_rendered = text_rendered.subsurface(Rect(0, (text_rendered.get_height() - text_height) / 2 , text_rendered.get_width(), text_height))
		rect_rendered = text_rendered.get_rect()
#		final_rect = pygame.Rect(left, top, width, height).fit(rect_rendered)
		final_rect = rect_rendered.fit(Rect(left, top, width, height))
		background.blit(transform.smoothscale(text_rendered, (final_rect.width, final_rect.height)), Rect(left, top, final_rect.width, final_rect.height))
Beispiel #3
0
 def scale(self, size):
     # Used for changing word size
     pos = (self.rect.x, self.rect.y)
     self.image = transform.smoothscale(self.image, (int(self.rect.width*size), int(self.rect.height*size)))
     self.msf = transform.scale(self.msf, (int(self.rect.width*size), int(self.rect.height*size)))
     self.rect = self.image.get_rect()
     self.rect.x, self.rect.y = pos
     self._update_mask()
Beispiel #4
0
def get_plant_thumbnail(plant, size):
	#print "get_plant_thumbnail:", plant, size ###
	thumb = plant._thumbnail
	if not thumb:
		#print "get_plant_thumbnail: generating thumbnail" ###
		buffer = render_plant(plant, (600, 600))
		thumb = transform.smoothscale(buffer, size)
		plant._thumbnail = thumb
	return thumb
Beispiel #5
0
    def __init__(self, model):
        self.id = 'Projectile'

        self.size = (model.radius*2, model.radius*2)

        self.base_image = load_image('planet.png')
        self.image = smoothscale(self.base_image, self.size)

        self.model = model
Beispiel #6
0
 def get_border(self):
     '''if self.model.lockdown_frames > 180:
         return smoothscale(self.border4, self.size)
     elif self.model.lockdown_frames > 120:
         return smoothscale(self.border3, self.size)
     elif self.model.lockdown_frames > 60:
         return smoothscale(self.border2, self.size)
     else:
         return smoothscale(self.border1, self.size)'''
     return smoothscale(self.border4, self.size)
Beispiel #7
0
 def set_height(self, height):
     if height is not None:
         self.height = int(height)
         if self.width is None:
             self.width = self.height
         if self.picture is not None:
             self.width = self.picture.get_width()
             self.picture = smoothscale(self.picture, (self.width,self.height))
         self.radius = ((self.width*self.width+self.height*self.height)**0.5)/2
     else:
         self.height = height
Beispiel #8
0
 def set_width(self, width):
     if width is not None:
         self.width = int(width)
         if self.height is None:
             self.height = self.width
         if self.picture is not None:
             self.height = self.picture.get_height()
             self.picture = smoothscale(self.picture, (self.width,self.height))
         self.radius = ((self.width*self.width+self.height*self.height)**0.5)/2
     else:
         self.width = width
Beispiel #9
0
 def set_pic(self, pic):
     self.picture = pygame.image.load(pic).convert()
     if (self.width is not None) and (self.height is not None):
         self.picture = smoothscale(self.picture, (self.width,self.height))
         
     else:
         self.width = self.picture.get_width()
         self.height = self.picture.get_height()  
     self.radius = ((self.width*self.width+self.height*self.height)**0.5)/2
     self.shape = None
     self.color = None
def test_subsurface_smoothscale(surface):
    """Test scaling a small subsurface"""
    obj = _make_object()

    transform.set_smoothscale_backend('GENERIC')

    obj_sub = obj.subsurface((20, 20, 20, 25))

    surface.blit(obj, (20, 20))
    surface.blit(obj_sub, (60, 20))
    obj1 = transform.smoothscale(obj_sub, (obj_sub.get_width(), obj_sub.get_height()))
    surface.blit(obj1, (120, 20))
    obj1 = transform.smoothscale(obj_sub, (20, 20))
    surface.blit(obj1, (60, 60))
    obj1 = transform.smoothscale(obj_sub, (40, 40))
    surface.blit(obj1, (80, 80))
    obj1 = transform.smoothscale(obj_sub, (60, 60))
    surface.blit(obj1, (160, 160))
    obj1 = transform.smoothscale(obj_sub, (120, 120))
    surface.blit(obj1, (220, 220))
Beispiel #11
0
    def __call__(self, x, y, w, h):
        if not x in self.cache:
            self.cache[x] = {}
        if not y in self.cache[x]:
            self.cache[x][y] = {}
        if not w in self.cache[x][y]:
            self.cache[x][y][w] = {}
        if not h in self.cache[x][y][w]:
            self.cache[x][y][w][h] = transform.smoothscale(self.sprites(x, y), (w, h))

        return self.cache[x][y][w][h]
Beispiel #12
0
 def init_map_titles(self, map_tile_setting):
     tile_cache = weakref.WeakValueDictionary()
     for y, tile_row in enumerate(map_tile_setting):
         for x, tile_id in enumerate(tile_row):
             tile_id = str(tile_id)
             tile = tile_cache.get(tile_id)
             if not tile:
                 tile = self.tile_images.get(tile_id).convert_alpha()
                 tile = smoothscale(tile, (tile.get_width(), tile.get_height() / 2))
                 tile_cache[tile_id] = tile
             w, h = tile.get_width(), tile.get_height()
             self.map_tiles[(w * x, h * y)] = tile
Beispiel #13
0
 def render_back(size):
     snake = prepare.GFX["pysnakeicon"]
     rect = pygame.Rect((0, 0), size)
     back = pygame.Surface(size)
     back.fill(pygame.Color("dodgerblue"))
     s_rect = snake.get_rect().fit(rect)
     s_rect.midbottom = rect.midbottom
     snake = smoothscale(snake, s_rect.size)
     back.blit(snake, s_rect)
     pygame.draw.rect(back, pygame.Color("gray95"), rect, 4)
     pygame.draw.rect(back, pygame.Color("gray20"), rect, 1)
     return back
Beispiel #14
0
 def __init__(self, space, rect):
     super(Ball, self).__init__()
     radius = rect.width / 2
     body = Body(ball_mass, moment_for_circle(ball_mass, 0, radius))
     body.position = rect.center
     self.shape = Circle(body, radius)
     self.shape.elasticity = .5
     self.shape.friction = 0
     self.shape.layers = 1
     self.shape.collision_type = ball_type
     self.rect = pygame.Rect(0, 0, rect.width, rect.width)
     image = smoothscale(prepare.GFX.get('ball-bearing'), self.rect.size)
     self._original_image = image.convert_alpha()
    def __init__(self, loc, sub_img, upgrade_box=False):
        UIElement.__init__(self, util.enums.RES + "icons/towerbox.png", loc)
        self.subImg = image.load(util.enums.RES + sub_img).convert_alpha()
        self.upgrade = upgrade_box
        if upgrade_box:
            self.subImg = transform.smoothscale(self.subImg, (37, 32))

        if upgrade_box:
            self.sub_loc = (5, 5)
        else:
            self.sub_loc = (7, 8)

        self.draw_subimg()
Beispiel #16
0
 def update_image(self):
     image = self.front_face if self._face_up else self.back_face
     if self._rotation:
         width, height = image.get_size()
         value = 180 * cos(two_pi * self._rotation / 180.) + 180
         width *= value / 360.0
         width = int(round(max(1, abs(width)), 0))
         image = smoothscale(image, (width, int(height)))
     rect = image.get_rect(center=self.rect.center)
     self._image = image
     self.rect.size = rect.size
     self.rect.center = rect.center
     self.dirty = 1
Beispiel #17
0
    def __init__(self, model):
        self.id = 'Planet'
        
        self.model = model

        self.size = model.radius*2, model.radius*2
        
        self.base_image = load_image('planet.png')
        self.image = smoothscale(self.base_image, self.size)

        self.border4 = load_image('border4.png')
        self.border3 = load_image('border3.png')
        self.border2 = load_image('border2.png')
        self.border1 = load_image('border1.png')
Beispiel #18
0
    def _render_interface(self, interface):
        """

        :param engine.interface.Canvas interface: Interface to render
        """
        for element in interface.get_children():
            if isinstance(element, SpriteElement):
                sprite = element.sprite
                if sprite is not None:
                    try:
                        surface = transform.smoothscale(sprite, (element.width, element.height))
                    except ValueError:
                        surface = transform.scale(sprite, (element.width, element.height))
                    self.screen.blit(surface, surface.get_rect(x=element.position.x, y=element.position.y))
Beispiel #19
0
 def draw_spectrum(self, f, x):
     draw_area = Surface((1, len(f)), depth=24)
     d = surfarray.pixels3d(draw_area)
     self.peak = np.maximum(np.amax(f, axis=0), self.peak)
     a = (255 * f / self.peak[np.newaxis, :]).astype(np.uint8)
     d[0, :, 1:] = a[::-1]
     d[0, :, 0] = a[::-1, 1] / 2 + a[::-1, 0] / 2
     for m in self.markers:
         im = int((2 * m / self.sample_rate) * len(f))
         d[0, -im, 0] = 255
     del d
     it = int((2 * self.top_freq / self.sample_rate) * len(f))
     self.surface.blit(smoothscale(draw_area.subsurface((0, len(f) - it - 1, 1, it)), (1, self.size[1])), (x, 0))
     self.peak *= 2.0 ** (-1.0 / 100)
Beispiel #20
0
 def renderer(text, native_ratio=native_ratio):
     # Render the text
     raw = font.render(text, False, color).convert_alpha()
     # No native ratio case
     if native_ratio is None:
         return raw
     # Ratio between native ratio and current ratio
     current_ratio = float(self.settings.width)/self.settings.height
     ratio = current_ratio/native_ratio
     # Already native case
     if ratio == 1:
         return raw
     # Scaling
     img_size = int(raw.get_width() * ratio), raw.get_height()
     return transform.smoothscale(raw, img_size)
Beispiel #21
0
 def update(self):
     delta = self.pow / 80.0
     self.radius += self.step
     self.pow -= 1
     r = (int(self.radius),) * 2
     self.img = transform.smoothscale(Torpedo0.Blast.img, r)
     array = surfarray.pixels_alpha(self.img)
     array[:] = array[:] * delta
     self.size = r
     self.center = self.pos
     for f in enemi:
         x, y = f.center
         h2 = (self.centerx - x) ** 2 + (self.centery - y) ** 2
         if h2 < (self.radius / 2.0) ** 2:
             f.shield -= 1
def get_aa_ellipsis(size, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([size[0] * 5, size[1] * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, size)
    #fill with color using blend_rgba_max
    circle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    circle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    return circle
Beispiel #23
0
def run(args):
    tile_image = pygame.image.load(os.path.join("res", "image", "tiles", "1.png")).convert_alpha()
    tile_image = transform.smoothscale(tile_image, (256, 128))
    img = pygame.image.load(args.filepath).convert_alpha()
    #img.fill((0, 128, 0), special_flags=BLEND_MULT)
    #img = img.subsurface((0, 0, 256, 256))
    img_rect = img.get_rect()
    words_blit_pos = img_rect.topright
    background_color = args.background_color or "black"
    #mask = pygame.Surface((256, 256)).convert_alpha()
    #mask.fill((0, 0, 0, 128))

    clock = pygame.time.Clock()
    while True:
        for event in pygame.event.get(): 
            if event.type == pygame.QUIT: 
                return
            if event.type == KEYDOWN and event.key == K_ESCAPE:
                return

        #for i in xrange(4):
        #    for j in xrange(6):
        #        screen.blit(tile_image, (i * 256, j * 128))

        screen.fill(pygame.Color(background_color))
        screen.blit(img, (0, 0))

        #screen.fill(pygame.Color(background_color))
        #mask = img.copy()
        #mask.fill(pygame.Color(32, 32, 32), special_flags=BLEND_ADD)
        #img.set_alpha(128)
        #screen.blit(img, (0, 0))
        #blit_pos = (randint(0, 10), randint(0, 10))
        #blit_pos = (0, 0)
        #screen.blit(mask, blit_pos)

        mouse_pos = pygame.mouse.get_pos()
        if mouse_pos[0] > img_rect.right or mouse_pos[1] > img_rect.bottom:
            words = "outside the image"
        else:
            words = "(%s, %s)" % tuple(map(int, mouse_pos))
        info = sfg.Font.ARIAL_32.render(words, True, pygame.Color("white"))
        screen.blit(info, words_blit_pos)

        pygame.display.update()

        clock.tick(sfg.FPS)
def InterpolateToDimensions(surface, dimensions):

    return transform.smoothscale(surface, tuple(dimensions))
Beispiel #25
0
 def set_dimensions(self, w, h):
     self.image_gloves = smoothscale(self.image_gloves, (w, h))
     self.image_gloves_gif = [smoothscale(self.image_gloves_gif[i], (w, h)) for i in
                              range(len(self.image_gloves_gif))]
 def update_subimage(self, subimg):
     self.subImg = image.load(util.enums.RES + subimg).convert_alpha()
     if self.upgrade:
         self.subImg = transform.smoothscale(self.subImg, (37, 32))
     else:
         self.subImg = transform.smoothscale(self.subImg, (37, 32))
     self.draw_subimg()
Beispiel #27
-1
	def update(self):
		# First, shrink it to match res of lolshield:
		smoothscale(self.surface, (SerialShield.width, SerialShield.height), self.lol_surface)
		# clear screen (to paint leds)
		self.surface.fill(Color('black'))
		# extract value data to send:
		for x in range(SerialShield.width):
			for y in range(SerialShield.height):
				h, s, v, a, = self.lol_surface.get_at((x, y, ))
				self.set_pixel(x, y, v >= 50)
Beispiel #28
-1
def test_varied_smoothscale(surface):
    """Scale with more varies factors"""
    obj = _make_object()

    transform.set_smoothscale_backend('GENERIC')

    surface.blit(obj, (20, 20))
    obj1 = transform.smoothscale(obj, (25, 55))
    surface.blit(obj1, (80, 80))
    obj1 = transform.smoothscale(obj, (14, 13))
    surface.blit(obj1, (160, 160))
    obj1 = transform.smoothscale(obj, (72, 68))
    surface.blit(obj1, (320, 320))
Beispiel #29
-1
 def game_loop(self):
     maquina_estados = self.fsm_loop()
     for estado in maquina_estados:
         for e in pygame.event.get():
             self.input(e)
         if Game.situacao[5] == -1: self.end_game()
         estado()
         if self.fullscreen:
             smoothscale(self.screen, self.f_size, self.scaled)
             self.f_screen.blit(self.scaled, (self.px,0))
         else:
             self.f_screen.blit(self.screen, (0,0))
         pygame.display.flip()
         pygame.time.wait(20)
Beispiel #30
-1
def test_int_smoothscale(surface):
    """Simple integer scaling tests"""
    obj = _make_object()

    transform.set_smoothscale_backend('GENERIC')

    surface.blit(obj, (20, 20))
    obj1 = transform.smoothscale(obj, (20, 20))
    surface.blit(obj1, (60, 60))
    obj1 = transform.smoothscale(obj, (40, 40))
    surface.blit(obj1, (80, 80))
    obj1 = transform.smoothscale(obj, (60, 60))
    surface.blit(obj1, (160, 160))
    obj1 = transform.smoothscale(obj, (120, 120))
    surface.blit(obj1, (320, 320))
Beispiel #31
-1
def get_aa_round_rect(size, radius, color):
    surface = Surface(size, flags=SRCALPHA).convert_alpha()
    rect = Rect((0, 0), size)
    color = Color(*color)
    alpha = color.a
    color.a = 0
    rectangle = Surface(size, SRCALPHA)
    #here 5 is an arbitrary multiplier, we will just rescale later
    circle = Surface([min(size) * 5, min(size) * 5], SRCALPHA)
    draw.ellipse(circle, (0,0,0), circle.get_rect(), 0)
    circle = transform.smoothscale(circle, (2*radius, 2*radius))
    #now circle is just a small circle of radius
    #blit topleft circle:
    radius_rect = rectangle.blit(circle, (0, 0))
    #now radius_rect = Rect((0, 0), circle.size), rect=Rect((0, 0), size)
    #blit bottomright circle:
    radius_rect.bottomright = rect.bottomright #radius_rect is growing
    rectangle.blit(circle, radius_rect)
    #blit topright circle:
    radius_rect.topright = rect.topright
    rectangle.blit(circle, radius_rect)
    #blit bottomleft circle:
    radius_rect.bottomleft = rect.bottomleft
    rectangle.blit(circle, radius_rect)
    #black-fill of the internal rect
    rectangle.fill((0, 0, 0), rect.inflate(-radius_rect.w, 0))
    rectangle.fill((0, 0, 0), rect.inflate(0, -radius_rect.h))
    #fill with color using blend_rgba_max
    rectangle.fill(color, special_flags=BLEND_RGBA_MAX)
    #fill with alpha-withe using blend_rgba_min in order to make transparent
    #the
    rectangle.fill((255, 255, 255, alpha), special_flags=BLEND_RGBA_MIN)
    surface.blit(rectangle, rect.topleft)
    return surface
Beispiel #32
-1
 def render(self):
     # ~ draw magnetradius
     if self.magnetradius:
         # ~ gfxdraw.aacircle(scr,self.centerx,self.centery,int(self.magnetradius),(150,130,110,int(self.magnetradius)))
         m = image.load("img/magnetichalo.png")
         m = transform.smoothscale(m, [int(self.magnetradius * 2)] * 2)
         scr.blit(m, m.get_rect(center=self.center))
     # ~ draw shieldbar
     r = draw.rect(scr, (50, 50, 50), (10, 500, 380, 18), 1)
     osdlayer.fill((100, 100, 200, self.shieldfxttl * 4 + 150), (10, 0, self.shield_ / self.shieldmax * 380, 18))
     # scr.blit(self.SHIELDTEXT,self.SHIELDRECT)
     # ~ draw lazerstate
     r = draw.rect(scr, (50, 50, 50), (10, 520, 380, 18), 1)
     osdlayer.blit(self.lazertempfx, (10, 20), (0, 0, DoubleLazer.temper / DoubleLazer.tempmax * 380, 18))
     # scr.blit(self.LAZERTEXT,self.LAZERRECT)
     # ~ draw bonusbar
     self.settingbonus_.render()
     self.loader1_.render()
     # ~ draw shieldcircle
     if self.shieldfxttl:
         self.shieldcolor.a = int(4 * self.shieldfxttl)
         gfxdraw.filled_circle(scr, self.centerx, self.centery, self.w, self.shieldcolor)
         self.shieldfxttl -= 1
     if self.foo:
         self.foo -= 1
         scr.blit(self.img2, ship)
         return
     # ~ draw ship
     scr.blit(self.img, ship)