CLOSED How to get current colorMode

Hi,

I try to get the current colorMode to adapt my code behaviour.
But I didn’t found anyway to get it ?

I try colorMode() without params but nedd at list one.

Any idea ?

Thanks & regards,

Constant

Can’t you set your own variable when you set your colormode?

Then your program can read this

eg boolean modeColor

or int colorModeIs = 3;

Sure it’s a way to do, but first I wanted to make sur that it was not already by the framework.

Meanwhile I look at p5.Color source code and see that each color hold a mode attribute which is set to either constants.HSB/HSL/RGB.

So far, I can use that mode.

Thank’s

1 Like

constants.RGB.HSL/RGB is not available in global scope, so I’ll my own variable :slight_smile:

1 Like

I believe this is true for p5.js because it was true in the original Processing(Java) API.

Currently, Java mode Processing has a generic way of doing style state checking, but it isn’t documented in the reference – the recommended way is to keep track of the settings before you set them. However, there is an alternative. getStyle() may be called on the g object (the canvas PGraphics) – this returns a PStyle object

https://processing.github.io/processing-javadocs/core/processing/core/PStyle.html

which has a colorMode which can be checked (and imageMode, strokeColor, textSize, tint, et cetera)

PStyle ps = g.getStyle();
println(ps);
println(ps.colorMode);
colorMode(HSB);
ps = g.getStyle();
println(ps.colorMode);

I’m not sure if p5.js has a similar system – if it does I’m not aware of it.

2 Likes

Hi,

I don’t find the equivalent in p5js.

Thank’s for the suggestion.

Regards.