• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python time.wait函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygame.time.wait函数的典型用法代码示例。如果您正苦于以下问题:Python wait函数的具体用法?Python wait怎么用?Python wait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: main

def main():

	# create two Launchpad instances
	lp1 = launchpad.Launchpad()
	lp2 = launchpad.Launchpad()

	# open them
	lp1.Open(0)
	lp2.Open(1)


	while 1:
	
		# random light show
		lp1.LedCtrlRaw( random.randint(0,127), random.randint(0,3), random.randint(0,3) )
		lp2.LedCtrlRaw( random.randint(0,127), random.randint(0,3), random.randint(0,3) )
		
		# some extra time to give the button events a chance to come through...
		time.wait( 5 )

		# wait until the arm button (lower right) is hit
		but = lp1.ButtonStateRaw()
		if but != []:
			print( but )
			if but[0] == 120:
				break
开发者ID:jesuswithyoyo,项目名称:launchpad.py,代码行数:26,代码来源:launchpad_demo_2devices.py


示例2: main

def main(file_path=None):
    """Play an audio file as a buffered sound sample

    Option argument:
        the name of an audio file (default data/secosmic_low.wav

    """
    if file_path is None:
        file_path = os.path.join(main_dir,
                                 'data',
                                 'secosmic_lo.wav')

    #choose a desired audio format
    mixer.init(11025) #raises exception on fail


    #load the sound    
    sound = mixer.Sound(file_path)


    #start playing
    print ('Playing Sound...')
    channel = sound.play()


    #poll until finished
    while channel.get_busy(): #still playing
        print ('  ...still going...')
        time.wait(1000)
    print ('...Finished')
开发者ID:123jefferson,项目名称:MiniBloq-Sparki,代码行数:30,代码来源:sound.py


示例3: start

def start(LP):
  snake = {}
  
  init_snake(LP, snake)
  
  LP.LedCtrlXY(0, 0, 0, 1)
  LP.LedCtrlXY(1, 0, 0, 1)
  LP.LedCtrlXY(8, 8, 1, 0)
  
  time.wait(500)
  
  while True:
    time.wait(500)
    
    but = LP.ButtonStateXY()
    while but != [] and not but[2]:
      but = LP.ButtonStateXY()
    
    if but != [] and but[2]:
      if but[0:2] == [8, 8]:
        break
      if but[0:2] == snake["food"]:
        snake["head"] = [3, 3]
      elif but[0:2] == [0, 0]:
        snake["dir"] = (snake["dir"] - 1) % 4
      elif but[0:2] == [1, 0]:
        snake["dir"] = (snake["dir"] + 1) % 4
    
    update(LP, snake)
开发者ID:Isti115,项目名称:RaspberryPi_Launchpad_Games,代码行数:29,代码来源:snake_old.py


示例4: update

    def update(self):
        
        self.tick = get_ticks()
        delta = self.tick - self.last_tick

        if self.slow_motion_delay > 0:
            self.slow_motion_delay -= 1

            if self.slow_motion_delay <= 0:
                self.frecuency = self.normal_frecuency


        if delta > self.frecuency:
            skips = delta / self.frecuency

            if skips > self.maxframeskip:
                skips = self.maxframeskip
                self.last_tick = self.tick
            else:
                self.last_tick += skips * self.frecuency

            self._update_status()
            return skips
        else:
            wait(1)
            return 0
开发者ID:HieuLsw,项目名称:sbfury,代码行数:26,代码来源:fps.py


示例5: ledctrlc

def ledctrlc(dev,list,buffer_time_lists,buffer_time_numbers):
 from pygame import time
 franum_total = 0
 for frame in list:
  franum_total += 1
 franum = 1
 print("#####ANIMATION START#####")
 for frame in list:
  colnum = 1
  print("+++++FRAME " + str(franum) + " / " + str(franum_total) + " +++++")
  for color in frame:
   for i in color:
    if colnum == 1:
     dev.LedCtrlRaw(i,3,0)
     print(str(i) + " -> red")
    elif colnum == 2:
     dev.LedCtrlRaw(i,3,3)
     print(str(i) + " -> yellow")
    elif colnum == 3:
     dev.LedCtrlRaw(i,0,3)
     print(str(i) + " -> green")
    else:
     dev.LedCtrlRaw(i,3,3)
     print(str(i) + " -> yellow by else case")
   colnum += 1
   time.wait(buffer_time_numbers)
  time.wait(buffer_time_lists)
  dev.Reset()
  franum += 1
 print("#####ANIMATION END#####\n")
开发者ID:sesshomariu,项目名称:launchpad-matrix,代码行数:30,代码来源:codes.py


示例6: run

    def run(self):
        self.net_tick = 0
        self.clients = {}
        self.lock = Lock()
        self.server = UdpServer(25000)

        self.socket_thread = SocketThread(self)
        self.socket_thread.start()

        print "Server up and running."

        self.input_thread = InputThread(self)
        self.input_thread.start()

        ticks_start = time.get_ticks()
        while not self.quit:
            ticks = time.get_ticks() - ticks_start - self.net_tick * FRAMETIME
            update_count = ticks / FRAMETIME
            with self.lock:
                for i in xrange(update_count):
                    self.update()
                    self.send_new_state()
                    dead_clients = []
                    for addr, client in self.clients.items():
                        client.countdown()
                        if client.is_dead():
                            dead_clients.append(addr)
                    for addr in dead_clients:
                        print "removing client %s (timeout)" % str(addr)
                        del self.clients[addr]
            time.wait(1)
开发者ID:oncer,项目名称:netproto,代码行数:31,代码来源:np_server.py


示例7: authenticate

    def authenticate(self):
        """ call this before opening the game
        gets the current tick from the server
        and synchronizes the game state """

        def threaded_recv(retlist):
            response, addr = self.client.recv()
            retlist.append(response)

        pkg_request = Packet(0)
        self.client.send(pkg_request)
        retlist = []
        t = Thread(target=lambda: threaded_recv(retlist))
        t.daemon = True
        t.start()
        wait_start = time.get_ticks()
        wait_end = wait_start + 1000
        while len(retlist) <= 0 and time.get_ticks() < wait_end:
            time.wait(1)

        if len(retlist) > 0:
            response = retlist[0]
            pkg_response = Packet.unpack(response)
            self.start_tick = pkg_response.tick
            if len(pkg_response.players) <= 0:
                raise RuntimeError("Invalid response: %s" % pkg_response)
            self.id = pkg_response.players[0][0]
            self.set_state(pkg_response, backtrack=False)
        else:
            raise RuntimeError("Server not responding")
开发者ID:oncer,项目名称:netproto,代码行数:30,代码来源:np_client.py


示例8: test

def test():
    sp = SoundPlayer()
    for i in range(8):
        sp.load(i)
    t = sp.sounds[1].get_length() * 1000
    sp.play(1)
    time.wait(t)
开发者ID:BenignCremator,项目名称:RPi-DMX-media-sync,代码行数:7,代码来源:sound_player.py


示例9: setup

def setup():
	random.seed()
	mixer.init()
	#screen = pygame.display.set_mode ((640, 480), 0, 32)
	samples = get_samples("./samples")
	init_playfield(samples)
	tick()
	print_playfield()
	pygame.init ()
	#screen.fill ((100, 100, 100))
	#pygame.display.flip ()
	#pygame.key.set_repeat (500, 30)
	#mixer.init(11025)
	#mixer.init(44100)
	#sample = samples[random.randint(0,len(samples)-1)]
	#print("playing sample:",sample)
	#sound = mixer.Sound(sample)
	#channel = sound.play()

	while True:
		play_sounds()
		#for i in range(2):	
		mutate_playfield()
		tick()
		print_playfield()
		#time.wait(int((1000*60)/80)) # 128bpm
		time.wait(50)

	#while channel.get_busy(): #still playing
	#	print("  ...still going...")
	#	time.wait(1000)
	#print("...Finished")
	pygame.quit()
开发者ID:pez2001,项目名称:Stuff,代码行数:33,代码来源:conwaysa.py


示例10: stopTripod

def stopTripod(t, turnAngle=0, back=False, duty_turn=0):
	""" Adds an ending point to the tripod gait and returns to a
	    standing position. """

	xjusAnalysis.endAccel(PLOT_ANALYSIS)
	xjusAnalysis.endAvgVelocity()
	#acc = xjusAnalysis.getAvgAbsZAccel()
	#print("===============================================")
	#print("Stability measure: %.4f" % (acc))
	current = xjusAnalysis.getAvgCurrent()
	#print("Power usage measure: %.4f" % (current))
	#print("===============================================")
	
	pytime.wait(DT)
	for node in nodes:
		[nA, pA, vA, tA] = addTripodPoint(t, turnAngle, back=back, end=True, duty_turn=duty_turn)
		addPvtArray(nA, pA, vA, tA)

	for node in nodes:
		xjus.stopIPM(node)
		xjus.printIpmStatus(node)

	wait()

	returnToStand()
开发者ID:hmartiro,项目名称:project-thesis,代码行数:25,代码来源:xjus.py


示例11: main

def main():

    LP = launchpad.Launchpad()  # creates a Launchpad instance (first Launchpad found)
    LP.Open()  # start it

    LP.LedCtrlString("HELLO ", 0, 3, -1)  # scroll "HELLO" from right to left

    # random output until button "arm" (lower right) is pressed
    print("---\nRandom madness. Stop by hitting the ARM button (lower right)")
    print("Remember the PyGame MIDI bug:")
    print("If the ARM button has no effect, hit an automap button (top row)")
    print("and try again...")

    while 1:
        LP.LedCtrlRaw(random.randint(0, 127), random.randint(0, 3), random.randint(0, 3))

        # some extra time to give the button events a chance to come through...
        time.wait(5)

        but = LP.ButtonStateRaw()
        if but != []:
            print(but)
            if but[0] == 120:
                break

    LP.Reset()  # turn all LEDs off
    LP.Close()  # close the Launchpad
开发者ID:sesshomariu,项目名称:launchpad-matrix,代码行数:27,代码来源:launchpad_demo.py


示例12: scheduler_loop

def scheduler_loop(timestamp_dictionary, stack):
    global now
    while active:        
        now = pgtime.get_ticks()
        # now schedule pending events ... thus we're having a fixed point of time ('now')
        while len(stack) > 0:
            delayed_event = stack.pop()
            # correct future time if wait was not precise
            future_time = delayed_event[1]                               
            if future_time not in timestamp_dictionary:
                timestamp_dictionary[future_time] = {}
            # get objects uuid
            key = delayed_event[0]
            # store function to be scheduled under the object uuid (necessary for cleaning) 
            timestamp_dictionary[future_time][key] = delayed_event[2]
        # after everything has been said and done, check if there's any garbage left ...
        time_points = timestamp_dictionary.keys()
        past_time_points = [x for x in time_points if x < now]
        for time_point in past_time_points:                    
            #print(str(len(timestamp_dictionary[past])) + " EVENTS at " + str(past))
            for past_event in timestamp_dictionary[time_point]:                
                try:                    
                    async = threading.Thread(target=timestamp_dictionary[time_point][past_event], args=(time_point, now))
                    async.start()
                except Exception as e:
                    print(e) 
                    raise e
            del timestamp_dictionary[time_point]            
            # wait one microsecond              
        pgtime.wait(1) 
开发者ID:the-drunk-coder,项目名称:regraa,代码行数:30,代码来源:regraa_scheduler.py


示例13: progress

def progress():

	global posX
	global posY
	global colour
	global delay

	# Progress by a random number between 2 and 6 blocks
	progression = random.randint(2,6)

	# Run 3 times, one for each state.
	for x in range(0, 3):

		for y in range(0, progression):

			# If progression has reached the 8th column, increase the row number and reset the column number.
			if posX[x] == 8:
				posY[x] += 1
				posX[x] = 0

			# Set LED Colours according to the state and colour var in setup.
			LP.LedCtrlXY(posX[x], posY[x], colour[x][0], colour[x][1])

			# Increase column number.
			posX[x] = posX[x]+1

		# Wait a rancom number of milliseconds according to the delay var.
		time.wait(random.randint(delay[x][0],delay[x][1]))
开发者ID:siddv,项目名称:Defrag.py,代码行数:28,代码来源:defrag.py


示例14: ledctrlfn

def ledctrlfn(dev,list,buffer_time_lists,buffer_time_numbers,red,green):
 from pygame import time
 for i in list:
  dev.LedCtrlRaw(i,red,green)
  print(i)
  time.wait(buffer_time_numbers)
  dev.Reset()
开发者ID:sesshomariu,项目名称:launchpad-matrix,代码行数:7,代码来源:codes.py


示例15: check_for_exit

def check_for_exit(poll_time=KEY_PRESS_POLL_TIME):
    time.wait(poll_time)
    if not event.peek():
        return

    ev = event.poll()
    if ev.type == pygame.KEYDOWN and ev.key == pygame.K_SPACE:
        sys.exit(0)
开发者ID:fjohnson,项目名称:ansidisplay,代码行数:8,代码来源:portrait.py


示例16: plan_mr_img

    def plan_mr_img(self):
        [r1,  r2, r3, r4] = [[50, 95],[50,135], [750, 100], [750, 130]]
        payload = [30,95]
        payload_img = pygame.image.load('payload.jpg')
        payload_img = pygame.transform.scale(payload_img, (45, 40))
        game_display = self.pygame.display_game(self.display_mode, self.caption)
        game_exit = False
        while not game_exit:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    game_exit = True
            if self.count_steps < 90:
                r1[0] +=3
                r2[0] +=3
                r3[0] -=3
                r4[0] -=3
                payload[0] +=3
                self.count_steps +=1 
            
            if self.count_steps == 90:
                r1 = [r1[0], r1[1]]
                r2 = [r2[0], r2[1]]
                p_center = self.math.find_center(r1, r2)
                #print p_center
                traj_r1 = self.math.plan_circular_trajectory(r1, p_center, self.angle_unit)
                traj_r2 = self.math.plan_circular_trajectory(r2, p_center, self.angle_unit)
                traj_payload = self.math.plan_circular_trajectory(payload, p_center, self.angle_unit)
                self.count_steps +=1
            if ((self.count_steps > 90) and (self.traj_steps < 30)):
                r1 = traj_r1[self.traj_steps]
                r2 = traj_r2[self.traj_steps]
                r3[0] -=1
                r4[0] -=1
                payload = traj_payload[self.traj_steps]
                self.count_steps +=1
                self.traj_steps +=1

            if ( (self.traj_steps >= 30) and (self.traj_steps < 150) ):
                r1[1] +=3
                r2[1] +=3
                r3[0] -=3
                r4[0] -=3
                payload[1] +=3
                self.count_steps +=1
                self.traj_steps +=1
            payload_tuple = (payload[0], payload[1])
            game_display.fill(self.color[0])
            pygame.draw.circle(game_display, self.color[3], r1,12)
            pygame.draw.circle(game_display, self.color[3], r2,12)
            pygame.draw.circle(game_display, self.color[1], r3,12)
            pygame.draw.circle(game_display, self.color[1], r4,12)
            game_display.blit(payload_img, payload_tuple)
            #pygame.draw.circle(game_display, self.color[2], payload,25)

            pygame.display.update()
            time.wait(100)          
        pygame.quit()
        quit()
开发者ID:HoangHuuPhuong,项目名称:MultipleRobotsSimulationPyGame,代码行数:58,代码来源:simuRobots.py


示例17: step

 def step (self):
     """Step forwards one frame."""
     t = time()
     dt = self.t + self.frame - t
     if dt > 0:
         wait(int(1000 * dt))
         self.t = t + dt
     else:
         self.t = t
开发者ID:ikn,项目名称:wvoas,代码行数:9,代码来源:sched.py


示例18: run

 def run(self):
     while(recording):
         if self.inst.poll():
             midi_events = self.inst.read(10)
             for note in midi_events:
                 if note[0][2] > 0: # filter out notes with velocity 0
                     self.noteList.append(midi_events[0])
                     time.wait(10)
     self.inst.close()
开发者ID:WillLynch,项目名称:query-by-lick,代码行数:9,代码来源:main.py


示例19: step

 def step(self):
     """Step forwards one frame."""
     t = time()
     t_left = self.t + self.frame - t
     if t_left > 0:
         wait(int(1000 * t_left))
         self.t = t + t_left
     else:
         self.t = t
开发者ID:Anstow,项目名称:TeamAwesome,代码行数:9,代码来源:sched.py


示例20: run

    def run(self, cb, *args, **kwargs):
        """Run indefinitely or for a specified amount of time.

run(cb, *args[, seconds][, frames]) -> remain

cb: a function to call every frame.
args: extra arguments to pass to cb.
seconds, frames: keyword-only arguments that determine how long to run for.  If
                 seconds is passed, frames is ignored; if neither is given, run
                 forever (until Timer.stop is called).  Either can be a float.
                 Time passed is based on the number of frames that have passed,
                 so it does not necessarily reflect real time.

remain: the number of frames/seconds left until the timer has been running for
        the requested amount of time (or None, if neither were given).  This
        may be less than 0 if cb took a long time to run.

"""
        self.stopped = False
        seconds = kwargs.get("seconds")
        frames = kwargs.get("frames")
        if seconds is not None:
            seconds = max(seconds, 0)
        elif frames is not None:
            frames = max(frames, 0)
        # main loop
        t0 = time()
        while 1:
            frame = self.frame
            cb(*args)
            t = time()
            t_gone = min(t - t0, frame)
            if self.stopped:
                if seconds is not None:
                    return seconds - t_gone
                elif frames is not None:
                    return frames - t_gone / frame
                else:
                    return None
            t_left = frame - t_gone  # until next frame
            if seconds is not None:
                t_left = min(seconds, t_left)
            elif frames is not None:
                t_left = min(frames, t_left / frame)
            if t_left > 0:
                wait(int(1000 * t_left))
                t0 = t + t_left
            else:
                t0 = t
            if seconds is not None:
                seconds -= t_gone + t_left
                if seconds <= 0:
                    return seconds
            elif frames is not None:
                frames -= (t_gone + t_left) / frame
                if frames <= 0:
                    return frames
开发者ID:Anstow,项目名称:TeamAwesome,代码行数:57,代码来源:sched.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python time.Clock类代码示例发布时间:2022-05-25
下一篇:
Python time.get_ticks函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap