Dynamically Varying Polygon Vertices

OS: macOS 10.13.6
PsychoPy version: PsychoPy2 1.90.3
Standard Standalone?: Yes

What are you trying to achieve?:

I would like to vary the number of vertices dynamically, so that a polygon stimulus can be either a triangle or a circle. Specifically, I am trying to recreate Miyake et al’s (2004) experiment, which I am attaching a picture of.

What did you try to make it work?:

  1. Typing $shape_vertices (a condition name) into the “Num. Vertices” field.
  2. Searching the code for where I can tweak the settings.

What specifically went wrong when you tried that?:

  1. I cannot set the number of vertices to change every repeat. “It is not (currently) possible to vary the number of vertices dynamically” (Polygon Documentation)
  2. It appears I would need to create a new function, something like .setPolygonVertices, but my Python skills are not at that level.

What I am requesting:

I would like to know if it is possible to either set the number of vertices to change every repeat from the builder view, or how I might insert a few lines of code to accomplish this in the coder view.

If neither is possible or easy, I know my last option is to manually create the stimuli (only 2x2=4 total) in MS Word and use pictures as stimuli.

I am attaching my experiment, conditions file, and picture of the task I am trying to copy.

Thank you.

color_shape.psyexp (13.6 KB)
color_shape_stim.csv (261 Bytes)

The Builder polygon component doesn’t give you the flexibility that you would have if you were creating the stimuli in code. Fortunately there is a workaround that you can implement in Builder with no code at all.

  • Create two fixed polygon stimuli in Builder (e.g. a red circle and green triangle or whatever).
  • Add a boolean variable to your conditions file called, say, circle_trial. i.e. this will be 1 if you want a circle on this trial and 0 if you don’t.
  • In the opacity field of the circle stimulus, put circle_trial and set it to update on every repeat, so it will be visible on circle trials and invisible on non-circle trials.
  • In the opacity field of the triangle stimulus, put 1.0 - circle_trial, to get the opposite behaviour.
3 Likes

Oh my gosh, this is brilliant. I’ve followed your directions, and it works perfectly. Thank you so much!!