I need a way to gradually change the color of a shape, depending on how many time it should be drawn

edited August 2015 in How To...

Hi,

I need to drawn a series of shapes depending on some external data. For how is structured that data, some shapes would be drawn multiple times, but what I actually want is to change their color. So, for example, if a square would be drawn once on the same area, I'd want to fill it with some greenish color, while if it would be drawn 5 times, I'd want to fill it with something yellowish.

I tried to check if blendMode() can accomplish that, but from what I've seen it can only increase\decrease the value of each channel, while I need to switch at some point to a different tonality (like from green to yellow and so on).

I've also check if I could directly manipulate the pixels of the sketch but that doesn't seem very efficient, and moreover I can't understand how work with the values I get: e.g. unless I'm wrong, with get(x,y) or pixels[], I can obtain a single int (with weird values, at lest for me)- not the color array I could work with.

(that's one simple code example I used to try get(x,y) or pixels[] command):

PGraphics pg;
void setup() {

  size(60, 60); 
  background(255);

  pg = createGraphics(40, 40);
  pg.beginDraw();
  noStroke();
  fill(255, 0, 0, 100);
  strokeWeight(1);
  ellipse(40, 40, 20, 20);
  pg.endDraw();

  color c = get(38,40);
   println(c);

}

void draw() {
}

So, could anyone help me, explaining if that's some way to work with blending, or what I'm doing wrong with get\pixels or if there's some other good way around? Obliviously, I'm trying to work with a solution like that because I would avoid to manipulate the data after reading it - in other words, avoiding to manually check what shapes are drawn more than once, and manually setting their colors to what I want.

Answers

Sign In or Register to comment.