0

I'm using Builder v1.80.06

I can vary the position of a polygon every repeat easily enough

e.g. I have a Positions list

positions=[[1,1],[1.1,0.9],...]

and in the 'Position field' have :

$positions[0]

and then change it's value in a code block on each repeat.

BUT I want to vary the size in a similar manner with a $sizes list but get an error.

Looking at the generated code, the problem is at the object creation stage. the code generated is:

for a hard coded polygon (ie ok)

polygon_1 = visual.Rect(win=win, name='polygon_1',
    width=[1.5, .2][0], height=[1.5, .2][1],
    ori=0, pos=[0, -0.6],
    lineWidth=1, lineColor=[1,1,1], lineColorSpace=u'rgb',
    fillColor=[0,1,0], fillColorSpace=u'rgb',
    opacity=1,interpolate=True)

for one populated by a variable (not working):

polygon_2= visual.Rect(win=win, name='polygon_2',
    width=1.0[0], height=1.0[1],
    ori=0, pos=[0,0],
    lineWidth=1, lineColor=[1,1,1], lineColorSpace=u'rgb',
    fillColor=[1,0,0], fillColorSpace=u'rgb',
    opacity=1,interpolate=True)

It complains (rightly) that 1.0[0] makes no sense on the width and height parameters

Even though I have my sizes list instantiated in a code block right at the beginning of the experiment instead of reading $sizes[0] a default float value of 1.0 is used.

Any other suggestions for how to vary the polygon size dynamically at runtime using builder?

I could just take the generated code and drop it into coder I suppose and fix the problem but I want to hand this over to a researcher so would like for them to be able to maintain it.

thanks,

jacanterbury
  • 1,435
  • 1
  • 26
  • 36

2 Answers2

1

If you set size to be a tuple/list with a pair values [1.2,1.5] or [1,1] does that not fix it?

Jon
  • 1,198
  • 7
  • 8
  • Thanks - not sure I've understood you right. Did you mean create a variable in a code block - e.g. `mysize=[1.2,1.5]` and then on the polygon form set size to `my_size and` set dropdown to `set every repeat` and then change the value of `mysize` in code as required? Putting any variable in the 'size' field for the polygon object generates the same error as above (although the field label has a $ attribute implying a variable can be used – jacanterbury Jun 26 '14 at 11:28
1

When you change attributes at runtime, just change the attribute of an existing stimulus instead of instantiating a full new stimulus. The latter is quite heavy on ressources, causing unreliable timing. So do

stim = visual.Rect(win)  # instantiation, ressource heavy
stim.attribute = newValue  # change attribute. lighter.

I can think of two ways you could do it in a pretty neat way. The first is to set width and height explicitly instead of the size attribute, but using a size-like value. So (removing all parameters not of interest):

polygon_2 = visual.Rect(win)

# Unpack the x,y-sizes to the stimulus .width and .height attributes
newSize = (1.5, 0.2)
polygon_2.width, polygon_2.height = newSize

The second, if the size attribute is really important to use, is to use the Polygin with edges=4 to make it a rectangle:

polygon_2 = visual.Polygon(win=win, edges=4, size=(1.5, 0.2))

# Setting size
polygon_2.size = (0.8, 0.4)

Do try Jon's suggestion first. But the idea with visual.Rect and visual.Circleis to use substitute Polygon's size and vertices for something more relevant. So size can do unexpected things if width/height etc. are not 1.

Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
  • Jonas, I think the orig post was referring to use of Builder – Jon Jun 23 '14 at 09:16
  • Thanks Jonas. Nearly there: if I hardwire the polygon size to an initial value &set it `constant` I can use some code on the `Begin routine` tab to change the `size`. 2 points: if I change `.width` and `.height` explicitly nothing happens (no resizing but no errors) but if I set `size` then the polygon IS resized however, somewhat puzzling it appears to ignore the `units=norm` setting and instead it appears it does a percentage rescale dependent upon the initial hard-coded setting. e.g. so setting `polygon.size=[1.1,1.1]` has a different effect if the initial `size` value is varied. :$ – jacanterbury Jun 26 '14 at 11:52
  • The ``.width`` and ``.height`` behavior is unsurprising as these are not properties of visual.Polygons, thus just something you add yourself to the object. I have to check out the behavior of ``polygon.size`` and get back to you. – Jonas Lindeløv Jun 27 '14 at 21:29