当前位置: 首页>>代码示例>>Python>>正文


Python Animation.load方法代码示例

本文整理汇总了Python中animation.Animation.load方法的典型用法代码示例。如果您正苦于以下问题:Python Animation.load方法的具体用法?Python Animation.load怎么用?Python Animation.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在animation.Animation的用法示例。


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

示例1: load

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import load [as 别名]
 def load(self, conf_path):
     dirname = os.path.dirname(conf_path)
     with open(conf_path, 'r') as fd:
         conf = json.load(fd)
         self.conf = conf['sprite']
         self.name = self.conf['name']
         self.texture = QtGui.QImage(
             dirname + '/' + self.conf['texture_path'])
         for anim_conf in self.conf['animations']:
             anim = Animation.load(anim_conf, self.texture)
             self.animations[anim.name] = anim
开发者ID:touilleMan,项目名称:yundong,代码行数:13,代码来源:sprite.py

示例2: load_ani

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import load [as 别名]
def load_ani(files):
	ani = Animation()
	ani.load(files)
	return ani
开发者ID:mikezucc,项目名称:augmented-reality-fighter-pygame,代码行数:6,代码来源:starter.py

示例3: AnimFont

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import load [as 别名]
class AnimFont(Font):
    """An animated Font with multiple frames per letter.
    
    Fonts can be loaded manually, using :meth:`load`, or with the :func:`font_named` utility function
    which supports searching a font path."""
        
    frames = None
    current = 0

    def __init__(self, filename=None):
        super(AnimFont, self).__init__()
        self.frames = list()
        self.current = 0
        self.__anim = Animation()
        if filename != None:
            self.load(filename)
        
    def load(self, filename): 
        """Loads the font from a ``.dmd`` file (see :meth:`Animation.load`).
        Fonts are stored in .dmd files with frame 0 containing the bitmap data
        and frame 1 containing the character widths.  96 characters (32..127,
        ASCII printables) are stored in a 10x10 grid, starting with space (``' '``) 
        in the upper left at 0, 0.  The character widths are stored in the second frame
        (index 1) within the 'raw' bitmap data in bytes 0-95; additional frames make
        up the rest of the animation.
        """
        (font_info_file, ext) = os.path.splitext(filename)

        if(ext == '.dmd'):
            composite_op = 'blacksrc'
        else:
            composite_op = None
        self.__anim.load(filename, composite_op=composite_op)

        if len(self.__anim.frames) < 1:
            raise ValueError, "Expected a minimum 2 frames: %d" % (len(self.__anim.frames))
        
        self.frames = list(self.__anim.frames)

        font_info_file = font_info_file + ".csv"
        self.char_data = self.parseCBFGinfo(font_info_file)
        self.char_height = self.char_data['Cell Height']
        self.char_width = self.char_data['Cell Width']
        self.char_size = self.char_width
        self.char_widths = list()
        # if(char_widths==None):
        for i in range(96):
            ch = chr(int(i+ord(' ')))
            self.char_widths += [self.char_data['positions'][ch]['Base Width'] + self.char_data['positions'][ch]['Width Offset']]
        #         self.char_widths += [14] #[self.__anim.frames[1].get_font_dot(i%self.__anim.width, i/self.__anim.width)]
        #         # self.char_widths += [self.__anim.frames[1].get_font_dot(i%self.__anim.width, i/self.__anim.width)]
        #         # print("Width: %d" % self.char_widths[-1])
        # else:
        #     self.char_widths = char_widths

        # for i in range(2,len(self.__anim.frames)):
        #     self.frames.append(self.__anim.frames[i])

        return self

    def parseCBFGinfo(self, filename):
        font_data = {}
        width_file = open(filename)

        for line in width_file:
            parse = line.split(',')
            line_data = parse[0]
            if line_data == "Font Name":
                line_value = parse[1][:-1]
                font_data[line_data] = line_value                
            else:
                line_value = int(parse[1][:-1])

                if line_data.startswith('Char'):
                    char_info = line_data.split(' ')
                    char = chr(int(char_info[1]))
                    if('positions' not in font_data):
                        font_data['positions'] = {}
                    if(char in font_data['positions']):
                        place = font_data['positions'][char]
                    else:
                        place = {}
                        font_data['positions'][char] = place

                    place[char_info[2] + ' ' + char_info[3]] = line_value
                else:
                    font_data[line_data] = line_value
    
        return font_data

    def size(self, text):
        """Returns a tuple of the width and height of this text as rendered with this font."""
        x = 0
        for ch in text:
            char_offset = ord(ch) - ord(' ')
            if char_offset < 0 or char_offset >= 96:
                continue
            width = self.char_widths[char_offset]
            x += width + self.tracking
        return (x, self.char_size)
#.........这里部分代码省略.........
开发者ID:horseyhorsey,项目名称:SkeletonProcVisualPinball10,代码行数:103,代码来源:animfont.py

示例4: Font

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import load [as 别名]
class Font(object):
    """Variable-width bitmap font.
    
    Fonts can be loaded manually, using :meth:`load`, or with the :func:`font_named` utility function
    which supports searching a font path."""
    
    char_widths = None
    """Array of dot widths for each character, 0-indexed from <space>.  
    This array is populated by :meth:`load`.  You may alter this array
    in order to update the font and then :meth:`save` it."""
    
    tracking = 0
    """Number of dots to adjust the horizontal position between characters, in addition to the last character's width."""
    
    composite_op = 'copy'
    """Composite operation used by :meth:`draw` when calling :meth:`~pinproc.DMDBuffer.copy_rect`."""
    
    def __init__(self, filename=None, char_widths=None):
        super(Font, self).__init__()
        self.__anim = Animation()
        self.char_size = None
        self.bitmap = None
        if filename != None:
            self.load(filename, char_widths)
        
    def load(self, filename, char_widths = None):
        """Loads the font from a ``.dmd`` file (see :meth:`Animation.load`).
        Fonts are stored in .dmd files with frame 0 containing the bitmap data
        and frame 1 containing the character widths.  96 characters (32..127,
        ASCII printables) are stored in a 10x10 grid, starting with space (``' '``) 
        in the upper left at 0, 0.  The character widths are stored in the second frame
        within the 'raw' bitmap data in bytes 0-95.
        """
        self.__anim.load(filename, composite_op = 'blacksrc')
        if self.__anim.width != self.__anim.height:
            raise ValueError, "Width != height!"
        if len(self.__anim.frames) == 1:
            # We allow 1 frame for handmade fonts.
            # This is so that they can be loaded as a basic bitmap, have their char widths modified, and then be saved.
            print "Font animation file %s has 1 frame; adding one" % (filename)
            self.__anim.frames += [Frame(self.__anim.width, self.__anim.height)]
        elif len(self.__anim.frames) != 2:
            raise ValueError, "Expected 2 frames: %d" % (len(self.__anim.frames))
        self.char_size = self.__anim.width / 10
        self.bitmap = self.__anim.frames[0]

        self.char_widths = []
        if(char_widths==None):
            for i in range(96):
                #print 'getting widths for character number: ' + str(i)
                #print  'x ' + str(i%self.__anim.width)
                self.char_widths += [self.__anim.frames[1].get_font_dot(i%self.__anim.width, i/self.__anim.width)]
                #self.char_widths += [self.char_size] #JEK hack
        else:
            # print("font widths provided")
            self.char_widths = char_widths
            # for i in range(96):
            #   self.__anim.frames[1].set_font_dot(i%self.__anim.width, i/self.__anim.width, self.char_widths[i])
        


        return self
    
    def save(self, filename):
        """Save the font to the given path."""
        out = Animation()
        out.width = self.__anim.width
        out.height = self.__anim.height
        out.frames = [self.bitmap, Frame(out.width, out.height)]
        for i in range(96):
            out.frames[1].set_font_dot(i%self.__anim.width, i/self.__anim.width, self.char_widths[i])
        out.save_old(filename)
        
    def draw(self, frame, text, x, y):
        """Uses this font's characters to draw the given string at the given position."""
        for ch in text:
            char_offset = ord(ch) - ord(' ')
            if char_offset < 0 or char_offset >= 96:
                continue
            char_x = self.char_size * (char_offset % 10)
            char_y = self.char_size * (char_offset / 10)
            width = self.char_widths[char_offset]
            Frame.copy_rect(dst=frame, dst_x=x, dst_y=y, src=self.bitmap, src_x=char_x, src_y=char_y, width=width, height=self.char_size, op=self.composite_op)
            x += width + self.tracking
        return x
    
    def size(self, text):
        """Returns a tuple of the width and height of this text as rendered with this font."""
        x = 0
        for ch in text:
            char_offset = ord(ch) - ord(' ')
            if char_offset < 0 or char_offset >= 96:
                continue
            width = self.char_widths[char_offset]
            x += width + self.tracking
        return (x, self.char_size)
    
    def draw_in_rect(self, frame, text, rect=(0,0,128,32), anchor=AnchorCenter):
        """Draw *text* on *frame* within the given *rect*, aligned in accordance with *anchor*.
        
#.........这里部分代码省略.........
开发者ID:horseyhorsey,项目名称:SkeletonProcVisualPinball10,代码行数:103,代码来源:font.py


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