Changing number of vertices of shape on each trial

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): 2021.2.3
Standard Standalone? (y/n) If not then what?: Y
What are you trying to achieve?:

I want to be able to determine the number of vertices a target has by pulling the information from an Excel file (i.e. I have a column ‘vert’ containing 3, 4 etc. for each trial).

What did you try to make it work?:

Shape → regular polygon
And then the variable name (‘vert’) in num vertices. Tried with and without $.

What specifically went wrong when you tried that?:
win=win, name=‘polygon’, vertices=vert,
NameError: name ‘vert’ is not defined

I want to get this online eventually so I’m trying to work in builder with code snippets, but I can’t even get setting ‘polygon.shape’ or ‘polygon.edges’ to something different in the ‘begin routine’ tab to change anything (the code runs, but the polygon shape doesn’t change from how it’s defined in the builder). Am I missing something obvious about how this works? Or is this just something that can’t be done?

Thanks for any help!

1 Like

I believe that this can’t be done. What I do is create separate polygon objects for each possibility and present the one I want.

shapes = []
#square
shapes.append(['square',[[.707,-.707],[-.707,-.707],[-.707,.707],[.707,.707]],' '])
#triangle
shapes.append(['triangle',[[.866,-.5],[-.866,-.5],[0,1]],' '])
#circle
shapes.append(['circle',[[0.000,0.866], [0.091,0.861], [0.180,0.847], [0.268,0.824], [0.352,0.791], [0.433,0.750], [0.509,0.701], [0.579,0.644], [0.644,0.579], [0.701,0.509], [0.750,0.433], [0.791,0.352], [0.824,0.268], [0.847,0.180], [0.861,0.091], [0.866,0.000], [0.861,-0.091], [0.847,-0.180], [0.824,-0.268], [0.791,-0.352], [0.750,-0.433], [0.701,-0.509], [0.644,-0.579], [0.579,-0.644], [0.509,-0.701], [0.433,-0.750], [0.352,-0.791], [0.268,-0.824], [0.180,-0.847], [0.091,-0.861], [0.000,-0.866], [-0.091,-0.861], [-0.180,-0.847], [-0.268,-0.824], [-0.352,-0.791], [-0.433,-0.750], [-0.509,-0.701], [-0.579,-0.644], [-0.644,-0.579], [-0.701,-0.509], [-0.750,-0.433], [-0.791,-0.352], [-0.824,-0.268], [-0.847,-0.180], [-0.861,-0.091], [-0.866,0.000], [-0.861,0.091], [-0.847,0.180], [-0.824,0.268], [-0.791,0.352], [-0.750,0.433], [-0.701,0.509], [-0.644,0.579], [-0.579,0.644], [-0.509,0.701], [-0.433,0.750], [-0.352,0.791], [-0.268,0.824], [-0.180,0.847], [-0.091,0.861]],' '])
if expInfo['expt'] != '15':
#diamond
    shapes.append(['diamond',[[1,0],[0,-1],[-1,0],[0,1]],' '])
#pentagon
    shapes.append(['pentagon',[[0,1],[.951,.309],[.588,-.809],[-.588,-.809],[-.951,.309]],' '])
#hexagon
#shapes.append(['hexagon',[[1,0],[.5,-.866],[-.5,-.866],[-1,0],[-.5,.866],[.5,.866]],' '])
#octagon
#shapes.append(['octagon',[[1,0],[.707,-.707],[0,-1],[-.707,-.707],[-1,0],[-.707,.707],[0,1],[.707,.707]],'n '])
#heptagon
    shapes.append(['heptagon',[[0,-1],[-.782,-.623],[-.975,.223],[-.434,.901],[.434,.901],[.975,.223],[.782,-.623]],' '])
#cross
#shapes.append(['cross',[[1,.25],[1,-.25],[.25,-.25],[.25,-1],[-.25,-1],[-.25,-.25],[-1,-.25],[-1,.25],[-.25,.25],[-.25,1],[.25,1],[.25,.25]],' '])
#parallelogram
    shapes.append(['parallelogram',[[1,.707],[.5,-.707],[-1,-.707],[-.5,.707]],' '])
#four pointed star
#shapes.append(['star',[[1,0],[.25,-.25],[0,-1],[-.25,-.25],[-1,0],[-.25,.25],[0,1],[.25,.25]],' '])
#trapezium
    shapes.append(['trapezium',[[.5,.707],[1,-.707],[-1,-.707],[-.5,.707]],' '])

shuffle(shapes)
showPic=-1
pic=[]
for Jdx in range(nPeople):
        pic.append(visual.ShapeStim(
        win=win,
        fillColor=white,
        lineColor=white,
        vertices=shapes[Jdx][1],
        pos = [0,0],
        size=.2
        ))

Did you ever get a solution? I have exactly the same problem!

I’m afraid I didn’t figure out any way to get it to work with a spreadsheet, sorry! (I was able to adjust the experiment so I didn’t need to change the shapes in the end - but thank you wakecarter for the code solution!)