WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 10-22-2008, 05:51 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I modified your script to randomly loom a new cube every iteration, and to handle the case if no reaction was registered for a certain amount of time. I also place the cube back to the original location once the reaction is entered.

Code:
import viz
import vizact
import viztask
import random

# Time limit for keyboard reaction
REACTION_TIME_LIMIT = 5.0

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

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?')

# List of cubes
cubes = []
for row in [0,2,4]:
	for col in [0,-3,3]:
		pos = (col,row,0)
		cube = viz.add('box.wrl',cache=viz.CACHE_CLONE,pos=pos)
		cube.originalPos = pos
		cubes.append(cube)

# Function that will update cube rotation every frame
def RotateCubes():
	increment = ROTATE_SPEED * viz.elapsed()
	for cube in cubes:
		cube.setAxisAngle([0, 5, 20, increment],viz.REL_PARENT)
	
vizact.ontimer(0,RotateCubes)

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

# 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 2 seconds
		yield viztask.waitTime(2)
		
		# Randomly loom a cube
		randomCube = random.choice(cubes)
		backAndFourth = vizact.sequence([vizact.goto(0, 0, -1, 1), vizact.goto(randomCube.originalPos, 1)])
		randomCube.addAction(backAndFourth)
		
		#Wait for next frame to be drawn to screen and save display time
		yield viztask.waitDraw(d)
		displayTime = d.time
		
		#Wait for keyboard reaction or timeout
		waitKey = viztask.waitKeyDown(None,d)
		waitTimeout = viztask.waitTime(REACTION_TIME_LIMIT)
		
		yield viztask.waitAny([waitKey,waitTimeout],d)
		
		if d.condition is waitKey:
			
			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
			
		else:
			
			print 'Reaction timeout exceeded'

		# Restore cube to original location and stop looming action
		randomCube.setPosition(randomCube.originalPos)
		randomCube.clearActions()
		
# Defines a callback for functions
viztask.schedule(SaveData())
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieve Object names Geoffrey Vizard 11 12-11-2009 04:26 AM
Can you link the position of a tracker to the orientation of an object? michaelrepucci Vizard 1 09-19-2008 10:23 AM
Getting object position in screen coordinates v-Salik Vizard 1 10-19-2007 03:41 PM
picking problem... k_iwan Vizard 2 07-27-2007 07:57 PM
rotate to object jargon Vizard 1 08-08-2005 12:20 PM


All times are GMT -7. The time now is 08:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC