psychojs icon indicating copy to clipboard operation
psychojs copied to clipboard

When called for an image component, setColor does not update image color.

Open dvbridges opened this issue 5 years ago • 5 comments

In PsychoPy, you can change the color of your image component on every repeat or every frame using the Color parameter in the Builder image component. However, the code that is used for the JavaScript is not working - where "image" is the name of the image component:

image.setColor(new util.Color('red'))

Example of current PsychoJS behaviour https://pavlovia.org/run/dvbridges/imagefade/html/

dvbridges avatar Feb 09 '19 13:02 dvbridges

The implementation in psychopy is essentially to multiply the image pixel color by the RGB of the designated color. We now do this with a shader but it used to be using textures combined with glColor

peircej avatar Feb 11 '19 11:02 peircej

Have you checked that this isn't related to writing 'red' instead of new util.Color([1, -1, -1]); ?

wakecarter avatar Jun 02 '20 15:06 wakecarter

Yes it fails both ways. For named colors, you can use any of those listed as a named color in PsychoJS

https://github.com/psychopy/psychojs/blob/8276bd790a682ab276052946f66cb4d591ad0eb6/js/util/Color.js#L493

dvbridges avatar Jun 02 '20 19:06 dvbridges

Hello, I am wondering whether this has been resolved. I'm having the same issue but for a text component. I built my experiment in Builder, and it works fine in psychopy but does not work when I run it on Pavlovia in psychojs. The behavior I am aiming to achieve is that on each trial when a participant presses the 'f' key, a text component on the screen will turn blue, indicating that it was the selected option, and then green if it is the correct answer or red if incorrect. And the same if the 'j' key is pressed for a different text component.

I know my logic that I added through a code component is correct because it works when I run it in builder. When I run it on Pavlovia though, it changes the colors correctly for the first trial only, and then after it is stuck on the behavior from the first trial. I know my logic in js is working too because the behavior of the "correct"/"incorrect" text feedback is correct, and it uses the same logic. Plus, I printed the color and where I was in the if/else conditionals to the consol and could see that the logic was properly handling the key input and changing the colors accordingly.

It seems that the call to text.setColor(new util.Color(color)) is not updating the color of the text, given that text is the text component and color is the color I want to change it to.

I am using Psychopy 2020.2.2 on Windows 10.

e-leib avatar Aug 17 '20 20:08 e-leib

Hi, I'm wondering if this has been resolved or anyone found a way around it. I'm trying to recolour an empty white image by setting a new colour. Works brilliantly locally, fails online. Unfortunately using a Polygon is not an option as I need a mask on the image.

laszlotalas avatar Aug 10 '21 09:08 laszlotalas