How to Move a Stimulus along a Vector (and not only left or right)

Hey guys,

I’m trying to build a neurological experiment, in which the participants of the study need to move a joystick to make a cursor hit a target to the left or right.
At the moment the participants can see the cursor at the updated position the whole time throughout each trial.
We want to change that, so that the Cursor moves with the Joystick position input just for a certain radius and then moves on its own along a certain Vector.

I used this piece of Code to just make an Object move in 2D space along the x or y axis. Now, how can I integrate a Vector into this Code? So that the Stimulus (in this case a circle, we want to change that later to our Code and use the cursor) is not moving just along x or y axis but in all 2D space along a Vector? I would love to get some insights form you.

This is the Code:

import os
from psychopy import visual, event, core

win = visual.Window(units = 'pix', color = 'black') # Set the window

x = 0 # initial positions
y = 0

# create just once, no need to specify a position yet:
circle = visual.Circle(win, radius = 10, fillColor= 'yellow')

while True: # draw moving stimulus

    x -= 2 # make circle constantly move left(here i want to use a Vector)
    circle.pos = [x, y] # directly update both x *and* y
    circle.draw()
    win.flip() # make the drawn things visible

win.close()
core.quit()

What you basically need is a function to take input of a single value and give an output of an x & y pair. You could define this at the beginning like so:

def yEqualsTwoX(z):
    """Function to convert a single value to the corresponding x and y coords on the vector y=2x"""
    x = z
    y = 2z
    return (x, y)

(but obviously replacing y=2x with whatever your vector needs in terms of conversion)

Then use it like this:

z = 0
while True:
    z -= 2
    circle.pos = yEqualsTwoX(z)

hey Tim !
thank you so much for the fast reply ! What you suggest makes a lot of sense. I will check it out immediately.

Greetings,

Finn

Hello again!
It works quite well :slight_smile: thank you ! Now I have to try to get the factor in front of “y” out of my sampled Joystick Data for each trial for the first datapoints.

Greetings and thanks again !