How to make polygons change color when pressed

Hi There,

You want to use a code component. In the begin routine tab list your polygons:

polygons = [polygon, polygon_1]

then on every frame check if the mouse is pressed in the polygon:


for thisPolygon in polygons:
    if mouse.isPressedIn(thisPolygon):
        thisPolygon.color = 'red'

Here is a demo file. polyChangeCol.psyexp (10.9 KB)

Hope this helps,
Becca

PS. I don’t know if you want to take that online, but just incase, it will need a slight edit in the code component (change code type to ‘both’, on the right hand side change color to fillColor, since ‘color’ is ‘fillColor’ in psychoJS JSDoc: Class: Polygon)