Hi All,

Apologies for my naivity in advance, but I am very new to the Python programming world - with experience mainly in Basic and Matlab.

I am studying my PhD and am currently trying to program using Python in the Vizard environment to create stimuli for experiments.

The purpose of the stimuli is to randomly display either one white circle or two white circles and then have them approach the observer at a particular speed.

The code is as follows...

``````import vizact
import math
import random
import whrandom
viz.go()

viz.clearcolor(0,0,0)
viz.MainView.setPosition(0,1.5,-10)

viz.startlayer(viz.POLY_FILL)
viz.vertexcolor(1,1,1)
NUM_DOTS = 10000.0
for i in range(0, NUM_DOTS):
angle= 360.0*(i/NUM_DOTS)
# Put a vertex at each of these, but jump back to zero in between
viz.vertex(0,0)
viz.vertex(x,y)

# Create Motorbike Headlight & Set Position to Off-Screen

# Define speed, distance and time
speed = 71.68 #40 mph
totaltime = 3.0
distance = speed*totaltime

# Set Speed, Time & Distance
# Set Initial Position as Off-Screen

# Create Motorbike Headlight & Set Position to Off-Screen

# Randomly Select MC or Car
# Define movement of lights
No_trials = 7
startpos = (0, 0, distance)
for i in range (0, No_trials):
move1 = vizact.goto(-0.8, 1.0, viz.DISTANCE, totaltime, viz.TIME)
else:
move1 = vizact.goto(-0.8, 1.0, viz.DISTANCE, totaltime, viz.TIME)
viz.mouse(viz.OFF)

I am sure that I am making a couple of fundamental errors, but I have become really stuck and was wondering if anyone could offer any assistance? The code runs, but will only ever display two headlights and does not appear to select randomly.

If you need any other info, please do not hesitate to ask,

Many Thanks

random.choice returns a random element of the list. Change your code

``````for i in range (0, No_trials):

random.choice returns a random element of the list. Change your code

``````for i in range (0, No_trials):

I have made the above adjustments, but the code does not seem to be looping - as it runs one trial and then stops.