# Different Colors when using PGraphics

**URL:** <https://discourse.processing.org/t/different-colors-when-using-pgraphics/29458>\
**Category:** Beginners\
**Created:** [April 17, 2021, 6:49pm UTC](https://discourse.processing.org/t/different-colors-when-using-pgraphics/29458 "2021-04-17T18:49:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kweso](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kweso/32/12864_2.png) [@kweso](https://discourse.processing.org/u/kweso)\
**Post date:** [April 17, 2021, 6:49pm UTC](https://discourse.processing.org/t/different-colors-when-using-pgraphics/29458/1 "2021-04-17T18:49:56Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [April 17, 2021, 6:58pm UTC](https://discourse.processing.org/t/different-colors-when-using-pgraphics/29458/2 "2021-04-17T18:58:25Z")

</div>

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

```auto
  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 🤔
