本文整理汇总了Python中ball.Ball.width方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.width方法的具体用法?Python Ball.width怎么用?Python Ball.width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ball.Ball
的用法示例。
在下文中一共展示了Ball.width方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Bounce
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import width [as 别名]
class Bounce():
''' The Bounce class is used to define the ball and the user
interaction. '''
def __init__(self, canvas, path, parent=None):
''' Initialize the canvas and set up the callbacks. '''
self._activity = parent
self._fraction = None
self._path = path
if parent is None: # Starting from command line
self._sugar = False
else: # Starting from Sugar
self._sugar = True
self._canvas = canvas
self._canvas.grab_focus()
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
self._canvas.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
self._canvas.add_events(Gdk.EventMask.KEY_PRESS_MASK)
self._canvas.add_events(Gdk.EventMask.KEY_RELEASE_MASK)
self._canvas.connect('draw', self.__draw_cb)
self._canvas.connect('button-press-event', self._button_press_cb)
self._canvas.connect('button-release-event', self._button_release_cb)
self._canvas.connect('key-press-event', self._keypress_cb)
self._canvas.connect('key-release-event', self._keyrelease_cb)
self._canvas.set_can_focus(True)
self._canvas.grab_focus()
self._sprites = Sprites(self._canvas)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - GRID_CELL_SIZE
self._scale = Gdk.Screen.height() / 900.0
self._timeout = None
self.buddies = [] # used for sharing
self._my_turn = False
self.select_a_fraction = False
self._easter_egg = int(uniform(1, 100))
# Find paths to sound files
self._path_to_success = os.path.join(path, LAUGH)
self._path_to_failure = os.path.join(path, CRASH)
self._path_to_bubbles = os.path.join(path, BUBBLES)
self._create_sprites(path)
self.mode = 'fractions'
self._challenge = 0
self._expert = False
self._challenges = []
for challenge in CHALLENGES[self._challenge]:
self._challenges.append(challenge)
self._fraction = 0.5 # the target of the current challenge
self._label = '1/2' # the label
self.count = 0 # number of bounces played
self._correct = 0 # number of correct answers
self._press = None # sprite under mouse click
self._new_bounce = False
self._n = 0
self._accel_index = 0
self._accel_flip = False
self._accel_xy = [0, 0]
self._guess_orientation()
self._dx = 0. # ball horizontal trajectory
# acceleration (with dampening)
self._ddy = (6.67 * self._height) / (STEPS * STEPS)
self._dy = self._ddy * (1 - STEPS) / 2. # initial step size
if self._sugar:
if _is_tablet_mode():
self._activity.reset_label(
_('Click the ball to start. Rock the computer left '
'and right to move the ball.'))
else:
self._activity.reset_label(
_('Click the ball to start. Then use the arrow keys to '
'move the ball.'))
def _accelerometer(self):
return os.path.exists(ACCELEROMETER_DEVICE) and _is_tablet_mode()
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)
#.........这里部分代码省略.........