本文整理汇总了Python中timer.Timer.set_mode方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.set_mode方法的具体用法?Python Timer.set_mode怎么用?Python Timer.set_mode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.set_mode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Signals
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import set_mode [as 别名]
#.........这里部分代码省略.........
obj_1.time_unused = time_unused
obj_2.time_unused = time_unused
obj_1.velocity -= obj_1.delta_velocity
obj_2.velocity -= obj_2.delta_velocity
# masy rowne
#obj_1.velocity, obj_2.velocity = obj_2.velocity, obj_1.velocity
# masy nie rowne
obj_1.velocity, obj_2.velocity = (obj_1.velocity * (obj_1.mass - obj_2.mass) + 2 * obj_2.mass * obj_2.velocity) / (obj_1.mass + obj_2.mass), (obj_2.velocity * (obj_2.mass - obj_1.mass) + 2 * obj_1.mass * obj_1.velocity) / (obj_1.mass + obj_2.mass)
for o in _active_objects:
_active_objects.remove(o)
_active_objects.extend([obj_1, obj_2])
self.signals.emit('on_collision')
# if there is an active gravity (between objects), add it:
if self.gravity:
# F = versor(r) * G m1 m2 / (r^2)
r = obj_1.position - obj_2.position
# gravity_force = r.normalized() * self.gravitational_constant * obj_1.mass * obj_2.mass / (r.length()**2)
r_squared_length = r.length_squared()
gravity_force = (r / math.sqrt(r_squared_length)) * self.gravitational_constant * obj_1.mass * obj_2.mass / r_squared_length
obj_1.poke(-gravity_force)
obj_2.poke(gravity_force)
# 3. Move every object:
map(self.move_object, self.objects)
def simulate(self):
if self.timer.mode == 'stop':
return True
self.timer.tick()
self.physics()
self.signals.emit('on_simulate')
def make_a_single_step(self, direction):
if self.step_size:
self.timer.step_size = self.step_size
self.timer.set_mode('step_by_step', direction)
self.simulate()
self.timer.set_mode(self.mode, self.get_direction())
def step_forward(self, waste=''):
self.make_a_single_step('forward')
def step_backward(self, waste=''):
self.make_a_single_step('backward')
def expose(self):
from random import uniform as rand
exposed = {
'const': const,
'V': Vector3,
'Vector3': Vector3,
'Sound': Sound,
'active_objects': _active_objects,
'let': self.let,
'Force': Vector3,
'Ball': sim_objects.Ball,
'Wall': sim_objects.Wall,
'Box': sim_objects.Box,
'WallBox': sim_objects.WallBox,
'simulation': self,
'rand': rand
}
for signal in self.signals.names:
exposed[signal] = None
return exposed
def set_script(self, script):
exposed = self.expose()
try:
self.script = script
exec (self.script, exposed, exposed)
error = None
except SyntaxError, err:
error_class = err.__class__.__name__
line_number = err.lineno
error = (error_class, err, line_number, None)
except Exception as err:
error_class = err.__class__.__name__
cl, exc, tb = sys.exc_info()
line_number = traceback.extract_tb(tb)[-1][1]
error = (error_class, err, line_number)