draw circles in random positions in sketchpad
Hello! I am trying to draw a random number of circles in a sketchpad. This number should be different in each trial. I tried to do it with inline script. I draw 4 circles in a sketchpad and then i inserted the following code:
from random import shuffle
positions = xy_random(4, 500,300,40)
shuffle(positions)
standard_1 = items['standard_1'].canvas
standard_1['c1'].x,standard_1['c1'].y = positions[0]
standard_1['c2'].x,standard_1['c2'].y = positions[2]
standard_1['c3'].x,standard_1['c3'].y = positions[3]
standard_1['c4'].x,standard_1['c4'].y = positions[1]
Although the experiment runs, circles don't change positions in each trial. Could someone please tell me what i am doing wrong?
Thank you in advance!😊
Comments
Hi @rania_tac,
Can you provide a little more information or upload your task (or a stripped down version of it). Are you running this code within the trial sequence? (if you run it before the loop, the same random arrangement will be used for all trials of the loop). It would help to see the task and how exactly you implement this code and draw the circles to know what the issue may be.
Best,
Fabrice.
Hi @rania_tac ,
In addition to @Fab 's response: Perhaps I'm missing something, but wouldn't it be easier to
inline_scriptitem...sketchpaditem...instead of the reverse order that you are referring to?
Like so:
In the `Run tab` of your
inline_scriptitem, put something like:And then use the `square-bracket notation` to refer to the variables x1, y1, etc. in the
sketchpaditem:See attached a working example.
Cheers,
Lotje
Did you like my answer? Feel free to

Hello again! Thank you so much @Fab and @lvanderlinden !!
I included it as inline script and it work!!!
Again thank you for all the help! ☺️