| Reference | Downloads | Github

Outputting or inputting the position of the polygon

Hi all,

Apologies in advance for the potentially nonsense questions. I am very new to PsychoPy so I am not sure yet if what I need is even feasible.

I am trying to use PsychoPy for research with insects and the stimulus I need to present is very simple: just a small dot that moves from side to side, with the movement ideally changing in velocity in a controlled manner.

What I would like to achieve is to have the coordinates of the dot in a csv file and make PsychoPy read those coordinates and update the position at every frame taking the next row of the file. If importing a file for the position is not feasible, then I would like to at least be able to output the position of the polygon (defined with the builder or coder) to a csv file. Could someone tell me if one of these options is feasible and if so how to achieve it?

Thank you!

You can certainly have a loop (in Builder) which reads coordinates for a trial that is only 1 frame long (or some other very short time).

Alternatively, the position could be updated using code (e.g. for Brownian motion) and the coordinates saved into the data file.

Thank you for your reply!
Instead of having a loop, would it be possible to define the motion in the coder’s line ‘polygon.setPos((x,y), log=False)’? At the moment I have ‘polygon.setPos((sin(frameN/100)*1000,0), log=False)’ but would like to replace that motion with a specific x coordinate for each frame. Is this exactly what a loop would achieve?

I’m only experienced with using loops, but yes if you have an Excel with columns xPos and yPos then you should be able to set the position of the polygon component as $(xPos,yPos) each Repeat or use polygon.setPos(xPos,yPos) in code.

Your task seems quite similar to Moving objects on Pavlovia