View Single Post
  #7  
Old 10-21-2008, 07:59 AM
ptjt255 ptjt255 is offline
Member
 
Join Date: Oct 2008
Posts: 24
Hi - I have been working on this all day and I'm still having difficulty in getting the objects to loom randomly, in the below script I have one object looming successfuly. Pressumably there also needs to be an if statement somewhere that says if key isn't pressed after x time move to next object.

Code:
viz.go()
viz.mouse(0)
viz.cursor(viz.OFF)

# Sets viewpoint at z meters away
viz.move(0,0,-10)

# Asks for the participant number
subject = viz.input('Enter the participant number?')

# Add a cube
cube1 = viz.add('box.wrl')

# Sets the speed of the rotation for all 9 cubes
speed = 50

# Sets the speed of the timer for all 9 cubes
UPDATE_RATE = 0.001

# Sets a variable that will hold the angle
angle = 0

# Sets the rotation rate degrees/sec
rotate = 270

# Positions the first row of cubes
cube1.setPosition(0,0)
cube2 = cube1.copy()
cube2.setPosition(-3,0)
cube3 = cube1.copy()
cube3.setPosition(3,0)

# Position the second row of cubes
cube4 = cube1.copy()
cube4.setPosition(0,2)
cube5 = cube1.copy()
cube5.setPosition(-3,2)
cube6 = cube1.copy()
cube6.setPosition(3,2)

# Position the third row of cubes
cube7 = cube1.copy()
cube7.setPosition(0,4)
cube8 = cube1.copy()
cube8.setPosition(-3,4)
cube9 = cube1.copy()
cube9.setPosition(3,4)

# Define speed and rotation of cubes
def mytimer(rotate):
	global angle 
	angle = angle + (speed * viz.elapsed())
	cube1.rotate(0, 5, 20, angle)
	cube2.rotate(0, 5, 20, angle)
	cube3.rotate(0, 5, 20, angle)
	cube4.rotate(0, 5, 20, angle)
	cube5.rotate(0, 5, 20, angle)
	cube6.rotate(0, 5, 20, angle)
	cube7.rotate(0, 5, 20, angle)
	cube8.rotate(0, 5, 20, angle)
	cube9.rotate(0, 5, 20, angle)

# Opens file 'response.txt' in write mode
file = open('reaction_time', 'a')

backAndForth = vizact.sequence([vizact.goto(0, 0, -1, 1), vizact.goto(0, 0, 0, 1)])

# Define a function that records reaction times in response to a looming cube
def SaveData():
	#Data for getting values from wait conditions
	d = viz.Data()
	while True:
		#Wait random amount of time
		yield viztask.waitTime(2)
		# Cube looming
		cube1.addAction(backAndForth)
		#Wait for next frame to be drawn to screen
		yield viztask.waitDraw(d)
		# Calculate reaction time
		displayTime = d.time
		#Wait for keyboard reaction
		yield viztask.waitKeyDown(None,d)
		reactionTime = d.time - displayTime
		# Create the output string
		out = str(reactionTime) + '\t''\n' 
		# Write the string to the output file
		file.write(out)
		print 'Reaction time:',reactionTime

# Defines a callback for functions
viz.callback(viz.TIMER_EVENT, mytimer)  
viz.starttimer(1, UPDATE_RATE, viz.FOREVER)
viztask.schedule(SaveData())
Reply With Quote