p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

"default" fill color used to be white, is now black (0.5.14)

Open aparrish opened this issue 9 years ago • 3 comments

The following code produces two solid rgb(0, 0, 0) shapes (note that I have not called fill() before drawing the shape):

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(100, 149, 237);
  ellipse(50, 50, 60, 60);
  rect(40, 40, 35, 45);
}

Previously I believe that identical code would have produced rgb(255, 255, 255) shapes (with a rgb(0, 0, 0) stroke), and checking with an older version of the library loaded confirms this. You can see the difference in behavior between the current tutorial page and the same tutorial page from earlier this year.

Interestingly, the same code called without createCanvas() produces the rgb(255, 255, 255) fill:

function setup() {

}

function draw() {
  background(100, 149, 237);
  ellipse(50, 50, 60, 60);
  rect(40, 40, 35, 45);
}

Ultimately the difference isn't that important, and I'm willing to live with a "just call fill() first if you don't want undefined behavior" answer. (I originally came across this when revising tutorial materials for ICM this year, in which I introduce createCanvas() before introducing fill().) But if it's not already defined somewhere easily accessible, it might be nice to know what behavior should be expected in this circumstance? Thanks!

aparrish avatar Sep 05 '17 19:09 aparrish

good catch. this had to do with new fill and stroke caching we had implemented. because createCanvas is called once by default, then again if you manually call it, it was registering the fill and stroke as already set when it actually wasn't set on the recently created canvas. that's why you were seeing different behavior depending on whether you call createCanvas() or not. it should be fixed now and will be in the next release.. though it may be a week or two before that happens, so best to be explicit in the code for now.

lmccart avatar Sep 06 '17 03:09 lmccart

great, thank you for the update and the fix. <3

aparrish avatar Sep 07 '17 18:09 aparrish

Please be aware that this issue reported affects the examples in the P5js reference. Most figures and shapes in the examples are all filled up with black, you can't distinguish the example. If you edit the example and add fill(255); at the top, it fixes it.

qrencha avatar Sep 21 '17 22:09 qrencha