Loading...
Logo
Processing Forum
Hi, I was just curious about 2 things regarding the following code.

1. Why is there a brief interval of time from when the program starts to when the shape is drawn in which there is just a  white background? In other words, why doesn't the program start with the shape already drawn? I tried moving  shape(tpz, 0, 0); to the setup function but this doesn't work, presumably for very obvious reasons beyond my comprehension.

2. Why is there a momentary flicker of gray in the instant that the shape is drawn?

Here is the code

PShape tpz; // The PShape object

void setup() {
  size(400, 400, P2D);

  // Create custom shape by specifying vertices.

  tpz = createShape();
  tpz.beginShape();
  tpz.fill(255, 0, 0);
  tpz.noStroke();
  tpz.vertex(150,150);
  tpz.vertex(250,150);
  tpz.vertex(300,250);
  tpz.vertex(100,250);
  tpz.endShape(CLOSE);
}

void draw() {
  background(255);
  shape(tpz, 0, 0);
}

Thanks in advance for the help!

Replies(4)

All "drawings" happen in a PGraphics buffer object referenced by variable g.
That buffer isn't rendered to screen until the very end of draw(). So nothing actually "happens" until then.
That quick gray flash is the canvas initial color. It becomes white due to background(255).
For me, it is not a brief time where the window is white, it is a long time, because OpenGL is slow to init on the first run... You use P2D, so you use OpenGL. Perhaps on better graphics cards, the delay is less noticeable.
If he hadn't said anything about some gray flash, I wouldn't have noticed it.
I had to pay close attention to spot it transitioning into white.
An nVidia GeForce 9800GT here. 
Right, I mean it's very subtle. The issue wasn't that it bothered me, I just wanted to know what caused it, since nothing in my code was an apparent indication. Also have a decent but not phenomenal gpu.