# Pseudorandom Order and Timing of Animations

OS (e.g. Win10): Mac (Monterey 12.1)

PsychoPy version (e.g. 1.84.x): v2021.2.3

Standard Standalone? (y/n) If not then what?: Y

What are you trying to achieve?: I am trying to create an experiment in builder that has some complicated counterbalancing. Here is the specific design:

Participants see a sequence of shapes (selected from cloud, moon, star, square). For one block (8 trials) two shapes appear in a predictable sequence (AAAB). For the other block (8 trials) the other two shapes appear in an unpredictable sequence (i.e., DCCC, CDCC, CCDC). Each “shape” appears for 2.5 seconds so that one trial lasts for 10 seconds in total. For both blocks, between each of the 8 trials a short video plays (need to jitter the timing of this video between 10-15 seconds). Within a block, each shape is associated with a sound (S1, S2, S3, S4) and a direction (left, right, up, down). For each participant, the shape, sound, and direction should be randomized and the block order should be counterbalanced.

Example of what a participant might see:

Predictable sequence (AAAB) first where A is a square that moves left to right and appears with S2 and B is a moon that moves up and down and appears with S4.
Unpredictable sequence second (8 trials that are pseudo-random- the same order, such as AABA does not appear twice in a row) where A is the star that moves down to up and appears with S3 and B is a cloud that moves right to left and appears with S1.

So from above, we see that for a single participant a sound and direction are paired with one shape consistently across the trials.

What did you try to make it work?:

I have tried to build this in builder but I am completely lost with how to create such a randomization using loops. I also do not know how to get the shape to move at one rate (i.e., starts at (.30,0) and ends at (-.30,0) for the right to left movement) while the sound plays at another (i.e., the sound plays for the entire 2.5 seconds while the shape moves across the screen). I thought about making little videos of the shapes but this makes it more difficult to counterbalance shape and direction and also the videos were not loading fast enough.

This experiment was originally designed by someone else in MATLAB and I have tried to adjust the code to move it to Python but I have no familiarity with Python so I got stuck when it came to converting MATLAB struct to Python.

If you want something to move from [-.3,0] to [.3,0] in 2.5 seconds then you could set the position to update each frame as

[-.3+.6*t/2.5,0]

For the randomisation you could have concentric loops where the outer loop points to the spreadsheet and the inner loop has four repetitions. The shape could be based on sequence[innerloop.thisN]]

e.g.

thisShape = ''
if  sequence[innerloop.thisN]] == 'A':
thisShape = 'cloud.png'
elif  sequence[innerloop.thisN]] == 'B'
thisShape = 'moon.png'
elif  sequence[innerloop.thisN]] == 'C'
thisShape = 'star.png'
elif  sequence[innerloop.thisN]] == 'D'
thisShape = 'square.png'

Thank you! I appreciate your assistance. I have tried creating a column in my conditions file for the position but when I try to run it I get the error that “t” has not been defined. I also tried just putting [-.3 + .6*t/2.5,0] in the Position field but I got the same error. Finally, when I tried creating a column for each co-ordinate (x, y) in my conditions file it gave me an error about converting string to float.

I also tried changing from exp settings to pix but the issue remains

Have you changed the setting to Each Frame from Constant?

It’s generally safer to have separate x and y columns in the conditions file rather than to enter coordinates.

I created a completely empty experiment with nothing but a single image. Here, I was able to get the shape to move across the screen by entering [-.3+.6t/2.5,0] into the Position field in builder. However, when I try to upload that same information from a .csv file I get a warning (see below). I have also tried where I have two columns (DirectionX and DirectionY). If I put [-.3+.6t/2.5] into the DirectionX column, I get the same error. If I remove the square brackets and just put -.3+.6t/2.5 I can now specify my Conditions csv in a loop but when it runs I get an error: could not convert string to float: '-0.3+0.6t/2.5’

I assume the ’ ’ mean it is being read as a string, but I am not sure how to remove those (they do not appear in my csv).

Thank you!

Your spreadsheet should contain the numbers you want for your equation (in separate columns), not the full equation with t.