Different Colors when using PGraphics

Hey all!
could you tell my why I get different colors when drawing to a PGraphic?

PGraphics canvas;
void setup(){
   size(1060,200); 
   colorMode(HSB,360,100,100,100);
   background(0,0,100);
   canvas = createGraphics(width,height);
   canvas.colorMode(HSB, 360, 100, 100, 100);
   for(int i = 0; i < 100; i++){
   noStroke();
   fill(62, 100, 83, i);
   rect(i*10+30 ,30 , 10, 10);
   noFill();
   stroke(0);
   strokeWeight(1);
   rect(30,30,1000,10);
  }
  canvas.beginDraw();
  for(int i = 0; i < 100; i++){
    canvas.noStroke();
    canvas.fill(62, 100, 83, i);
    canvas.rect(i*10+30 ,90 , 10, 10);
    canvas.noFill();
    canvas.stroke(0);
    canvas.strokeWeight(1);
    canvas.rect(30,90,1000,10);
  }
  canvas.endDraw();
   image(canvas, 0, 0);
}

Thank you very much!
kws

Hello, you need the colorMode to be after the beginDraw:

  canvas.beginDraw();
  canvas.colorMode(HSB, 360, 100, 100, 100);

I don’t know why that is though… Can’t think of any reason why it would need to be set after beginDraw :thinking:

1 Like