I am trying to have a gradient RGB rectangle to reflect each color on a bigger rectangle depending on the mouse’s position. I was able to come up with this:
void draw() {
noStroke();
for (i = 0;i < width; i++)
{
fill(i, 100, 100);
rect(i+x, 0, width, 50);
color mouseColor = get(mouseX, mouseY);
fill(mouseColor);
//noStroke();
rect(0,i+50,width,height-50);
}
}
The problem is, all colors on the RGB gradient get displayed one by one on top of one another as the cursor moves past them. What I want is for the colors to be separately reflected. Any help would be appreciated. I’m very much a newbie in Processing. Thanks!
hmmm in fact I think the problem is that the rectangle overlay is overwriting the texture (I assume that the op somehow made gradient texture similar to this example). Perhaps the op needs to separate the background into a PGraphics so it won’t be affected by overlay
thank you for the suggestion! I did try PGraphics and was successful. My remaining problem is how to display the colors in a “gradient” HSB like the one in the image below. Right now I’m only able to display solid colors.
The colors are all the same in my example but you can extract hue(), saturation() and brightness() and color and fill() each corner achieve this effect:
You can tweak this to your liking.
There are other ways to do this with pixels[] and and get() and set() that may be better to show the hue, saturation and brightness in the rectangle.
This was just a quick exploration of this.
I have done this before and do something different each time.