View Single Post
  #2  
Old 08-03-2009, 04:51 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Your script was only creating 2 object, even when more than 2 distractors were selected. I modified your script to dynamically create the objects based on the number of distractors. I also modified the sceneOn function to be more general in positioning the objects.

I'm still not sure what you mean by placing the objects in a semi-circle. The list of positions you have pretty much places all the objects in a vertical line.

Anyway, here's the modified script:
Code:
import viz
import viztask
import random
viz.go()

Z_dist = -5
#viz.move(0,0,Z_dist)
viz.MainView.move(0.5,0,-10)

# Add distractor and target objects
ballsize = [2.0,2.0,2.0,1.0,1.0,1.0]

# Set up zones for the objects to appear on the screen
choice = ['2', '4', '6', '8']
select  = viz.choose('How many distractors?', choice)
numDistractors = int(choice[select])

#make a list with the objects in it
objects = []

# Distractor ball
for x in range(numDistractors-1):
	distractor = viz.add('soccerball.ive')
	distractor.setScale(ballsize[0],ballsize[1],2)
	distractor.addAction(vizact.spin(0,1,0,100))
	objects.append(distractor)

# Target Ball
target = viz.add('ball.wrl')
target.setScale(ballsize[3],ballsize[4],1)
target.addAction(vizact.spin(0,1,0,100))
objects.append(target)

# keep 2 positions in an array
pos = [[-1.0,0.0,Z_dist],[-1.0,0.5,Z_dist],[-2.0,1.0,Z_dist],[-1.0,1.5,Z_dist],[-1.0,2.0,Z_dist],[-1.0,2.5,Z_dist],[-1.0,3.0,Z_dist],[-1.0,3.5,Z_dist]]

def sceneOn(num):
	
	# Get random sample of positions
	rand_positions = random.sample(pos,numDistractors)
	
	# Apply positions to objects
	for p,o in zip(rand_positions,objects):
		o.setPosition(p)

sceneOn(1)
Reply With Quote