Hi everyone,
I’m new to Psychopy and I’m working on creating an online experiment where subjects will see lines of different lengths and then be asked to draw the line they just saw using a mouse. Specifically, I want them to be able to increase the length of the line by 4 pixels with each scroll up and decrease it by 4 pixels with each scroll down.
So far, I’ve managed to create the experiment, and it seems to be working fine. However, after I press ‘n’ to proceed, I’m not seeing the probe where mouse input is supposed to be shown. I’m not sure what I’m missing.
Here’s the code I’ve written:
from psychopy import visual, core, event
Create a list of line lengths
line_lengths = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500]
Create a window
win = visual.Window([1366, 768], monitor=“testMonitor”, units=“pix”)
Create a text stimulus to instruct participants
instruction_text = visual.TextStim(win, text=‘Press “n” key to start’, color=‘white’)
instruction_text.draw()
win.flip()
Wait for the ‘n’ key press to start the experiment
keys = event.waitKeys(keyList=[‘n’])
Function to handle keyboard responses
def handle_keyboard_response():
global length
keys = event.getKeys([‘m’, ‘b’])
if ‘m’ in keys: # Increase line length by 4 pixels when ‘m’ is pressed
length += 4
elif ‘b’ in keys: # Decrease line length by 4 pixels when ‘b’ is pressed
length -= 4
Loop through each line length
for length in line_lengths:
# Clear the window
win.flip()
# Create a line stimulus with the specified length
line = visual.Line(win, start=(-length/2, 0), end=(length/2, 0), lineColor='white')
# Loop to update line length based on keyboard responses
while True:
line.draw()
handle_keyboard_response() # Check for keyboard responses
win.flip()
if 'n' in event.getKeys(): # Press 'n' key to confirm line length
break
# Update the window to display the line
win.flip()
# Wait for a specified duration (e.g., 2 seconds) before presenting the next line
core.wait(2)
Close the window and end the experiment
win.close()
core.quit()
Any help or suggestions would be greatly appreciated!
Thanks,