| Reference | Downloads | Github

Online RGBA support

Hi all!
I was wondering if the colour of polygon components can be specified in RGBA for Pavlovia experiments?

I keep getting this error:
“The argument should be an array of numbers of length 3”.
This error disappears when I delete the alpha channel.

I am trying to hold the colour of two circle polygon components constant at black, and vary their luminance by varying the alpha value:

ContinuousCirc.setFillColor([-1, -1, -1, alpha])
ContinuousCirc.setLineColor([-1, -1, -1, alpha])

Is there any other way I can manipulate the luminance of a polygon component?

Hi There,

Because polygons are rendered online using pixi you could use

polygon._pixi.alpha = 0.5

in a code component - but it might be easier to manipulate the opacity parameter?


We’re working on bringing PsychoJS more in line with PsychoPy in general, and colours are an area we’re particularly focused on. RGBA works in python so hopefully soon we’ll be able to match that in JS :slight_smile:

Until then, the solution Becca proposes should work just the same.

Thank you both for the really quick replies, I really appreciate it!

Unfortunately, it’s not working on my end. I am getting this error:

TypeError: Cannot set property ‘alpha’ of undefined.

The console identifies this code as the issue:

 flash._pixi.alpha = FlashLum;

Without any changes in outcome, I have tried this line of code in the begin routine and each frame sections of a code component. I have also tried running it as: flash.pixi.alpha = FlashLum

I am a bit confused about why it thinks the polygon component is undefined when Becca’s line of code is inserted, as that code belongs to this block of code, which executes successfully in its absence:

    flash.setLineColor([0, 0, 0]);
    flash.setFillColor([0, 0, 0]);
    flash._pixi.alpha = FlashLum;
    thisExp.addData("FlashLuminance", FlashLum);

Where are you adding the code to at the moment? (e.g. which tab?)

At the moment I am storing it in Begin Routine. Here’s a screenshot:

if you comment out line 15 and use window.flash = flash then open the console whilst running your task in browser can you inspect if flash has the attribute ._pixi?

alternatively is the code component rendered before or after your polygon in the routine?


When I type in flash into the console, ._pixi becomes a suggested fill-in option.
However, when I enter flash._pixi into the console, it comes up undefined. I have attached a screenshot below.

I believe the code component is rendered before the polygon, as I am trying to change/set the alpha before the first frame is drawn. However, in the screenshot above, the error caused by flash._pixi.alpha is in the each flash tab, and should only be altering the alpha of an already rendered flash.

That’s weird! can you use the opacity field of the polygon instead? that should achieve the same thing?


Thank you so much for your help Becca! Turns out opacity will do exactly what I need!

fabulous! that should be much easier too!

Good luck with your study!