Hello, I’m a beginner to code on PsychoPy so I need help to program my experiment.
In this experiment, a gray ball of fixed size (30mm diameter) is displayed in the center of the screen. Above it, a white opening in the form of a circle is shown. The size of the opening varies from a diameter of 3mm to 60mm, resulting in a total of 20 sizes. I would like all participants to encounter, in a block of 20 trials, each opening size once in a random order. Below the gray ball, a white cross (in the shape of an X) is displayed.
The purpose of the task is that if the ball can pass through the opening, the participant must move (without clicking) the mouse over the opening. If the ball cannot pass through the opening, the participant must move (without clicking) the mouse over the cross.
A trial is structured as follows:
- Presentation of a gray fixation cross alone (max 10 seconds), the participant must click on it with their mouse to start the trial.
- Display of the stimulus configuration: ball, opening, cross X. The participant moves the mouse over the X or the opening. Note that by clicking on the fixation cross just before, the participant finds themselves in the middle of the ball with their mouse. Max 10 seconds or participant response.
In the experiment, I want to record two variables. The first variable is the participant’s response: whether they moved the mouse without clicking on the cross or the opening. The second variable is the initiation time, which corresponds to the time between the appearance of the stimuli and the moment when the participant starts moving their mouse to respond.
1 block = 20 trials, 1 for each opening size, randomized. I want 5 blocks in my experiment.
I managed to code the beginning of the task up to the appearance of the stimuli after clicking on the fixation cross (code below). However, I’m stuck for the rest, either PsychoPy bugs and stops responding, or I get error messages. I’m not sure how to proceed, so if you have any ideas for isolating the time between stimulus presentation and the start of movement (leaving the ball), and if the participant moves their mouse over the opening or the cross, I would really appreciate it.
Thank you
KB
from psychopy import visual, event, core, monitors
import random
from numpy import linspace
Création de la fenêtre
win = visual.Window(size=(800, 600), color=‘black’, units=‘pix’)
Création des stimuli
ball = visual.Circle(win, radius=56.69, pos=(0, 0), fillColor=‘gray’, lineColor=None)
opening = visual.Circle(win, radius=30, pos=(0, 175), fillColor=‘white’, lineColor=None)
chemin_image = “cross.jpg”
cross = visual.ImageStim(win, image=chemin_image, pos=(0,-175))
chemin_image = “fixationcross.png”
false_circle = visual.Circle(win, radius=10, pos=(0, 0), fillColor=‘blue’, lineColor=None)
fixation_cross = visual.ImageStim(win, image=chemin_image, pos=(0,0))
fixation_ball = visual.Circle(win, radius=8, pos=(0, 0), fillColor=‘gray’, lineColor=None)
Générer les tailles d’ouverture
opening_sizes = linspace(5.67, 113.4, num=20) # Génère 20 valeurs de 5.67 à 113.4 inclusivement
random.shuffle(opening_sizes) # Mélanger aléatoirement
Boucle pour les blocs
for block in range(5): # 5 blocs
# Boucle pour les essais
for opening_size in opening_sizes:
# Affichage de la croix de fixation
fixation_cross.draw()
fixation_ball.draw()
win.flip()
mouse = event.Mouse()
response_clock = core.Clock()
response_clock.reset()
click_detected = False
while not click_detected and response_clock.getTime() < 10:
if mouse.getPressed()[0]:
if fixation_ball.contains(mouse):
click_detected = True
# Affichage des stimuli
opening.setRadius(opening_size) # Taille de l'ouverture
ball.draw()
opening.draw()
cross.draw()
false_circle.draw()
win.flip()
# Attendre que la souris commence à bouger
response_clock_initiation = core.Clock()
response_clock_initiation.reset()
???..???
# Attendre la réponse du participant
participant_response = None
response_clock = core.Clock()
response_clock.reset()
while response_clock.getTime() < 10: # Attendre max 10 secondes pour la réponse
if mouse.isOver(opening):
participant_response = 'opening'
break
elif mouse.isOver(cross):
participant_response = 'cross'
break
if participant_response is None:
participant_response = 'NR'
# Enregistrer les données de l'essai
print(f"Block: {block + 1}, Opening Size: {opening_size}, Response: {participant_response}, Initiation Time: {initiation_time}")
Fermeture de la fenêtre à la fin de l’expérience
win.close()