"Paint on the right spot" task

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2.6
Standard Standalone? (y/n) If not then what?: Y
**What are you trying to achieve?:
Hi guys! I’m trying to build a task that requires the participant to use the brush tool to paint the “right spot” on an image. I know the brush tool does not automatically saves it’s data on the .csv file that’s created after a trial, but it shows up on the .log file, like this:

92.1524 	DATA 	Mouse: Left button down, pos=(810,647)
92.1524 	EXP 	Resetting brush parameter: brushPos.
92.1525 	EXP 	Creating ShapeStim for brush
94.1191 	DATA 	Mouse:  Left button up, pos=(876,650)

So at first i figured i could try to make the program save data for all positions from the brush component, but it would generate A LOT of data.

So i thought about it and now my idea is to make the program understand where the “right spot” is, so when the participant’s painting starts and ends at the “right spot”, a “correctAnswer” variable changes value (eg. from 0 to 1).

I don’t know if this is the best approach to this issue, but i need your help with a couple things:
1- How do i teach the program to save the brush position data on a .csv file in addition to the .log one?
2- Is there a way to make the program show me my mouse coords is in real time as i’m testing it? Something like this:
show-mouse-coordinates-on-desktop-screen
3- How do i code so that the program knows the full “right spot”? eg.:
This is one of the images:
imagem bvacm (1)
The marks here are where i want the “right spot” to be, AKA if the participant starts and ends the brush tool inside this area, it will be considered a correct answer:
imagem bvacm marcada

4- Is there a function to make this work? Something that tells the program something like this?

if brushTool starts inside this whole area, CorrectBrushStart = 1
else CorrectBrushStart = 0

if brushTools ends inside this whole area, CorrectBrushEnd = 1
else CorrectBrushEnd = 0

if CorrectBrushStart = 1
 and CorrectBrushEnd = 1
CorrectAnswer = 1

If so, what is it?

5- Is there a way to make a “reset button”, like a button where if the participant clicks on it, brush position and variables are reset? I know there is a way to reset the brush, since the .log show this line:
22.8348 EXP Resetting brush
But i don’t know the function to code it.

As always, thank you in advance!

Hi There,

Cool idea! A few functions that might help you get going.

After adding a mouse and code component. you want to add the following to your code component.

Begin Routine tab:

coordList =[] # an empty list to add coordinates to only if in the 'right spot'

Every frame tab (track if the mouse is currently pressed in the ‘right spot’ and if so add those coords to a list:

if nameOfMouse.IsPressedIn(rightSpotPolygon):
    coordList.append(mouse.getPos())

End Routine tab - save data to file:

nameOfLoop.addData('right_spot_coords', coordList)

The hardest bit will be alligning your polygon which defines the ‘right spot’ to a particular location! it is easy to see if something is pressed in a whole object but less so an edge of an object Had you planned to overlay your images with ‘invisible’ polygons or provide an array of correct coordinates?

Hope this helps,
Becca

Thank you so much Becca, this helps a whole lot!

Had you planned to overlay your images with ‘invisible’ polygons or provide an array of correct coordinates?

To be honest, both were considered and right now i’m thinking about an array of coordinates, but the polygons MIGHT be easier, i don’t know.

My plan was to figure out a way to see the coords in real time to have an idea of where the images are positioned and therefore where the polygons should be placed. Is it possible to do that on PsychoPy? Something like this:
java-mouse-cursor-xy-coordinates-label
Or am i overthinking it and there’s an easier way to figure this out?

Yes sure! Try this showCoords.psyexp (8.6 KB)

Thank you!

Hi there!

i’m having some trouble with the code and i don’t know why!

Here is my build:

My code is written as follows:

Begin Routine:
coordList =[] # an empty list to add coordinates to only if in the 'right spot'

Each Frame:

if mouseCoord.IsPressedIn(polygonCoord):
    coordList.append(mouseCoord.getPos())

End Routine:

Coordloop.addData('right_spot_coords', coordList)

The program works fine without the code, but when i try to run with it, the program tries to open, then closes itself and there is no error message. I cheked every variable name, checked to see if i somehow the fact that the polygon has no color was causing a conflict, checked my mouse component to see if there’s anything missing…

Here’s the mouse component:

Then, i tried adding the polygon component to Clickable stimuli, but it still doesn’t work

Is there anything i’m missing that’s causing it to not work?

Here is the program running without the code:

I left the polygon colored to make it easier to see here, but changing the opacity to 0 works just fine.

I really don’t know what i’m doing wrong with the code, it seems fine to me.

Hi There,

for if mouseCoord.IsPressedIn(polygonCoord):

you need a lower case “i”

if mouse.isPressedIn(x)

if you have no error message can I check you are runnning a recent version of psychopy ? there was an annoying bug in a previous release that stopped error messages showing - it is now resolved.

Thank you, it finally worked!

I added two new variables and a new polygon to make things easier for me. Now the code looks like this:

Begin Routine:

coordList =[] # an empty list to add coordinates to only if in the 'right spot'
resp1 = 0 #variable to verify if the participant painted on polygon 1
resp2 = 0 #variable to verify if the participant painted on polygon 2

Each Frame:

if mouseCoord.isPressedIn(polygonCoord1):
    coordList.append(mouseCoord.getPos())
    resp1 = 1

if mouseCoord.isPressedIn(polygonCoord2):
    coordList.append(mouseCoord.getPos())
    resp2 = 1

End Routine:

Coordloop.addData('right_spot_coords', coordList)
Coordloop.addData('resp1', resp1)
Coordloop.addData('resp2', resp2)

So now, i can easily find out if the participant clicked on the right spot or not when i’m analyzing the data.

BUT, i still need to know one more thing:
Is it possible to make sure the variables resp1 and resp2 will only be equal to 1 if the participant starts AND ENDS the brush component on the right spot? Right now, they just need to START on the right spot, but they don’t have to END the painting there, like this:

Here, i started the brush inside the polygon and finished outside, but the resp1 variable is still = 1.

Again, thank you so much! You guys here are life savers!

Hi There,

It looks like you are making some great progress here!

I think you just want an else statement on your code.

i.e.

if mouseCoord.isPressedIn(polygonCoord1):
    coordList.append(mouseCoord.getPos())
    resp1 = 1
else:
    resp1 = 0

This way your resp1 variable is reset if the mouse is being pressed elsewhere!

Do you think that might provide a solution?

Becca

Thank you again, Becca!