当前位置: 首页>>代码示例>>Python>>正文


Python Timer.tick方法代码示例

本文整理汇总了Python中timer.Timer.tick方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.tick方法的具体用法?Python Timer.tick怎么用?Python Timer.tick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在timer.Timer的用法示例。


在下文中一共展示了Timer.tick方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Signals

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import tick [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)
开发者ID:krassowski,项目名称:basic-particle-simulator,代码行数:104,代码来源:simulation.py

示例2: Window

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import tick [as 别名]
        sdl2.SDL_Init(sdl2.SDL_INIT_EVERYTHING)
        self.window = sdl2.SDL_CreateWindow(c_char_p(b"Haxball"), 100, 100, self.w, self.h, sdl2.SDL_WINDOW_SHOWN)
        self.ren = sdl2.SDL_CreateRenderer(self.window, -1, sdl2.SDL_RENDERER_ACCELERATED)

w = Window()
p = Player(w)
b = Ball(w, rad=9,x=100,y=100)
s = SpeedVector(p)
sdl2.SDL_RenderClear(w.ren)
e = sdl2.SDL_Event()
quit = False
timer = Timer()
while not quit:
    sdl2.SDL_SetRenderDrawColor(w.ren, 0,0,0,255)
    sdl2.SDL_RenderClear(w.ren)
    while(sdl2.SDL_PollEvent(byref(e))):
            if e.type == sdl2.SDL_QUIT:
                quit = True
            p.handle_event(e)
    dt = timer.tick()

    p.update(dt)
    b.update(dt)

    p.draw()
    b.draw()
    s.draw()
    p.collision(b)
    sdl2.SDL_RenderPresent(w.ren)
    sdl2.SDL_Delay(2)
开发者ID:JerzySpendel,项目名称:Ball,代码行数:32,代码来源:main.py

示例3: Timer

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import tick [as 别名]
# timer_driver.py
# Driver to test the Timer class.
# Written by THC.

from timer import Timer

timer = Timer(1, 30, 0)

while not timer.is_zero():
    print timer
    timer.tick()

print timer
开发者ID:CS98,项目名称:TheOneRepo,代码行数:15,代码来源:timer_driver.py

示例4: Frog

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import tick [as 别名]



####### create objects
frog = Frog(color = globals.GREEN, pos = [globals.WIDTH/2-10, globals.HEIGHT-25])
frog2 = Frog(color = globals.WHITE, pos = [globals.WIDTH/2+50, globals.HEIGHT-25])
car = Vehicle(color = globals.RED, pos = [0, globals.HEIGHT-95])
car2 = Vehicle(color = globals.BLUE, pos = [0, globals.HEIGHT-300])
bang = Bang(color = globals.GREEN)
bang2 = Bang(color = globals.WHITE)
road1 = Road(pos = [0, globals.HEIGHT-150])
road2 = Road(pos = [0, globals.HEIGHT-300])
road3 = Road(pos = [0, globals.HEIGHT-500])


###### start program

# Setup the main loop timer.
main_timer = Timer()

while True :

    # If the time since the last tick is more than 10 milliseconds.
    if main_timer.get_ticktime() > 10:
        main()

        # Tick the timer to reset it.
        main_timer.tick()

开发者ID:beckettsimmons,项目名称:bermyfrog,代码行数:30,代码来源:bermyfrog.py


注:本文中的timer.Timer.tick方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。