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


Python sprites.Sprite类代码示例

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


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

示例1: create_toolbar_background

def create_toolbar_background(sprite_list, width):
    # Create the toolbar background for the selectors
    spr = Sprite(sprite_list, 0, 0,
                 svg_str_to_pixbuf(SVG().toolbar(2 * width, ICON_SIZE)))
    spr.type = 'toolbar'
    spr.set_layer(CATEGORY_LAYER)
    return spr
开发者ID:Daksh,项目名称:turtleart,代码行数:7,代码来源:taselector.py

示例2: create

    def create(self, string, attributes=None, sprites=None, file_path=None):
        if attributes is None:
            if self.spr is None:
                self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string))
            else:
                self.spr.set_image(svg_str_to_pixbuf(string))
            self.index = None
        else:
            self.shape = attributes[0]
            self.color = attributes[1]
            self.num = attributes[2]
            self.fill = attributes[3]
            self.index = self.shape * COLORS * NUMBER * FILLS + \
                self.color * NUMBER * FILLS + \
                self.num * FILLS + \
                self.fill
            if self.spr is None:
                self.spr = Sprite(sprites, 0, 0, svg_str_to_pixbuf(string))
            else:
                self.spr.set_image(svg_str_to_pixbuf(string))

            if file_path is not None:
                self.spr.set_image(load_image(file_path, self._scale), i=1,
                                   dx=int(self._scale * CARD_WIDTH * .125),
                                   dy=int(self._scale * CARD_HEIGHT * .125))
        self.spr.set_label_attributes(self._scale * 24)
        self.spr.set_label('')
开发者ID:i5o,项目名称:dimensions,代码行数:27,代码来源:card.py

示例3: Slide

class Slide(Stator):
    """ Create a sprite for a slide """
    def __init__(self, sprites, path, name, x, y, w, h, svg_engine=None,
                 function=None):
        if svg_engine is None:
            self.spr = Sprite(sprites, x, y, file_to_pixbuf(path, name, w, h))
        else:
            self.spr = Sprite(sprites, x, y,
                              svg_str_to_pixbuf(svg_engine().svg))
        self.tab_dx = [0, SWIDTH - TABWIDTH]
        self.tab_dy = [2 * SHEIGHT, 2 * SHEIGHT]
        self.tabs = []
        self.tabs.append(Tab(sprites, path, 'tab', x + self.tab_dx[0],
                             y + self.tab_dy[0], TABWIDTH, SHEIGHT))
        self.tabs.append(Tab(sprites, path, 'tab', x + self.tab_dx[1],
                             y + self.tab_dy[1], TABWIDTH, SHEIGHT))
        self.calculate = function
        self.name = name

    def add_textview(self, textview, i=0):
        self.tabs[i].textview = textview
        self.tabs[i].textbuffer = textview.get_buffer()

    def set_fixed(self, fixed):
        for tab in self.tabs:
            tab.fixed = fixed

    def match(self, sprite):
        if sprite == self.spr or sprite == self.tabs[0].spr or \
                sprite == self.tabs[1].spr:
            return True
        return False

    def draw(self, layer=1000):
        self.spr.set_layer(layer)
        self.spr.draw()
        for tab in self.tabs:
            tab.draw()

    def move(self, dx, dy):
        self.spr.move((dx, dy))
        for i, tab in enumerate(self.tabs):
            tab.move(dx + self.tab_dx[i], dy + self.tab_dy[i])

    def move_relative(self, dx, dy):
        self.spr.move_relative((dx, dy))
        for i, tab in enumerate(self.tabs):
            tab.move_relative(dx, dy)

    def hide(self):
        self.spr.hide()
        for tab in self.tabs:
            tab.hide()

    def label(self, label, i=0):
        self.tabs[i].label(label)
开发者ID:leonardcj,项目名称:slideruler,代码行数:56,代码来源:sprite_factory.py

示例4: __init__

 def __init__(self, sprites, path, name, x, y, w, h, svg_engine=None,
              calculate=None, result=None):
     if svg_engine is None:
         self.spr = Sprite(sprites, x, y, file_to_pixbuf(path, name, w, h))
     else:
         self.spr = Sprite(sprites, x, y,
                           svg_str_to_pixbuf(svg_engine().svg))
     self.spr.type = name
     self.name = name
     self.calculate = calculate
     self.result = result
开发者ID:leonardcj,项目名称:slideruler,代码行数:11,代码来源:sprite_factory.py

示例5: Stator

class Stator():
    """ Create a sprite for a stator """
    def __init__(self, sprites, path, name, x, y, w, h, svg_engine=None,
                 calculate=None, result=None):
        if svg_engine is None:
            self.spr = Sprite(sprites, x, y, file_to_pixbuf(path, name, w, h))
        else:
            self.spr = Sprite(sprites, x, y,
                              svg_str_to_pixbuf(svg_engine().svg))
        self.spr.type = name
        self.name = name
        self.calculate = calculate
        self.result = result

    def draw(self, layer=1000):
        self.spr.set_layer(layer)

    def match(self, sprite):
        if self.spr == sprite:
            return True
        return False

    def move(self, dx, dy):
        self.spr.move((dx, dy))

    def move_relative(self, dx, dy):
        self.spr.move_relative((dx, dy))

    def hide(self):
        self.spr.hide()
开发者ID:leonardcj,项目名称:slideruler,代码行数:30,代码来源:sprite_factory.py

示例6: configure_cb

    def configure_cb(self, event):
        self._width = Gdk.Screen.width()
        self._height = Gdk.Screen.height() - GRID_CELL_SIZE
        self._scale = Gdk.Screen.height() / 900.0

        # We need to resize the backgrounds
        width, height = self._calc_background_size()
        for bg in self._backgrounds.keys():
            if bg == 'custom':
                path = self._custom_dsobject.file_path
                pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                    path, width, height)
            else:
                pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
                    os.path.join(self._path, 'images', bg),
                    width, height)
            if Gdk.Screen.height() > Gdk.Screen.width():
                pixbuf = self._crop_to_portrait(pixbuf)

            self._backgrounds[bg] = pixbuf

        self._background = Sprite(self._sprites, 0, 0,
                                  self._backgrounds[self._current_bg])
        self._background.set_layer(-100)
        self._background.type = 'background'

        # and resize and reposition the bars
        self.bar.resize_all()
        self.bar.show_bar(2)
        self._current_bar = self.bar.get_bar(2)

        # Calculate a new accerlation based on screen height.
        self._ddy = (6.67 * self._height) / (STEPS * STEPS)

        self._guess_orientation()
开发者ID:Daksh,项目名称:fractionbounce,代码行数:35,代码来源:bounce.py

示例7: __init__

class Card:
    # Spade   = 1,-1
    # Heart   = 2,-2
    # Club    = 3,-3
    # Diamond = 4,-4
    def __init__(self, game, c, i, x, y):
        self.north = c[0]
        self.east = c[1]
        self.south = c[2]
        self.west = c[3]
        self.orientation = 0
        self.images = []
        self.images.append(load_image(
            os.path.join(game.path, 'card%d.svg' % (i)),
            game.card_dim * game.scale, game.card_dim * game.scale))
        for j in range(3):
            self.images.append(self.images[j].rotate_simple(90))
        # create sprite from svg file
        self.spr = Sprite(game.sprites, x, y, self.images[0])
        self.spr.set_label(i)

    def reset_image(self, game, i):
        while self.orientation != 0:
            self.rotate_ccw()

    def set_orientation(self, r, rotate_spr=True):
        while r != self.orientation:
            self.rotate_ccw(rotate_spr)

    def rotate_ccw(self, rotate_spr=True):
        # print "rotating card " + str(self.spr.label)
        tmp = self.north
        self.north = self.east
        self.east = self.south
        self.south = self.west
        self.west = tmp
        self.orientation += 90
        if self.orientation == 360:
            self.orientation = 0
        if rotate_spr is True:
            self.spr.set_shape(self.images[int(self.orientation / 90)])

    def print_card(self):
        print "(" + str(self.north) + "," + str(self.east) + \
              "," + str(self.south) + "," + str(self.west) + \
              ") " + str(self.rotate) + "ccw" + \
              " x:" + str(self.spr.x) + " y:" + str(self.spr.y)
开发者ID:sugarlabs,项目名称:cardsort,代码行数:47,代码来源:card.py

示例8: __init__

    def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
        self._activity = parent
        self._colors = colors

        self._canvas = canvas
        parent.show_all()

        self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self._canvas.connect("draw", self.__draw_cb)
        self._canvas.connect("button-press-event", self._button_press_cb)

        self._width = Gdk.Screen.width()
        self._height = Gdk.Screen.height() - (GRID_CELL_SIZE * 1.5)
        self._scale = self._height / (14.0 * DOT_SIZE * 1.2)
        self._dot_size = int(DOT_SIZE * self._scale)
        self._turtle_offset = 0
        self._space = int(self._dot_size / 5.)
        self._orientation = 0
        self.level = 0
        self.custom_strategy = None
        self.strategies = [BEGINNER_STRATEGY, INTERMEDIATE_STRATEGY,
                           EXPERT_STRATEGY, self.custom_strategy]
        self.strategy = self.strategies[self.level]
        self._timeout_id = None

        # Generate the sprites we'll need...
        self._sprites = Sprites(self._canvas)
        self._dots = []
        for y in range(THIRTEEN):
            for x in range(THIRTEEN):
                xoffset = int((self._width - THIRTEEN * (self._dot_size + \
                                      self._space) - self._space) / 2.)
                if y % 2 == 1:
                    xoffset += int((self._dot_size + self._space) / 2.)
                if x == 0 or y == 0 or x == THIRTEEN - 1 or y == THIRTEEN - 1:
                    self._dots.append(
                        Sprite(self._sprites,
                               xoffset + x * (self._dot_size + self._space),
                               y * (self._dot_size + self._space),
                               self._new_dot('#B0B0B0')))
                else:
                    self._dots.append(
                        Sprite(self._sprites,
                               xoffset + x * (self._dot_size + self._space),
                               y * (self._dot_size + self._space),
                               self._new_dot(self._colors[FILL])))
                    self._dots[-1].type = False  # not set

        # Put a turtle at the center of the screen...
        self._turtle_images = []
        self._rotate_turtle(self._new_turtle())
        self._turtle = Sprite(self._sprites, 0, 0,
                              self._turtle_images[0])
        self._move_turtle(self._dots[int(THIRTEEN * THIRTEEN / 2)].get_xy())

        # ...and initialize.
        self._all_clear()
开发者ID:leonardcj,项目名称:turtlepond,代码行数:57,代码来源:game.py

示例9: __init__

	def __init__(self,bg=(0,0,0),snake=(0,240,0),apple=(255,0,0),snake_max_len=4):
		
		
		super(SnakeScene,self).__init__(tempo=360,bg=bg)
		
		self.snake = Sprite(color=snake,blend=False,z=10,trail=snake_max_len)
		self.add_sprite(0,0,self.snake)
		
		self.apple_time = 0
		self.apple = Sprite(color=apple,blend=False,z=5)
		self.add_sprite(0,0,self.apple)
		
		self.snake_reset()
		self.apple_reset()
		
		self.points = 0
		
		self._snake_dir = rint(0,4) 
开发者ID:topher515,项目名称:metropowall,代码行数:18,代码来源:snake2.py

示例10: __init__

    def __init__(self, turtle_window, n):
        '''This class handles the display of palette selectors (Only relevant
        to GNOME version and very old versions of Sugar).
        '''

        self.shapes = []
        self.spr = None
        self._turtle_window = turtle_window
        self._index = n

        if not n < len(palette_names):
            # Shouldn't happen, but hey...
            debug_output('palette index %d is out of range' % n,
                         self._turtle_window.running_sugar)
            self._name = 'extras'
        else:
            self._name = palette_names[n]

        icon_pathname = None
        for path in self._turtle_window.icon_paths:
            if os.path.exists(os.path.join(path, '%soff.svg' % (self._name))):
                icon_pathname = os.path.join(path, '%soff.svg' % (self._name))
                break

        if icon_pathname is not None:
            off_shape = svg_str_to_pixbuf(svg_from_file(icon_pathname))
        else:
            off_shape = svg_str_to_pixbuf(svg_from_file(os.path.join(
                self._turtle_window.icon_paths[0], 'extrasoff.svg')))
            error_output('Unable to open %soff.svg' % (self._name),
                         self._turtle_window.running_sugar)

        icon_pathname = None
        for path in self._turtle_window.icon_paths:
            if os.path.exists(os.path.join(path, '%son.svg' % (self._name))):
                icon_pathname = os.path.join(path, '%son.svg' % (self._name))
                break

        if icon_pathname is not None:
            on_shape = svg_str_to_pixbuf(svg_from_file(icon_pathname))
        else:
            on_shape = svg_str_to_pixbuf(svg_from_file(os.path.join(
                self._turtle_window.icon_paths[0], 'extrason.svg')))
            error_output('Unable to open %son.svg' % (self._name),
                         self._turtle_window.running_sugar)

        self.shapes.append(off_shape)
        self.shapes.append(on_shape)

        x = int(ICON_SIZE * self._index)
        self.spr = Sprite(self._turtle_window.sprite_list, x, 0, off_shape)
        self.spr.type = 'selector'
        self.spr.name = self._name
        self.set_layer()
开发者ID:Daksh,项目名称:turtleart,代码行数:54,代码来源:taselector.py

示例11: __init__

 def __init__(self, sprites, svg, svgs, tile_type='tile', number=0):
     self.highlight = [svg_str_to_pixbuf(svg)]
     self.spr = Sprite(sprites, 0, 0, self.highlight[0])
     for s in svgs:
         self.highlight.append(svg_str_to_pixbuf(s))
     self.paths = []  # [[N, E, S, W], [N, E, S, W]]
     self.shape = None
     self.orientation = 0
     self.type = tile_type
     self.number = number
     self.value = 1
     self.spr.set_label_color('#FF0000')
开发者ID:erilyth,项目名称:paths,代码行数:12,代码来源:tile.py

示例12: __init__

 def __init__(self, tw, width, height):
     """ Create a sprite to hold the canvas. """
     self.tw = tw
     self.width = width
     self.height = height
     if self.tw.interactive_mode:
         self.canvas = Sprite(tw.sprite_list, 0, 0,
             gtk.gdk.Pixmap(self.tw.area, self.width * 2,
                            self.height * 2, -1))
     else:
         self.canvas = Sprite(None, 0, 0, self.tw.window)
     self.canvas.set_layer(CANVAS_LAYER)
     (self.cx, self.cy) = self.canvas.get_xy()
     self.canvas.type = 'canvas'
     self.gc = self.canvas.images[0].new_gc()
     self.cm = self.gc.get_colormap()
     self.fgrgb = [255, 0, 0]
     self.fgcolor = self.cm.alloc_color('red')
     self.bgrgb = [255, 248, 222]
     self.bgcolor = self.cm.alloc_color('#fff8de')
     self.textsize = 48 # depreciated
     self.textcolor = self.cm.alloc_color('blue')
     self.tw.active_turtle.show()
     self.shade = 0
     self.pendown = False
     self.xcor = 0
     self.ycor = 0
     self.heading = 0
     self.pensize = 5
     self.tcolor = 0
     self.color = 0
     self.gray = 100
     self.fill = False
     self.poly_points = []
     self.svg = SVG()
     self.svg.set_fill_color('none')
     self.tw.svg_string = ''
     self.clearscreen(False)
开发者ID:max630,项目名称:turtleart-hacks,代码行数:38,代码来源:tacanvas.py

示例13: _make_mark

 def _make_mark(self):
     ''' Make a mark to show the fraction position on the bar. '''
     mark = svg_header(self._ball_size / 2.,
                       BAR_HEIGHT * self._scale + 4, 1.0)
     mark += svg_rect(self._ball_size / 2.,
                      BAR_HEIGHT * self._scale + 4, 0, 0, 0, 0,
                      '#FF0000', '#FF0000')
     mark += svg_rect(1, BAR_HEIGHT * self._scale + 4, 0, 0,
                      self._ball_size / 4., 0, '#000000', '#000000')
     mark += svg_footer()
     self.mark = Sprite(self._sprites, 0,
                        self._height,  # hide off bottom of screen
                        svg_str_to_pixbuf(mark))
     self.mark.set_layer(1)
开发者ID:erilyth,项目名称:fractionbounce,代码行数:14,代码来源:bar.py

示例14: update

    def update(self, t=0, v=None):
        """ update render position (velocity is vector in OpenGL style coorinates/timestep)"""
        # if update() has not been run, set time_since_update to current time
        Sprite.update(self, t=t, v=v)

        p1, p2 = self.position_current
        if self.use_polar_coords:
            x, y = pol2cart(p1, p2)
        else:
            x, y = (p1, p2)
        sz = self.size
        th = self.thickness
        self.vertices = [  # horizontal beam
            (x - sz / 2.0, y + th / 2),  # left-top
            (x - sz / 2.0, y - th / 2),  # left-bottom
            (x + sz / 2.0, y - th / 2),  # right-bottom
            (x + sz / 2.0, y + th / 2),  # right-top
            # vertical beam
            (x - th / 2, y + sz / 2.0),  # left-top
            (x - th / 2, y - sz / 2.0),  # left-bottom
            (x + th / 2, y - sz / 2.0),  # right-bottom
            (x + th / 2, y + sz / 2.0),  # right-top
        ]
        self.t_since_update = t  # set time_since_update to current time
开发者ID:SridharLab,项目名称:neurodot-present,代码行数:24,代码来源:animated_fixation_cross.py

示例15: _generate_spiral

 def _generate_spiral(self):
     ''' Make a new set of dots for a sprial '''
     for z in range(4):
         for i in range(len(colors)):
             if self._zones[i] == z:
                 self._dots.append(
                     Sprite(self._sprites, self._xy[0], self._xy[1],
                            self._new_dot(colors[i])))
                 self._dots[-1].type = i
                 self._calc_next_dot_position()
     if self._xo_man is None:
         x = 510 * self._scale
         y = 280 * self._scale
         self._xo_man = Sprite(self._sprites, x, y,
                              self._new_xo_man(self.colors))
         self._xo_man.type = None
开发者ID:leonardcj,项目名称:xocolors,代码行数:16,代码来源:game.py


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