# Using elementstimarray with dots

**URL:** <https://discourse.psychopy.org/t/using-elementstimarray-with-dots/16276>\
**Category:** Builder\
**Created:** [September 6, 2020, 1:19am UTC](https://discourse.psychopy.org/t/using-elementstimarray-with-dots/16276 "2020-09-06T01:19:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Becks](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@Becks](https://discourse.psychopy.org/u/Becks)\
**Post date:** [September 6, 2020, 1:19am UTC](https://discourse.psychopy.org/t/using-elementstimarray-with-dots/16276/1 "2020-09-06T01:19:44Z")

</div>

If this template helps then use it. If not then just delete and start from scratch.

**OS** (e.g. Win10): Win10  
**PsychoPy version** (e.g. 1.84.x): 3.2.4  
**What are you trying to achieve?:**  
I’m trying to generate array of dots (up to 150)

**What did you try to make it work?:**  
I generate the trial parameters in the beginning of experiment code component and initialize black and white dots.

```auto
totdots = [50, 100, 150]
dot1_stim = []

for tt in totdots:
        #loop creating stimuli, number of black and white dots
        dot1_stim.append([nb_dots1,nb_dots2,ratio])

random.shuffle(dot1_stim)

white_dot_stim = psychopy.visual.ElementArrayStim(
    win=win, units="pix",
    elementTex=None,
    elementMask="circle",
    sizes=5,
    colorSpace='rgb',
    colors='white'
)

black_dot_stim = psychopy.visual.ElementArrayStim(
    win=win, units="pix",
    elementTex=None,
    elementMask="circle",
    sizes=5,
    colorSpace='rgb',
    colors='black'
)

```

And then I would generate the array in the beginning routine using:

```auto
n_white_dots = dot1_stim[trialcounter][1] 
n_black_dots = dot1_stim[trialcounter][0] 

white_dot_xys = []
black_dot_xys = []

for dot in range(n_black_dots):
    dot_x = random.uniform(-70, 70)
    dot_y = random.uniform(5, 145)
    black_dot_xys.append([dot_x, dot_y])

for dot in range(n_white_dots):
    dot_x = random.uniform(-70, 70)
    dot_y = random.uniform(-145, -5)
    white_dot_xys.append([dot_x, dot_y])

white_dot_stim.xys = white_dot_xys
white_dot_stim.nElements = n_white_dots

black_dot_stim.xys = black_dot_xys
black_dot_stim.nElements = n_black_dots

white_dot_stim.setAutoDraw(True)
black_dot_stim.setAutoDraw(True)

```

I also have two rectangles components in this routine. This is the intended final product:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/0/20ac4207cfbc6a6a736691481cc3e0478363a626.png)

I looked at the crib sheet and this method was proposed for other types of stimuli, but I’m having trouble implementing it with static dots. This is the error I’m getting:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/4/74684d803873888c355ac778d79b94e5f579d893.png)

Any ideas on how to make this work?
