psychopy.org | Reference | Downloads | Github

Help with looming, randomized, branching experiment

What are you trying to achieve?:

  • Randomized blue/orange circles
  • Upon keypress, will expand to larger circle (must stay same color). This expansion must be smooth and take frame rate into account.
  • 5 orange/blue circles respectively, for a total of 10 trials. No color must repeat for more than 2 (consecutively).

What did you try to make it work?:

  • Tried to do all this in coding first, but don’t have much experience with python and gave up. Now trying a mix of both builder and coder.
  • I made an excel sheet with [-1,-1,1] (blue) and [1,0,-1] (orange) cells, set a polygon to 256 vertices and used the excel sheet to randomize fillColor. Nested 2 inner loops with this code (at beginning of experiment, although I tried all positions):

if(polygon.fillColor == ‘[-1,-1,1]’):
BLUE = 1
ORANGE = 0
else:
BLUE = 0
ORANGE = 1

  • For blue trial, I set nReps to BLUE and for orange trial, set nReps to ORANGE

What specifically went wrong when you tried that?:

  • Circles only expand to a larger orange circle upon key press, even if blue. Seems like it isn’t checking the color. Thought this was bad positioning of code, but trying to change that didn’t work.
  • Also don’t know how to make them expand smoothly. I believe its something to do with framerates, but unsure how to approach.

Any help would be great! Thank you. I’m only a beginner.

  • Use your conditions file to control the colour of the polygon at the start of the routine. So then it will be either blue or orange, so you don’t need to do anything different in code, as the colour doesn’t influence the change in size.
  • Split your trial across two routines. The first will show the constant size stimulus, and wait for a key press:
    • Insert a circle, with its colour controlled by the relevant variable from the conditions file.
    • Its size is set to a constant value.
    • Insert a keyboard component, set to “force end of routine”.
    • Both the keyboard and polygon components have no set duration.
  • The second routine will show the looming stimulus:
    • Again, have a polygon stimulus with its colour controlled in the same way.
    • Its size field will now contain a formula that is time-related, using the variable t, which contains the time in seconds since the start of the routine. e.g.
50 + t * 5

If the units are set in pixels, say, this would start (from t == 0) at a width and height of 50 pixels and grow by 5 pixels per second. Tweak these as required. It doesn’t have to be linear of course, you can select a different growth function as required.

The only code necessary here is that expression in the “size” field of the stimulus on the second routine.

1 Like

Thank you so much. That worked out great. I’m trying to get some of the looming circles to randomly switch their color to green. This is what I’ve added into my code, but I get some syntax errors that I’m unsure how to fix. (This is at the beginning of the experiment):

random = [0, 1]
random.shuffle(random)

if (random) == '1'
    and CircleBig.size == 3100:
    polygon.fillColor = [-1,1,-1]

CircleBig is my loom circle, with size == $[200 + t*50].

Updated code, which now works and the experiment boots/looms BUT will not actually change to green randomly. Just blue/orange random, looming circles upon keypress:

import random

green = [0, 1]
random.shuffle(green)

if (green == ['1']) and (CircleBig.size == ['500, 500']):
    CircleBig.fillColor = [-1,1,-1]
    CircleBig.fillColor /= Color

Not sure about the whole CircleBig.fillColor /= Color. I just put that there to ensure that its changing colours from my previous $Colour variable (from an excel sheet).

Hi. If you want to generate a random number between 0 and 1 and based on that switch/not switch color of your circle to green, you’re better off with just:
green = randint(0, 2)
Then your if statement needs to be changed to
if green == 1 and CircleBig.size == ['500,500']:

Also, am not aware of the rest of your code, but if your CircleBig.size variable is a list containing two integers (numbers), and I would assume it is, then you might be okay dropping ' ' and just writing
if green == 1 and CircleBig.size == [500,500]:

Hope this helps,

1 Like

My code right now still changes to green halfway through, but for every circle rather than a random selection of them. I’m not sure what to change. Even when I set green = 0 and keep the if green == 1 statement, the circles change to green. I feel like the solution is fairly simple but going way over my head.

from random import randint

green = randint(0,2)

if green == 1 and frameN >= 60:
        CircleBig.fillColor = [-1,1,-1]

For anyone looking at this later: I had an issue with where I placed my code. I set green = randint to be executed each frame. Instead, I placed it at the beginning of my loom routine and kept the if statement to be executed each frame (since dependent on FrameN >= 60).