• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python transform.scale函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygame.transform.scale函数的典型用法代码示例。如果您正苦于以下问题:Python scale函数的具体用法?Python scale怎么用?Python scale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了scale函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _get_raw_shadow

 def _get_raw_shadow(self):
     target_img = self.target.get_image(self.capture_state)
     r = target_img.get_rect()
     #the shadow will be larger in order to make free space for fadeout.
     r.inflate_ip(2*self.shadow_radius, 2*self.shadow_radius)
     img = Surface(r.size)
     img.fill((255, 255, 255, 255))
     img.blit(target_img, (self.shadow_radius, self.shadow_radius))
     if self.sun_angle <= 0.:
         raise Exception("Sun angle must be greater than zero.")
     elif self.sun_angle != 45. and self.vertical:
         w, h = img.get_size()
         new_h = h / tan(self.sun_angle * pi / 180.)
         screen_size = functions.get_screen().get_size()
         new_h = abs(int(min(new_h, max(screen_size))))
         img = scale(img, (w, new_h))
     if self.angle_mode == "flip":
         img = flip(img, self.mode_value[0], self.mode_value[1])
     elif self.angle_mode == "rotate":
         img = rotate(img, self.mode_value)
     else:
         raise Exception("angle_mode not available: " + str(self.angle_mode))
     shadow = pilgraphics.get_shadow(img,
                                     radius=self.shadow_radius,
                                     black=self.black,
                                     alpha_factor=self.alpha_factor,
                                     decay_mode=self.decay_mode,
                                     color=self.color)
     return shadow
开发者ID:YannThorimbert,项目名称:ThorPy-1.0,代码行数:29,代码来源:_shadow.py


示例2: preview_img

def preview_img(screen, img):
    # generate an image preview
    square_width = 200
    square_height = 175
    (img_width, img_height) = img.get_size()
    small_img = img
    # display a preview image in dimensions that won't distort it:
    if img_width > img_height:
        if (not img_width < square_width and not img_height < square_height) or (img_width > square_width) or (img_height > square_height) or (img_width > square_width and img_height > square_height):
            r = float(img_width) / float(img_height)
            new_width = square_width
            new_height = int(new_width / r)
            scale_val = new_width, new_height
            small_img = scale(img, scale_val)
    if img_width < img_height:
        if (not img_width < square_width and not img_height < square_height) or (img_width > square_width) or (img_height > square_height) or (img_width > square_width and img_height > square_height):
            r = float(img_height) / float(img_width)
            new_height = square_height
            new_width = int(new_height / r)
            scale_val = new_width, new_height
            small_img = scale(img, scale_val)
    if img_width == img_height: 
        if (not img_width < square_width and not img_height < square_height) or (img_width > square_width) or (img_height > square_height) or (img_width > square_width and img_height > square_height):
            r = float(img_width) / float(img_height)
            new_height = square_height
            new_width = square_width
            scale_val = new_width, new_height
            small_img = scale(img, scale_val)
    (img_width, img_height) = small_img.get_size()
    return (small_img, img_width, img_height)
开发者ID:paulmadore,项目名称:luckyde,代码行数:30,代码来源:verbose.py


示例3: main

def main():
    import pygame
    from pygame import surfarray,transform
    screen_size = (DIM[0]*4,DIM[1]*4)
    screen = pygame.display.set_mode(screen_size)
    pygame.display.init()
    pygame.init()
    board = create_board(*DIM)
    board = initialize_board(
        board,
        [[5,5],[5,6]],
    )
    rate = .25
    next = time.time() -1
    small = pygame.Surface( DIM )
    blitter = pygame.Surface( screen_size )
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                raise SystemExit(0)
        if time.time() > next:
            next = time.time() + rate 
            board = cycle(board)
            surfarray.blit_array(small,board)
            transform.scale( small, screen_size, blitter )
        screen.blit( blitter, (0,0) )
        #surfarray.blit_array(screen,board)
        pygame.display.flip()
开发者ID:CodeRetreatTO,项目名称:projects,代码行数:28,代码来源:brians_numpy.py


示例4: get_surface

    def get_surface(self):
        W, H = functions.get_screen_size()
        if isinstance(self.img_path, str):  # load image
            surface = load_image(self.img_path)
        else:  # take image
            surface = self.img_path
        if 0 < self.alpha < 255:
            surface.set_alpha(self.alpha, RLEACCEL)
        if self.mode == "scale to screen":
            surface = scale(surface, (W, H))
            self.size = (W, H)
        elif self.mode == "cut to screen":
            new_surface = Surface((W, H))
            new_surface.blit(surface, (0, 0))
            self.size = (W, H)
        elif self._resized:
            surface = scale(surface, self._resized)
        elif self.mode:
            functions.debug_msg("Unrecognized mode : ", self.mode)
##        elif self._resized:
##            surface = scale(surface, self._resized)
        if self.colorkey:
            surface.set_colorkey(self.colorkey, RLEACCEL)
        surface.set_clip(self.clip)
        if self.alpha < 255:
            return surface.convert_alpha()
        else:
            return surface.convert()
开发者ID:YannThorimbert,项目名称:ThorPy-1.0,代码行数:28,代码来源:imageframe.py


示例5: drawMapView

 def drawMapView(self, surface, increment = 1):
     """Drawing the Map with Player and Beetles"""
     beetle_color_vect=["beetle_right.png","beetle_left.png","beetle_up.png","beetle_down.png"]
     life_imm=["./start_end/life_empty.png","./start_end/life_last.png","./start_end/life_mid.png","./start_end/life_full.png"]
     surface.blit(self.mp.getMapView(self.viewRect), ORIGIN)
     
     for i in range(number_beetles):
         imagePath_2=os.path.join("sprites", beetle_color_vect[beetle[i].color])
         img_2=pg.image.load(imagePath_2)
         image_2=scale(img_2, beetle[i].size)
         image_2.convert()
         surface.blit(image_2,beetle[i].position)
 
     imagePath = os.path.join("sprites", player.color)
     img = pg.image.load(imagePath)
     image=scale(img, player.size)
     image.convert()
             #surface.blit(image,player.position)
         #if(self.index_life>0):
     surface.blit(image,player.position)
         #else:
             #print 'todo: add image of damage'
         
     image_life = pg.image.load(life_imm[player.life])
     image_life.convert()
     surface.blit(image_life, ORIGIN)
开发者ID:Antunello,项目名称:HopFrog,代码行数:26,代码来源:HopFrog.py


示例6: activate

    def activate(self):
        GameState.activate(self)

        w, h = sd.get_size()

        self.cr_open = scale(res.loadImage("open.png", 0, 1), (20,30))
        self.cr_grasp = scale(res.loadImage("grasp.png", 0, 1), (20, 25))
        self.cr_arrow = res.loadImage("next_arrow.png", 0, 1)

        self.cr = KeyCursor(self.cr_open)
        self.cr_state = HAND_OPEN

        self.cr_bounds = Rect(0,0,w,h).inflate(-w*.2, -h*.2)
        self.cr_bounds.height -= 30
        self.cr_bounds.width -= 20
        self.cr_pos = list(self.cr_bounds.center)
        self.cr_speed = 0
        self.cr.enable()

        self.map_pos = self.cr_pos[:]

        path = res.mapPath("overworld3.tmx")

        self.tilemap = BufferedTilemapRenderer(path,
                       (w,h), force_colorkey=(128,0,63))

        self.camera = OverworldCamera([], self.tilemap, ((0,0), (w,h)))
        self.camera.center(self.cr_pos)
        self.tilemap.redraw()


        self.cleared = 0
开发者ID:MacLeek,项目名称:mh,代码行数:32,代码来源:overworld.py


示例7: fit_image

def fit_image(img, screen):
    "resize the image to fit the imgv window"
    rect = screen.get_rect()
    gl.SCALE_UP = 0
    if gl.REAL_WIDTH > gl.REAL_HEIGHT:
        r = float(gl.REAL_WIDTH) / float(gl.REAL_HEIGHT)
        new_width = screen.get_width()
        new_height = int(new_width / r)
        scale_val = new_width, new_height
        img = scale(img, scale_val)
        gl.SHRUNK = 1
    elif gl.REAL_WIDTH < gl.REAL_HEIGHT:
        r = float(gl.REAL_HEIGHT) / float(gl.REAL_WIDTH)
        new_height = screen.get_height()
        new_width = int(new_height / r)
        scale_val = new_width, new_height
        img = scale(img, scale_val)
        gl.SHRUNK = 1
    elif gl.REAL_WIDTH == gl.REAL_HEIGHT:
        r = float(gl.REAL_WIDTH) / float(gl.REAL_HEIGHT)
        new_height = screen.get_height()
        new_width = screen.get_width()
        if new_height > new_width:
            scale_val = int(new_width / r), int(new_width / r)
        elif new_width > new_height:
            scale_val = int(new_height / r), int(new_height / r)
        else:
            scale_val = new_width, new_height
        img = scale(img, scale_val)
    else:
        new_height = new_width = screen.get_width()
        scale_val = new_width, new_height
        img = scale(img, scale_val)
    return img
开发者ID:paulmadore,项目名称:luckyde,代码行数:34,代码来源:load_img.py


示例8: get_player_sprites

    def get_player_sprites(self, sprite_sheet):
        """Creates a dict containing all player sprites with grouped by facing. Not generally applicable."""

        # Order of sprites' facings in sprite sheet
        sprite_sheet_direction = [Direction.DOWN, Direction.LEFT, Direction.RIGHT, Direction.UP]

        sprites = {}
        for i in range(0, 12, 3):
            direction_sprites = []
            scaled_sprite_size = (self.sprite_width * self.scale_factor, self.sprite_height * self.scale_factor)

            # Get all sprites with certain alignment
            sprite_move_1 = Rect(self.get_sprite_location(i), (self.sprite_width, self.sprite_height))
            sprite_stationary = Rect(self.get_sprite_location(i + 1), (self.sprite_width, self.sprite_height))
            sprite_move_2 = Rect(self.get_sprite_location(i + 2), (self.sprite_width, self.sprite_height))

            current_direction = sprite_sheet_direction[i // 3]

            # Current sprite sheet has duplicate sprites for left and right facing, thus reordering to allow animation
            if current_direction == Direction.RIGHT or current_direction == Direction.LEFT:
                direction_sprites = [scale(sprite_sheet.subsurface(rect), scaled_sprite_size) for rect in
                                     [sprite_move_1, sprite_stationary, sprite_move_2]]
            else:
                direction_sprites = [scale(sprite_sheet.subsurface(rect), scaled_sprite_size) for rect in
                                     [sprite_move_1, sprite_move_2, sprite_stationary]]

            # Add sprites to sprite dict with alignment as key
            sprites[sprite_sheet_direction[i // 3]] = direction_sprites

        return sprites
开发者ID:Korkkii,项目名称:pokemon-drinking-game,代码行数:30,代码来源:sprites.py


示例9: __init__

 def __init__(self,imagefile,soundfile,trgtimg,trgtsnd):
     self.image = scale(image.load(imagefile), SIZE).convert()
     self.fill = scale(image.load(BASE),SIZE).convert()
     self.sound = mixer.Sound(soundfile)
     self.trgtimg = trgtimg
     self.trgtsnd = trgtsnd
     self.result = [not(self.trgtimg),not(self.trgtsnd)]
开发者ID:sfavors3,项目名称:MindMixer,代码行数:7,代码来源:mindmixer.py


示例10: update_display

def update_display():
    if DOUBLE_SIZE:
        #group.clear(screen_buffer, background)
        #dirty = group.draw(screen_buffer)
        scale(screen_buffer, (644, 406), screen)
        #pygame.transform.scale2x(screen_buffer, screen)

    pygame.display.update()
开发者ID:mikezucc,项目名称:augmented-reality-fighter-pygame,代码行数:8,代码来源:gfx.py


示例11: __init__

 def __init__(self, width, client, **kwds):
     font = self.predict_font(kwds)
     h = font.get_linesize()
     d = 2 * self.predict(kwds, "margin")
     kwds["align"] = kwds.get("align", "l")
     ScrollPanel.__init__(self, inner_width=width, **kwds)
     self.icons = {
         True: scale(folder_image, (self.row_height, self.row_height)),
         False: scale(file_image, (self.row_height, self.row_height)),
     }
     self.client = client
     self.names = []
开发者ID:germanalen,项目名称:MCEdit-Unified,代码行数:12,代码来源:file_dialogs.py


示例12: update_display

def update_display():
    if DOUBLE_SIZE:
        #group.clear(screen_buffer, background)
        #dirty = group.draw(screen_buffer)
        scale(screen_buffer, (644, 406), screen)
        #pygame.transform.scale2x(screen_buffer, screen)
    currSurf = pygame.display.get_surface()
    currSurf = pygame.Surface((644, 406), pygame.SRCALPHA, 32)
    #mask.fill
    #mask.set_alpha(255)
    #currSurf.blit(mask,(0,0),special_flags=(pygame.BLEND_RGBA_SUB))
    #self.world.view.set_background(pygame.Surface((644, 406), pygame.SRCALPHA, 32))
    pygame.display.update()
开发者ID:mikezucc,项目名称:opencv-tests,代码行数:13,代码来源:gfx.py


示例13: resize

 def resize(self):
     if self.marker <= 1:
         charRow = self.charactor.sector.idNum / NUM_COLS
         baseW, baseH = self.image.get_rect().width*3/4, self.image.get_rect().height*3/4
         self.image = trans.scale(self.image,(baseW + (baseW/3) * charRow, baseH + (baseH/3) * charRow))
     elif self.marker == 2: #red closer, first player closer
         charCol = self.charactor.sector.idNum % NUM_COLS
         baseW, baseH = self.image.get_rect().width*3/4, self.image.get_rect().height*3/4
         self.image = trans.scale(self.image,(baseW + (baseW/3) * (NUM_COLS - charCol), baseH + (baseH/3) * (NUM_COLS - charCol)))
     elif self.marker == 3: #blue closer, 
         charCol = self.charactor.sector.idNum % NUM_COLS
         baseW, baseH = self.image.get_rect().width*3/4, self.image.get_rect().height*3/4
         self.image = trans.scale(self.image,(baseW + (baseW/3) * charCol, baseH + (baseH/3) * charCol))
开发者ID:blai64,项目名称:MegamanBattleNetworkArcade,代码行数:13,代码来源:pyTest.py


示例14: command_zoom_out

def command_zoom_out(new_img, new_img_width, new_img_height, img, screen, file, num_imgs, rect, zoom_type):
    wait_cursor()
    start = start_timer()
    if new_img.get_width() >= gl.MIN_WIDTH and new_img.get_height() >= gl.MIN_HEIGHT:
        gl.ZOOM_EXP -= 1
        if zoom_type == "normal":
            gl.ZOOM_DOUBLE = 0
            new_img = scale(img, (new_img.get_width() / 1.1, new_img.get_height() / 1.1))
        else:
            gl.ZOOM_DOUBLE = 1
            new_img = scale(img, (new_img.get_width() / 2, new_img.get_height() / 2))
        rect = get_center(screen, new_img)
        my_update_screen(new_img, screen, rect, file, num_imgs, check_timer(start))
    normal_cursor()
    return (new_img, img, rect)
开发者ID:paulmadore,项目名称:luckyde,代码行数:15,代码来源:zoom.py


示例15: test_scale

def test_scale(surface):
   """Simple scale tests"""
   obj = _make_object()

   surface.blit(obj, (20, 20))
   obj1 = transform.scale(obj, (100, 100))
   surface.blit(obj1, (80, 80))
   obj2 = transform.scale(obj1, (60, 60))
   surface.blit(obj2, (160, 160))
   obj3 = transform.scale(obj, (60, 60))
   surface.blit(obj3, (240, 160))
   obj1 = transform.scale2x(obj)
   surface.blit(obj1, (240, 240))
   obj1 = transform.scale2x(obj2)
   surface.blit(obj1, (320, 320))
开发者ID:GertBurger,项目名称:pygame_cffi,代码行数:15,代码来源:test_transforms.py


示例16: overlayAHat

def overlayAHat(surf, face):
    # Draw an image of a hat on top of the face.
    width_factor, height_factor = 5/5, 3/5
    scaled_hat = transform.scale(hat, (int(width_factor*face.width), int(height_factor*face.height)))
    hat_x = int(face.left + (face.width/2) - width_factor*face.width/2)    
    hat_y = int(face.top - height_factor*face.height/2)
    surf.blit(scaled_hat, (hat_x, hat_y))
开发者ID:Foued70,项目名称:pycam,代码行数:7,代码来源:DrawAHat.py


示例17: prepare_size

 def prepare_size(self,asked_width):
     he = self.head_end
     hl = self.head_line
     hm = self.head_mid
     fe = self.foot_end
     fl = self.foot_line
     self.min_header_width = mhw = he.get_width()*2 + hm.get_width()
     self.min_footer_width = mfw = fe.get_width()*2
     cwidth,cheight = self.content_size()
     self.width = max(asked_width,cwidth,mhw,mfw)
     topgap = (self.width-self.min_header_width)/2
     bottomgap = self.width-self.min_footer_width
     self.top_line = scale(hl,(topgap,hl.get_height()))
     self.bottom_line = scale(fl,(bottomgap,fl.get_height()))
     self.headheight = he.get_height()
     self.footheight = fe.get_height()
开发者ID:scavpy,项目名称:Scav-Threads-PyWeek-Sep-2012,代码行数:16,代码来源:gui.py


示例18: update

 def update(self, platforms, new_sprites_group, player):
     
     final_lives = None
     
     # Check if we have to blink
     if self.current_lives != glo.lives:
         #~ print "Lives changed! Time to blink!"
         self.last_lives = self.current_lives
         self.current_lives = glo.lives
         self.blinking = True
         self.blink_update_counter = 0
     
     if self.blinking:
         first_period = True if (self.blink_update_counter % self.updates_per_blink) / (self.updates_per_blink / 2) else False
         self.blink_update_counter += 1
         if self.blink_update_counter == self.updates_blinking:
             self.blinking = False
         if first_period:
             final_lives = self.current_lives
         else:
             final_lives = self.last_lives
         #~ print "Blinking: final_lives = ", final_lives, "; first_period = ", first_period, "; blink_update_counter = ", self.blink_update_counter
     else:
         final_lives = glo.lives
     
     if final_lives != self.lives_in_counter:
         #~ print "Updating image!"
         self.lives_in_counter = final_lives
     # Update it every frame...
     self.image = self.get_lives_image(self.text, final_lives, scale(player.image,(12,12)), 3, self.lives_pos_offset)
开发者ID:Fenixin,项目名称:yogom,代码行数:30,代码来源:livescounter.py


示例19: ingredient_count

    def ingredient_count(self, items, money):
        # sides are at 650 and 675
        #            /1200    /900
        #            13/24   27/36
        ingredient_block = Surface((self.game_engine.width * 11/24,
                                    self.game_engine.height * 9/36))
        ingredient_block.fill((255, 255, 255))
        
        icon_size = int(ingredient_block.get_width() / (len(items) * 1.5))
        icon_width = ingredient_block.get_width() / len(items)
        j = icon_size / 3
        render_top = 15 + icon_size
        for name, count in items.items():
            icon = image.load("images/icon-%s.gif" % name).convert()
            icon = transform.scale(icon, (icon_size, icon_size))
            ingredient_block.blit(icon, (j, 10))

            # Put an item count under the icon.
            ren = self.__font.render(str(count), True, (0, 0, 0))
            fw, fh = ren.get_size()
            render_left = j + (icon_size / 2) - (fw / 2)
            ingredient_block.blit(ren, (render_left, render_top))
            j += icon_width

        ren = self.__font.render("Funds: %s" % format_money(money), True, (0, 0, 0))
        fw, fh = ren.get_size()
        render_left = ingredient_block.get_width() / 2 - fw / 2
        render_top = (ingredient_block.get_height() - render_top) / 2 + render_top
        ingredient_block.blit(ren, (render_left, render_top))

        return ingredient_block
开发者ID:FOSSRIT,项目名称:lemonade-stand,代码行数:31,代码来源:LemonadeGui.py


示例20: draw

    def draw(self):
        viewport = display.get_surface()
        if self.menu_state == "ok":
            self.menu_state = "dim_out_1"
        if self.menu_state == "dim_out_1":
            if not self.dimmer:
                self.dimmer = pygame.Surface(display.get_surface().get_size())
                self.dimmer.fill((0, 0, 0))
            self.dimmer.set_alpha(self.dim)
            self.dim += 1
            viewport.blit(self.dimmer, (0, 0))
            if self.dim > 30:
                self.menu_state = "dim_in_zoom"
                self.dimmer = None
        if self.menu_state in ("dim_in_zoom", "wait"):
            if not self.dimmer:
                self.dimmer = pygame.Surface(display.get_surface().get_size())
            scaled = transform.scale(self.screen, self.zoom_size)
            viewport.blit(scaled,
                          ((-scaled.get_width() + VWIDTH)/2,
                           (-scaled.get_height() + VHEIGHT)/2))

            self.draw_score(viewport)
            self.draw_highscores(viewport)
            self.scores.add_score(self.points)

            if self.menu_state == "dim_in_zoom":
                self.dimmer.set_alpha(self.dim)
                self.dim -= 1
                self.zoom_size[0] -= 10
                self.zoom_size[1] -= 10

            viewport.blit(self.dimmer, (0, 0))
            if self.dim < 4:
                self.menu_state = "wait"
开发者ID:bluepeppers,项目名称:me,代码行数:35,代码来源:me.py



注:本文中的pygame.transform.scale函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python transform.smoothscale函数代码示例发布时间:2022-05-25
下一篇:
Python transform.rotate函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap