本文整理汇总了Python中sprites.Sprite.get_xy方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.get_xy方法的具体用法?Python Sprite.get_xy怎么用?Python Sprite.get_xy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprites.Sprite
的用法示例。
在下文中一共展示了Sprite.get_xy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tab
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import get_xy [as 别名]
class Tab():
""" Create tabs for the slide; include a TextView for OSK input """
def __init__(self, sprites, path, name, x, y, w, h):
self.spr = Sprite(sprites, x, y, file_to_pixbuf(path, name, w, h))
self.spr.label = "1.0"
self.spr.type = name
self.name = name
self.width = w
self.textview = None
self.textbuffer = None
self.fixed = None
self.textview_y_offset = 0
def label(self, label):
if self.textbuffer is not None:
self.textbuffer.set_text(label)
def _move_textview(self, x, y):
y += self.textview_y_offset
if self.textview is not None:
if x > 0 and x < Gdk.Screen.width() - self.width and y > 0:
self.fixed.move(self.textview, x, y)
self.textview.show()
else:
self.textview.hide()
def move(self, x, y):
self.spr.move((x, y))
self._move_textview(x, y)
def move_relative(self, dx, dy):
self.spr.move_relative((dx, dy))
x, y = self.spr.get_xy()
self._move_textview(x, y)
def draw(self, layer=100):
self.spr.set_layer(layer)
self.spr.draw()
x, y = self.spr.get_xy()
self._move_textview(x, y)
def hide(self):
self.spr.hide()
示例2: __init__
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import get_xy [as 别名]
class TurtleGraphics:
""" A class for the Turtle graphics canvas """
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)
def start_fill(self):
""" Start accumulating points of a polygon to fill. """
self.fill = True
self.poly_points = []
def stop_fill(self):
""" Fill the polygon. """
self.fill = False
if len(self.poly_points) == 0:
return
minx = self.poly_points[0][0]
miny = self.poly_points[0][1]
maxx = minx
maxy = miny
for p in self.poly_points:
if p[0] < minx:
minx = p[0]
elif p[0] > maxx:
maxx = p[0]
if p[1] < miny:
miny = p[1]
elif p[1] > maxy:
maxy = p[1]
w = maxx - minx
h = maxy - miny
self.canvas.images[0].draw_polygon(self.gc, True, self.poly_points)
self.invalt(minx - self.pensize * self.tw.coord_scale / 2 - 3,
miny - self.pensize * self.tw.coord_scale / 2 - 3,
w + self.pensize * self.tw.coord_scale + 6,
h + self.pensize * self.tw.coord_scale + 6)
self.poly_points = []
def clearscreen(self, share=True):
"""Clear the canvas and reset most graphics attributes to defaults."""
rect = gtk.gdk.Rectangle(0, 0, self.width, self.height)
self.gc.set_foreground(self.bgcolor)
self.canvas.images[0].draw_rectangle(self.gc, True, *rect)
self.invalt(0, 0, self.width, self.height)
self.setpensize(5, share)
self.setgray(100, share)
self.setcolor(0, share)
self.settextcolor(70)
self.setshade(50, share)
for turtle_key in iter(self.tw.turtles.dict):
self.set_turtle(turtle_key)
self.tw.active_turtle.set_color(0)
self.tw.active_turtle.set_shade(50)
self.tw.active_turtle.set_gray(100)
self.tw.active_turtle.set_pen_size(5)
self.tw.active_turtle.reset_shapes()
self.seth(0, share)
self.setpen(False, share)
self.setxy(0, 0, share)
self.setpen(True, share)
self.tw.active_turtle.hide()
self.set_turtle(self.tw.default_turtle_name)
self.tw.svg_string = ''
self.svg.reset_min_max()
#.........这里部分代码省略.........
示例3: Game
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import get_xy [as 别名]
#.........这里部分代码省略.........
dy = self._xy[1] - self._cxy[1]
r = sqrt(dx * dx + dy * dy)
c = 2 * r * pi
a = atan2(dy, dx)
da = (self._dot_size_plus / c) * 2 * pi
a += da
r += self._dot_size_plus / (c / self._dot_size_plus)
self._xy[0] = r * cos(a) + self._cxy[0]
self._xy[1] = r * sin(a) + self._cxy[1]
if self._xy[1] < self._min or self._xy[1] > self._max:
self._calc_next_dot_position()
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
def move_dot(self, i, x, y):
self._dots[i].move((x, y))
def get_dot_xy(self, i):
return self._dots[i].get_xy()
def move_xo_man(self, x, y):
self._xo_man.move((x, y))
def get_xo_man_xy(self):
return self._xo_man.get_xy()
def rotate(self):
x, y = self._dots[0].get_xy()
for i in range(len(colors) - 1):
self._dots[i].move(self._dots[i + 1].get_xy())
self._dots[-1].move((x, y))
def _generate_bg(self, color):
''' a background color '''
self._bg = Sprite(self._sprites, 0, 0, self._new_background(color))
self._bg.set_layer(0)
self._bg.type = None
def adj_background(self, color):
''' Change background '''
self._bg.set_image(self._new_background(color))
self._bg.set_layer(0)
def _button_press_cb(self, win, event):
win.grab_focus()
x, y = map(int, event.get_coords())
self.dragpos = [x, y]
spr = self._sprites.find_sprite((x, y))
if spr == None or spr == self._bg:
return
示例4: Ball
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import get_xy [as 别名]
class Ball():
''' The Bounce class is used to define the ball and the user
interaction. '''
def __init__(self, sprites, filename):
self._current_frame = 0
self._frames = [] # Easter Egg animation
self._sprites = sprites
self.ball = Sprite(self._sprites, 0, 0, svg_str_to_pixbuf(
svg_from_file(filename)))
self.ball.set_layer(3)
self.ball.set_label_attributes(24, vert_align='top')
ball = extract_svg_payload(file(filename, 'r'))
for i in range(8):
self._frames.append(Sprite(
self._sprites, 0, 0, svg_str_to_pixbuf(
svg_header(SIZE[0], SIZE[1], 1.0) + TRANSFORMS[i] +
ball + PUNCTURE + AIR + '</g>' + svg_footer())))
for frame in self._frames:
frame.set_layer(3)
frame.move((0, -SIZE[1])) # move animation frames off screen
def new_ball(self, filename):
''' Create a ball object and Easter Egg animation from an SVG file. '''
self.ball.set_shape(svg_str_to_pixbuf(svg_from_file(filename)))
ball = extract_svg_payload(file(filename, 'r'))
for i in range(8):
self._frames[i].set_shape(svg_str_to_pixbuf(
svg_header(SIZE[0], SIZE[1], 1.0) + TRANSFORMS[i] +
ball + PUNCTURE + AIR + '</g>' + svg_footer()))
def new_ball_from_image(self, filename, save_path):
''' Just create a ball object from an image file '''
if filename == '':
_logger.debug('Image file not found.')
return
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
if pixbuf.get_width() > pixbuf.get_height():
size = pixbuf.get_height()
x = int((pixbuf.get_width() - size) / 2)
else:
size = pixbuf.get_width()
x = int((pixbuf.get_height() - size) / 2)
crop = GdkPixbuf.Pixbuf.new(0, True, 8, size, size)
pixbuf.copy_area(x, 0, size, size, crop, 0, 0)
scale = crop.scale_simple(85, 85, GdkPixbuf.InterpType.BILINEAR)
scale.savev(save_path, 'png', [], [])
self.ball.set_shape(
svg_str_to_pixbuf(generate_ball_svg(save_path)))
except Exception as e:
_logger.error('Could not load image from %s: %s' % (filename, e))
def new_ball_from_fraction(self, fraction):
''' Create a ball with a section of size fraction. '''
r = SIZE[0] / 2.0
self.ball.set_shape(svg_str_to_pixbuf(
svg_header(SIZE[0], SIZE[1], 1.0) +
svg_sector(r, r + BOX[1], r - 1, 1.999 * pi,
COLORS[0], COLORS[1]) +
svg_sector(r, r + BOX[1], r - 1, fraction * 2 * pi,
COLORS[1], COLORS[0]) +
svg_rect(BOX[0], BOX[1], 4, 4, 0, 0, '#FFFFFF', 'none') +
svg_footer()))
def ball_x(self):
return self.ball.get_xy()[0]
def ball_y(self):
return self.ball.get_xy()[1]
def frame_x(self, i):
return self._frames[i].get_xy()[0]
def frame_y(self, i):
return self._frames[i].get_xy()[1]
def width(self):
return self.ball.rect[2]
def height(self):
return self.ball.rect[3]
def move_ball(self, pos):
self.ball.move(pos)
def move_ball_relative(self, pos):
self.ball.move_relative(pos)
def move_frame(self, i, pos):
self._frames[i].move(pos)
def move_frame_relative(self, i, pos):
self._frames[i].move_relative(pos)
def hide_frames(self):
for frame in self._frames:
#.........这里部分代码省略.........
示例5: Game
# 需要导入模块: from sprites import Sprite [as 别名]
# 或者: from sprites.Sprite import get_xy [as 别名]
class Game():
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()
def _move_turtle(self, pos):
''' Move turtle and add its offset '''
self._turtle.move(pos)
self._turtle.move_relative(
(-self._turtle_offset, -self._turtle_offset))
def _all_clear(self):
''' Things to reinitialize when starting up a new game. '''
# Clear dots
for dot in self._dots:
if dot.type:
dot.type = False
dot.set_shape(self._new_dot(self._colors[FILL]))
dot.set_label('')
# Recenter the turtle
self._move_turtle(self._dots[int(THIRTEEN * THIRTEEN / 2)].get_xy())
self._turtle.set_shape(self._turtle_images[0])
self._set_label('')
if self._timeout_id is not None:
GObject.source_remove(self._timeout_id)
def new_game(self, saved_state=None):
''' Start a new game. '''
self._all_clear()
# Fill in a few dots to start
for i in range(15):
n = int(uniform(0, THIRTEEN * THIRTEEN))
if self._dots[n].type is not None:
self._dots[n].type = True
self._dots[n].set_shape(self._new_dot(self._colors[STROKE]))
# Calculate the distances to the edge
self._initialize_weights()
self.strategy = self.strategies[self.level]
def _set_label(self, string):
''' Set the label in the toolbar or the window frame. '''
self._activity.status.set_label(string)
#.........这里部分代码省略.........