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 viztask
import math
import random
import whrandom
viz.go()
viz.clearcolor(0,0,0)
viz.MainView.setPosition(0,1.5,-10)
# Create first headlight
viz.startlayer(viz.POLY_FILL)
viz.vertexcolor(1,1,1)
Radius = 0.1
NUM_DOTS = 10000.0
for i in range(0, NUM_DOTS):
angle= 360.0*(i/NUM_DOTS)
x = Radius*math.sin(angle)
y = Radius*math.cos(angle)
# Put a vertex at each of these, but jump back to zero in between
viz.vertex(0,0)
viz.vertex(x,y)
headlight1 = viz.endlayer()
# Create Motorbike Headlight & Set Position to Off-Screen
headlight3 = headlight1.copy()
headlight3initial = (0, 1000, 10)
headlight3.setPosition(headlight3initial)
# Define speed, distance and time
speed = 71.68 #40 mph
totaltime = 3.0
distance = speed*totaltime
# Create Copy of First Headlight as Second Headlight
# Set Speed, Time & Distance
# Set Initial Position as Off-Screen
headlight2 = headlight1.copy()
viz.link(headlight1,headlight2,priority =1, offset =(1.6,0,0))
headlight1initial = (-0.8,100, distance)
headlight1.setPosition(headlight1initial)
# Create Motorbike Headlight & Set Position to Off-Screen
headlight3 = headlight1.copy()
headlight3initial = (0, 100, distance)
headlight3.setPosition(headlight3initial)
# Randomly Select MC or Car
# Define movement of lights
No_trials = 7
def headlightmove():
startpos = (0, 0, distance)
for i in range (0, No_trials):
random.choice([headlight3, headlight1])
if headlight1:
headlight1.setPosition(startpos)
move1 = vizact.goto(-0.8, 1.0, viz.DISTANCE, totaltime, viz.TIME)
headlight1.add(move1)
else:
headlight3.setPosition(startpos)
move1 = vizact.goto(-0.8, 1.0, viz.DISTANCE, totaltime, viz.TIME)
headlight3.add(move1)
viz.mouse(viz.OFF)
yield viztask.waitMouseDown(viz.MOUSEBUTTON_LEFT)
viztask.schedule(headlightmove())
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