Dot Matrix. How to build a random dot pattern

Hello!

I am trying to buil a memory test. It is a 4x4 Grid (16 positions) and show between 3 and 8 squares randomly on the screen at random positions. The number of stimuli should change randomly on each trial. Right now i can only produce a Grid with all the possitions filled or blank (opacity 1/0). I want the stimulus to be shown in a random sequence. I saw other posts about this topic but i still could not achieve the desired results.
In my builder, i have a image of a grid, and 16 polygons.

This is my conditions file.

this is how my first polygon is setted. the others have small changes regarding the position, to match the grid.

I am new with psychopy. I was able to do a digit and word recall before, but that is my whole knowledge so far.
Thank you in advance for your help

Pedro Ferreira

You either need to have all the possible rows of 3-8 squares in your Excel file (which will be a lot of rows) or use a code component.

Your opacity should be set every repeat not every frame.

You could have

Begin Experiment

dots=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
dotOpacity=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

Begin Routine

nDots=randint(3,9)
shuffle(dots)
for Idx in range(nDots):
     dotOpacity[dots[Idx]]=1
for Idx in range(nDots,16):
     dotOpacity[dots[Idx]]=0

and then use dotOpacity[0] through dotOpacity[15] for your opacities.

hello!
Thank you for your reply!
I added a code component to the routine and pasted the code you sent me (thank you).
then i changed the opacity to every repeat.
I dont understant what you mean by “and then use dotOpacity[0] through dotOpacity[15] for your opacities”.
Could you explain?

Thank you very much!!

Pedro Ferreira

Set the opacity for dot1 to dotOpacity[0]
Set the opacity for dot2 to dotOpacity[1]
Set the opacity for dot3 to dotOpacity[2]
and so on

My code should have assigned some of the opacity values as 1 and the others as 0

Hi again!
It´s not working. every place in the grid its blank.

Hi

Please could you show a screenshot of the code component and an example dot?

Of course!
Thank you for your help.

That looks correct. Maybe try print(‘nDots’,nDots,‘Opacity’,dotOpacity) after the Begin Routine code. If you can’t get that to give you any output please send me your psyexp file and I’ll take a quick look.

I tried to do what you asked but it gave me some type of error.
dotmatrix.psyexp (37.3 KB) excelldot.xlsx (8.7 KB) .
I attached the psyexp file and the Excell file as well.

Thank you so much for your quick replies and help

It works for me if I move your code component to the top of the routine (so it executes before the dots are drawn). You don’t need the Excel file.

hey!
It is almost perfect. thank you.
But i need the dots to appear as a sequence. they are appearing all at the same time. Is there something that i could change in the code?
thank you.

How were you previously planning to create the sequence?

Personally I’d probably move the opacity code into Each Frame but I’d need to set up a flag to know which stage I was on.

For example:

Begin Routine

nDots=randint(3,9)
shuffle(dots)
dotNum=0
dotGap=.2
for Idx in range(16):
     dotOpacity[Idx]=0

Each Frame

if t > dotGap*dotNum and dotNum < nDots:
     dotOpacity[dots[dotNum]] =1
     dotNum +=1

Opacity would now need to be set to each frame