コード例 #1
0
ファイル: test_smoothscale.py プロジェクト: CTPUG/pygame_cffi
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))
コード例 #2
0
ファイル: render.py プロジェクト: konfiot/PRoq
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))
コード例 #3
0
ファイル: word.py プロジェクト: nullicorn/scwordcloudapp
 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()
コード例 #4
0
ファイル: rendering.py プロジェクト: wolmir/cristina
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
コード例 #5
0
ファイル: sprites.py プロジェクト: dmalves/galgrav
    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
コード例 #6
0
ファイル: sprites.py プロジェクト: dmalves/galgrav
 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)
コード例 #7
0
ファイル: Particles.py プロジェクト: casibbald/kamaelia
 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
コード例 #8
0
ファイル: Particles.py プロジェクト: casibbald/kamaelia
 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
コード例 #9
0
ファイル: Particles.py プロジェクト: casibbald/kamaelia
 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
コード例 #10
0
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))
コード例 #11
0
ファイル: spriteSheet.py プロジェクト: roSievers/Orbital4
    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]
コード例 #12
0
ファイル: gameworld.py プロジェクト: busuncle/renne
 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
コード例 #13
0
ファイル: cards.py プロジェクト: iminurnamez/pyroller
 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
コード例 #14
0
ファイル: playfield.py プロジェクト: paulpaterson/pyroller
 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()
コード例 #15
0
    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()
コード例 #16
0
ファイル: cards.py プロジェクト: iminurnamez/pyroller
 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
コード例 #17
0
ファイル: sprites.py プロジェクト: dmalves/galgrav
    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')
コード例 #18
0
ファイル: renderer.py プロジェクト: mtusnio/pyPlatformer
    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))
コード例 #19
0
ファイル: spectro.py プロジェクト: aarchiba/Waterfall
 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)
コード例 #20
0
ファイル: renderer.py プロジェクト: vxgmichel/pygame-mvctools
 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)
コード例 #21
0
ファイル: ship.py プロジェクト: strin/curriculum-deep-RL
 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
コード例 #22
0
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
コード例 #23
0
ファイル: image_see.py プロジェクト: busuncle/renne
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)
コード例 #24
0
def InterpolateToDimensions(surface, dimensions):

    return transform.smoothscale(surface, tuple(dimensions))
コード例 #25
0
ファイル: gloves.py プロジェクト: 1vanC1ndr1c/CoronaHero
 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))]
コード例 #26
-1
 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()
コード例 #27
-1
ファイル: pygamedemo.py プロジェクト: emdete/lolpaint
	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)
コード例 #28
-1
ファイル: test_smoothscale.py プロジェクト: CTPUG/pygame_cffi
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))
コード例 #29
-1
ファイル: __init__.py プロジェクト: robsonfr/atac-py
 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)
コード例 #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))
コード例 #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
コード例 #32
-1
ファイル: ship.py プロジェクト: strin/curriculum-deep-RL
 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)