ElementArrayStim - displaying other objects

Hey everybody!

I’m currently working on a project using different visual stimuli and face some problems trying to implement certain features. In general, I want to present stimuli of different shapes and numbers. Therefore, I am using ElementArrayStim to achieve this.
However, I haven’t quite figured out how to incorporate other elements in ElementArrayStim since currently it just blacks the whole screen instead of presenting a different shape. Apparently one can use any object that has a .draw() and a .setPos([x,y]) method. So I created some different shapes using ShapeStim and am now trying to incorporate them into the presentation of ElementArrayStim (which isn’t working properly).
My guess is, that I need to give ShapeStim additionally to its position argument a .setPos([x,y]) method, but I do not know how. Another idea I had, was to create an object with init_ etc., but since I am a bloody beginner this seemed even more overwhelming to me.

Currently my code (reduced to the important bits) looks like this:

#define global variables
size_obj = None
n_dots = None
ascending = [1,2,3,4,5,6,20]

#function for the star object 
def StarFunction (size_obj): 
    star = visual.ShapeStim(win, units = 'pix', name='star', vertices='star7',size=(size_obj), ori=0, 				        pos=(50,0), lineWidth=1, lineColor=[-1,-1,-1], lineColorSpace='rgb',  fillColor=[-1,-1,-1], 				fillColorSpace='rgb', opacity=1, depth=0.0, interpolate=True)
	star.draw()
	#star.setPos([0,50])

star_obj = StarFunction (10)

#function displaying mulitple objects
def Test (n_dots): 
    VarStim = visual.ElementArrayStim( 
            win, units="pix",
            fieldSize=(1.0, 1.0), fieldPos=(0, 0),  fieldShape="circle", nElements=n_dots,  colors=[-1,-1,-1],  		    elementTex=None,  elementMask=None, element=star_obj,  sizes=10)
    VarStim.draw()
    win.flip()
    core.wait(1)
    Blankscreen(0.45)


#Loop through the number of objects
for i in ascending:
    Test(i)

I would appreciate any help or comment! Also, ideas different than the ones that I had are very much welcome because I’m stuck for a while now.

Thank you so so much in advance!

Best wishes to you all :slight_smile:

Hi There,

For a useful demo of the elementArrayStim this might help https://www.djmannion.net/psych_programming/vision/draw_dots/draw_dots.html

I think this should do what you are trying to achieve :slight_smile:


import random

import psychopy.visual
import psychopy.event
from psychopy.visual import ShapeStim
win = psychopy.visual.Window(
    size=[400, 400],
    units="pix",
    fullscr=False
)

n_dots = 200

dot_xys = []

star7Vert = [(0.0,0.5),(0.09,0.18),(0.39,0.31),(0.19,0.04),(0.49,-0.11),(0.16,-0.12),(0.22,-0.45),(0.0,-0.2),(-0.22,-0.45),(-0.16,-0.12),(-0.49,-0.11),(-0.19,0.04),(-0.39,0.31),(-0.09,0.18)]
star7 = ShapeStim(win, vertices=star7Vert, fillColor='green', lineWidth=2, lineColor='white')


for dot in range(n_dots):

    dot_x = random.uniform(-200, 200)
    dot_y = random.uniform(-200, 200)

    dot_xys.append([dot_x, dot_y])

dot_stim = psychopy.visual.ElementArrayStim(
    win=win,
    units="pix",
    nElements=n_dots,
    elementTex=None,
    fieldShape=star7,
    #elementMask='circle',
    xys=dot_xys,
    sizes=10
)

dot_stim.draw()

win.flip()

psychopy.event.waitKeys()

win.close()

Hopefully this helps :slight_smile:

Becca

PS. The shapestim attributes here are very much stolen from the demo in view>coder>demos>stimuli>shapes

1 Like

Thank you for your sharing. It is very useful. I can’t find the demo on the official website.