本文整理汇总了Python中sprites.Sprites.set_delay方法的典型用法代码示例。如果您正苦于以下问题:Python Sprites.set_delay方法的具体用法?Python Sprites.set_delay怎么用?Python Sprites.set_delay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprites.Sprites
的用法示例。
在下文中一共展示了Sprites.set_delay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from sprites import Sprites [as 别名]
# 或者: from sprites.Sprites import set_delay [as 别名]
class Game():
''' OLPC XO man color changer designed in memory of Nat Jacobson '''
def __init__(self, canvas, parent=None, mycolors=['#A0FFA0', '#FF8080']):
self._activity = parent
self.colors = [mycolors[0]]
self.colors.append(mycolors[1])
self._canvas = canvas
if parent is not None:
parent.show_all()
self._parent = parent
self._canvas.connect("draw", self.__draw_cb)
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("button-press-event", self._button_press_cb)
self._canvas.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
self._canvas.connect('button-release-event', self._button_release_cb)
self._canvas.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
self._canvas.connect("motion-notify-event", self._mouse_move_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - GRID_CELL_SIZE
self._scale = self._width / 1200.
self.press = None
self.dragpos = [0, 0]
self.startpos = [0, 0]
self._dot_cache = {}
self._xo_cache = {}
self._radius = 22.5
self._stroke_width = 9.5
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._sprites.set_delay(True)
self._dots = []
self._xo_man = None
self._generate_bg('#FFF')
# First dot, starting angle
self._cxy = [self._width / 2, self._height / 2]
self._xy = [self._width / 2 + 120 * self._scale,
self._height / 2 - self._radius * self._scale]
self._angle = 0
self._dot_size_plus = self._radius * 3 * self._scale
self._min = -self._dot_size_plus / 3
self._max = self._height - (self._dot_size_plus / 2.2)
self._zones = []
self._calc_zones()
self._generate_spiral()
self._sprites.draw_all()
def _calc_zones(self):
for color in colors:
rgb1 = _from_hex(color[0])
rgb2 = _from_hex(color[1])
dv = _contrast(rgb1, rgb2)
dh = _delta_hue(rgb1, rgb2)
self._zones.append(_zone(dv, dh))
def _calc_next_dot_position(self):
''' calculate spiral coordinates '''
dx = self._xy[0] - self._cxy[0]
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):
#.........这里部分代码省略.........