本文整理汇总了Python中ball.Ball.frame_y方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.frame_y方法的具体用法?Python Ball.frame_y怎么用?Python Ball.frame_y使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ball.Ball
的用法示例。
在下文中一共展示了Ball.frame_y方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Bounce
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import frame_y [as 别名]
#.........这里部分代码省略.........
return int(BAR_HEIGHT * (1 - (self.ball.ball_x() /
float(self.bar.width()))))
def _mark_offset(self, x):
return int(BAR_HEIGHT * (1 - (x / float(self.bar.width())))) - 12
def _animate(self):
''' A little Easter Egg just for fun. '''
if self._new_bounce:
self._dy = self._ddy * (1 - STEPS) / 2 # initial step size
self._new_bounce = False
self._current_frame = 0
self._frame_counter = 0
self.ball.move_frame(self._current_frame,
(self.ball.ball_x(), self.ball.ball_y()))
self.ball.move_ball((self.ball.ball_x(), self._height))
GObject.idle_add(play_audio_from_file, self, self._path_to_bubbles)
if self._accelerometer():
fh = open(ACCELEROMETER_DEVICE)
string = fh.read()
xyz = string[1:-2].split(',')
self._dx = float(xyz[0]) / 18.
fh.close()
else:
self._dx = uniform(-int(DX * self._scale), int(DX * self._scale))
self.ball.move_frame_relative(
self._current_frame, (int(self._dx), int(self._dy)))
self._dy += self._ddy
self._frame_counter += 1
self._current_frame = self.ball.next_frame(self._frame_counter)
if self.ball.frame_y(self._current_frame) >= self.ball_y_max:
# hit the bottom
self.ball.move_ball((self.ball.ball_x(), self.ball_y_max))
self.ball.hide_frames()
self._test(easter_egg=True)
self._new_bounce = True
self._timeout = GObject.timeout_add(BOUNCE_PAUSE, self._move_ball)
else:
GObject.timeout_add(STEP_PAUSE, self._animate)
def add_fraction(self, string):
''' Add a new challenge; set bar to 2x demominator '''
numden = string.split('/', 2)
self._challenges.append([string, int(numden[1]), 0])
def _get_new_fraction(self):
''' Select a new fraction challenge from the table '''
if not self.we_are_sharing():
n = int(uniform(0, len(self._challenges)))
else:
n = self._n
fstr = self._challenges[n][0]
if '/' in fstr: # fraction
numden = fstr.split('/', 2)
fraction = float(numden[0].strip()) / float(numden[1].strip())
elif '%' in fstr: # percentage
fraction = float(fstr.strip().strip('%').strip()) / 100.
else: # To do: add support for decimals (using locale)
_logger.debug('Could not parse challenge (%s)', fstr)
fstr = '1/2'
fraction = 0.5
return fraction, fstr, n