Moving cursor stimuli

Can anyone tell how can I create a moving cursor as stimuli in Psychopy Builder?

1 Like

You simply put variables in the stimulus’ position field that change with time. You need to detail exactly what you mean by “moving” for anyone to give more specific suggestions.

Michael,

I am quite new with PsychoPy and I am not fully familiar with all of its capabilities.

Regarding the stimuli, I want to have a circle-like cursor moving horizontally in some trials and moving vertically in some other trials with constant velocity. I am not sure how can I proceed with PsychoPy to design such a thing.

Builder maintains a variable called t that represents the time elapsed in seconds since the start of the trial. So if you put an expression like:

(t, 0)

in the position field of stimulus, and set that field to update on every screen refresh, and set the units of the stimulus to be, say, cm, then the stimulus would move rightwards at a constant velocity of 1 cm per second while staying fixed vertically.

To make it go faster or slower (or to scale for using other units, like pixels or normalised units), multiply t by some factor:

(3 * t, 0)

To make it start from 10 units to the left of centre:

(-10 + t, 0)

etc.

If you want to mix horizontal and vertical movement from trial to trial, then you should have a pair of variables in your conditions file called, say horizontal and vertical, with values of 0 (don’t move in this direction) or 1 (do move in this direction), then put those variables in your formula so that either the horizontal or vertical component gets set to 0 on each trial:

(t * horizontal, t * vertical)
2 Likes

Thanks Michael!

That was very helpful.

Hi Michael,

I found this message really helpful, I got exactly the motion I wanted by following it. Thanks!

I was wondering if you can also help me with one additional question: how can I have the stimulus stop moving and stay on screen for a while (e.g. 1s) then vanish?

(I only have 2-day experience using Psychopy so far, hope the question makes sense…)

Thanks again!

You can achieve anything you describe like that by using a small snippet of code, to calculate the position based on certain conditions. But you might find that you can do it just using the graphical components. e.g. define one stimulus component do have a duration only for the period you want the movement to occur in. Then have another, otherwise identical stimulus, that appears at a constant position but only at the point in time when the other one disappears, so they look in effect to be there same stimulus. This second stimulus would be set to have a fixed duration of only 1 second.

Hi Michael,

Thank you for the quick reply! That was very helpful!

Hi Michael,

Me again, I have a follow-up question about using the variable t and hope you can help me as well.

This time I aimed to have a picture stay at the same position, while its size gradually changes as a function of t.

I made the size change working by using expressions such as (2t,2t) for “size[w,h]$”, while the picture size wouldn’t change in a “constant speed” by this way (as of course, here is a quadratic relationship between size and time instead of linear).

So my question is: is there a way to make the picture size changing in a “constant speed” like it is a linear function, and how should I write the expression?
(Hope the question makes sense too…)

Thank you very much for your time!

Your mathematical intuition is correct - area will increase with t2 if each side scales with t, so a solution might be to scale the sides with sqrt(t) instead (Builder automatically imports this square root function from the numpy library for you, along with a few other useful trigonometric functions).

Thanks Michael!

That was really helpful!