psychopy.org | Reference | Downloads | Github

Generating stimuli in response to subject actions

Hi all,

This is my first post about my first project using PsychoPy. I’m as newbie as they come and I look forward to getting to know PsychoPy and the community better :slight_smile:

I want to put together an experiment with the following procedure:

  1. Present subject with an image and instruct them to click on points (no restrictions on the number of points) of the image using a mouse for a set time, say 90 seconds.
  2. Each time the subject clicks a point:
    i. The position is registered in the experiment data
    ii. All subsequent presentations of the image will include a cross marking the point that the participant clicked.
  3. For a “cooldown period” of 0.5 seconds, participant clicks will not be registered.
  4. Until the 90s have passed, this loop of registering clicks, generating crosses on the image and “cooling down” continues.

There will be a limited number of areas which indicate “correct” responses, but the participant will not be given feedback on whether or not their response was correct or not. The only feedback will be the crosses demarcating the points that the subject has clicked, as a kind of memory aid. Just as there is no limit to the number of responses the subject can give during the 90s, there is no limit for the number of crosses that are generated/displayed.

I’m in the very early stages of even trying to figure out PsychoPy so there are obviously many things I need to do, but mostly I have a rough idea of how they might be solved. When it comes to the part about generating the crosses based on subject actions however, I don’t really know where to even begin.

I haven’t found anything in the documentation for mouse events( http://www.psychopy.org/builder/components/mouse.html and https://www.psychopy.org/api/event.html ).

I searched the forums but the things that turned up weren’t quite the same, e. g.:



The main difference is that the threads I saw talked about modifying stimuli in response to subject actions, but not generating novel (or at least, new copies of) stimuli in response to actions.

Does anyone have tips for me on this? If I need to jump into Python coding to achieve the intended effect then that’s fine since I know Python from before, I just need some pointers on how to start working on this kind of reactivity in PsychoPy.

(I tried creating a very, very basic illustration of what I’m getting at and uploaded it on gitlab. I haven’t used gitlab before either, but I hope the link works: https://gitlab.pavlovia.org/Arboc/responsive-clickable-images-project )

Hi @Arboc, this will get you started with creating crosses on clicks. In this example, using Builder I create a polygon, a mouse and a code component. When the polygon is clicked, the makeCross function is called, which creates a small cross at the location of the mouse click, draws it, and returns the cross object. The returned cross object is stored in a list for later use. You will need the cross objects stored so that you can get the positions of the crosses, and so you can stop drawing them at the end of the trial (if that is what you want to do).

# Begin Experiment
def makeCross(pos):
    cross = visual.ShapeStim(win, pos=pos, depth=-2, vertices='cross', size=(.01,.01), fillColor="black")
    cross.setAutoDraw(True)
    return cross

# Begin Routine
crosses = []  # list container for storing cross objects

# Each Frame
if mouse.isPressedIn(polygon):
    crosses.append(makeCross(mouse.getPos()))
1 Like

Great, that helps a lot! I’ll try to implement it right away, if I find anything interesting I’ll be sure to post it here :slight_smile:

Due to copyright issues I can’t share the finished program with the intended images. But when I’m done I’ll try to make a “dummy version” where all the code is intact and only the images have been swapped, in case it’s of any help to someone who stumbles upon this thread and wants to try something similar.

Edit1: Re: “… so you can stop drawing them at the end of the trial” - I added this to the code snippet to make sure that the crosses aren’t drawn afterwards, I’m guessing you meant something like it.

# End Routine
for across in crosses:
        across.setAutoDraw(False)

Maybe there’s a more elegant way to do it, I basically just copied the method used by PsychoPy itself for stopping objects from drawing themselves.

Edit2: While looking at the documentation for ShapeStim (https://www.psychopy.org/api/visual/shapestim.html#psychopy.visual.ShapeStim) I noticed that it says the “depth” parameter is deprecated, because “Depth is now controlled simply by drawing order.”… But when using code snippets in the Builder, just reordering the stimuli doesn’t seem to work (since the code snippet isn’t arranged in the actual code like other stimuli as far as I understand), and the crosses end up being “underneath” the other stimuli if the depth parameter isn’t used. I wonder what the best-practice method for solving this would be?

1 Like

Perhaps don’t use autoDraw but instead explicitly draw the stimuli yourself on every frame, e.g.:

# this first step may or may not be necessary, but if it is, you'll probably need to set 
# the corresponding Builder component to not have a time of onset:
background_image.draw()

for cross in crosses:
    cross.draw()