View Single Post
  #2  
Old 11-26-2007, 01:02 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
If you need exactly 1800 samples, then setup a counter that will stop the timer after the specified number of samples have been recorded. Here is some sample code that should show you how it works:
Code:
import viz
viz.go()

MAX_SAMPLES = 1800
SAMPLE_RATE = 1.0 / 30.0

samples = 0
def onTimer(num):
	global samples
	if num == 1:
		
		#TODO: Process sample
		
		#Increment samples
		samples += 1
		if samples < MAX_SAMPLES:
			viz.starttimer(1,SAMPLE_RATE)
		else:
			print 'Finished collecting samples'
			
viz.callback(viz.TIMER_EVENT,onTimer)


def onKeyDown(key):
	global samples
	if key == ' ':
		#Clear samples and start timer
		samples = 0
		viz.starttimer(1,SAMPLE_RATE)

viz.callback(viz.KEYDOWN_EVENT,onKeyDown)
Reply With Quote