Moving a circle polygon by using frame rate but it constantly appears and disappears

Hi !
I’m totally nex to PsychoPy and to coding, and I need a little help to improve my task.

What are you trying to achieve?:
I need to create a pursuit-fixation task. A target (black circle - made with polygon component - on a white background) is at the center of the screen for several seconds. Then, it moves to the right, then to the opposite left, then it come back to the centrer before going to the top, then at the opposite bottom and finally it comes back once again to the center. So, the drawing of the circle forms a cross shape.

Moreover, each time the circle reaches an extremity of the “cross shape” (4 times), it stops moving for 2s.

What did you try to make it work?:
Thanks to other forum topics, I was able to move the black circle using a loop with an excel file in which I put all the coordinates (x-axe and y-axe, in pixel) of the black circle. And so, thanks to the frame rate of my screen (59,977 Hz), the coordinates of the black circle are update every frame (thankc to the loop) and the circle moves for 4 pixel each frame, which in the end allows me to move the circle in a “smooth pursuit” looks.

Capture
Here an example of my excel file

Shape
Here the sequence of my task

(I’m pretty sure that a function exists and that using a code would allows me to do the same thing, but I know nothing about coding and I didn’t even know what kind of function allows this.)

What specifically went wrong when you tried that?:
The task works perfectly : the black circle moves in the way I want. BUT, because of the frame rate, the black circle is constantly appearing and disappearing, so that instead of being perfectly black, it si rather gray (which is normal because the coordinates’ circle are constantly update by the frame rate, and that update is perfectly perceptible).

So, my request is how can I make the circle move without it just appearing and disappearing ? (e.g, how can I make it constantly black despite the change of its coordinates ?)

I think that a code is needed to solve this, and that I should probably use a code to make the circle move instead of the loop with the excel file, but like I said at the beginning, I have know idea of which function to use.

Thanks for you help !

Hi @Anthony_C,

Thanks for your detailed description!

You’re perfectly correct - rather than use a loop to set the position of the circle on each frame, you’ll need to use a code component. Please could you share your conditions file here so that I can write the necessary code to recreate the co-ordinates in the code component?

Thanks!

Kim

Hi @Kimberley_Dundas ,

Thank you for your help !

Here is my conditions file
Coordinates.xlsx (26.4 KB)

If you need further details, let me know !

Anthony

Hi @Anthony_C,

Sorry for the delay here, I’m struggling to replicate your problem on my side - would you mind also sharing your .psyexp file here?

Thanks,

Kim

Hi @Kimberley_Dundas ,

Don’t worry, I appreciate your help. Here it is :

Pursuit_4.psyexp (61.7 KB)

Anthony

Ah @Anthony_C I see what I was doing now!

Could you please try running this updated version? Just note that you’ll have to end the routine after a certain amount of time or on a keypress/mouse click etc now, as the duration of the circle routine is infinite at the minute.

Pursuit_4_UPDATED.psyexp (63.8 KB)

Thanks,

Kim

Thank you so much @Kimberley_Dundas it’s working great ! Exactly what I needed !

I juste have a little question : I have another experiment, which is basically the same but without the 2s-fixation on the extremities. So I put a new conditions file (with less lines) in the loop : it’s working again, the circle is fully black, but the experiment stops sooner than expected and this message appears on the Runner : “IndexError: list index out of range”.

I guess this is because the new conditions file contains less lines and a change is needed in the code, but I don’t see where. Maybe the " posIndex = 0 " in the began routine ?

Thanks,

Anthony

Hi @Anthony_C,

I’m so pleased that this has solved the problem for you!

You’re totally right again here - I think actually if you just add the conditions file again (or save it as a different name and add it again), this could solve the problem.

Let me know how this works :slight_smile:
Kim

Hi @Kimberley_Dundas ,

Unfortunately, adding or renaiming the conditions file again doesn’t work. The task/code works in itself, but the end of the code causes the end of the task, whereas I have other routine after the code.

Here is what the Runner says about it :

It seems like a problem occurs at the line 341, but I don’t understand what line it is (I don’t thinks it’s an excel line because my Excel file contains more than 341 lines and is read to the end by the code) and why the log=False appears.

Also, the “IndexError: list out of range” seems to suggest that the code want to access an item that doesn’t exist, and thus ends the experiment instead of just puting an end to the loop routine.

Also, and maybe it is the cause of this sooner ending, I didn’t put a code to end the routine (at first sight I thought that the routine ended by itself with no problem, I hadn’t seen that the routine after the loop didn’t start). I tried some code in the “End Routine”

for items in trials.trialList:
trials.finished=1533

to put an end to the routine after the last line is read (line 1533 for example) but it’s doesn’t work (pretty sure that I didn’t write it correctly). What function I have to use to called the last line (1533) and specifiy that the routine (but not the experiment) must end after that line is read ?

Thanks a lot,
Anthony

Thanks for sharing this @Anthony_C,

Could you attach your psyexp and conditions files for this version of the task? I can take a look at what’s going on then :slight_smile:

Thanks,

Kim

You’ll find the psyexp and my conditions file. 2 things are changed compared to my original task : no immobile circle at the extremities and the circle disaeaper 2 times behing a white rectangle.
So like I said previously, everything is fine except the fact that the experiment ends after the loop routine whereas it must end after the “End” routine.

Here are the files :
Occlusion.psyexp (51.9 KB)

List_occlusion.xlsx (19.9 KB)

Thanks a lot,

Anthony

Hi @Kimberley_Dundas ,

I wanted to know if you had time to look at my script to see why my task stops abruptly after the loop regardless of the routine that follows?

On my side, I tried adding an external loop to make the task repeat 5x in a row but the same problem appears. Here is the script.

Error PsychoPy

Occlusion.psyexp (56.4 KB)
Occlusion_list.xlsx (21.0 KB)

Thanks,

Anthony

Hello,

I had a look at this just and I managed to remove the error, but it then crashes once the circle stops, it might work differently for you though so please try it. In your each frame tab I added:

while posIndex == 961:
    continueRoutine = False

And then I deleted what was in the end routine tab. I think the issue with the index out of range was that it didn’t have anything telling it to stop. So it would get to posIndex 962 and throw that error because there was no code to say “once it gets to 961 it should end”.

Hi @Jdigg ,

Thank you for trying ! Indeed, the end routine tab was a try to stop the routine after the final excel line was read, but doesn’t worked either.

Unfortunately, even with the “while posIndex”, it doesn’t work with me either, and the problem are apparently now on the line 486 (yesterday it was on ligne 372)

Error PsychoPy 2

Line 483*

The length of the Excel file is slightly longer now, the last line is 1057. But it doesn’t change anything.

Occlusion_list.xlsx (21.0 KB)