Rotating stimulus doesn't rotate online

Hi all,

I’m trying to create an experiment that involves a continuously rotating (animated) polygon. I’ve made a triangle polygon in the Builder, and added a custom code component (see picture) that adds 1 degree to the orientation of the polygon for each frame. This works perfectly offline, but when I upload the experiment to Pavlovia, it doesn’t rotate anymore and just shows a static picture of a triangle. I don’t get any error messages.

Some things I’ve tried to fix it:

  • Tried different browsers.
  • Set the orientation of the polygon to “set every frame” in the Builder. This however also causes it to stop rotating offline, so I keep it set to “constant.”
  • Tried the code component with different polygons, of different sizes, and with images. They all rotate offline, but not online.

Does anyone know what the problem might be here?

What does polygon.setOri(1,’+’) mean? Try polygon.setOri(t)

Why do you have polygon.draw()? Your first line suggests that polygon is a component in the current routine and will therefore be autodrawn once started.

Please do bookmark my crib sheet, if you haven’t already found it.

1 Like

Hi, thanks for the help, wakecarter.

Why do you have polygon.draw()?

I removed it. After reading your crib sheet, I now understand that was redundant. Thank you for that. I’m quite new to programming and I’m learning as I go (that crib sheet is a great help!).

What does polygon.setOri(1,’+’) mean?

It adds 1 degree to the orientation of the polygon each frame. I had written it like that because the next step for my experiment is to change the “1” to a custom value that a participant can change with a key press. So eventually, the code would be something like setOri(customvalue, ‘+’) where customvalue is defined as the number of key presses.

Try polygon.setOri(t)

I uploaded the polygon with this code component instead, and now it does move! However, it moves extremely slowly, I think it would take several minutes to just complete one rotation. It also moves counterclockwise online, whereas offline it moves clockwise. And also, with this setup, I don’t think I could implement the step I mentioned above? Is there any way around that?

Now you’ve shown it can move the next step is easy.

Set thisOri = 0 in Begin Experiment

Use the following in Each Frame. Customise to suit your desired rotation speed.
thisOri += 1
polygon.setOri(thisOri)

If you want it moving in the same direction offline and online then use +=1 offline and -=1 online in your Both component.

1 Like

That worked! Thank you so much!

But now that my stimulus is rotating I already ran into another problem… I want participants to be able to speed up or slow down the rotation speed by pressing the “up” or “down” arrows on their keyboards, so I added this code:

if polygon.status == STARTED:
        thisOri += newOri
        polygon.setOri(thisOri)
if event.getKeys('up'):
        newOri += 1
if event.getKeys('down'):
        newOri -= 1

thisOri and newOri are both defined in the “Begin Experiment” tab as “0.” Again, it works beautifully offline, but doesn’t work online. I’ve read that the “event.getKeys()” part needs to be replaced by “psychoJS.eventManager.getKeys()” when converting to javascript, but when I do this my stimulus does not respond to any key inputs at all.

I guess that’s a whole new issue altogether, and requires some more research!

I would use:

keys = event.getKeys()
if 'up' in keys:
     newOri += 1
elif 'down' in keys:
     newOri -= 1

If you follow my tips for code_JS in my crib sheet then you don’t need to worry about manually translating event.

However, you might want the increment to be less that 1 (e.g. .1) unless you want one arrow press to double or stop the rotation.

1 Like

That is perfect! Thank you for all the help, I really appreciate it.