Fill() does not accept hexidecimal?

function setup() {
  createCanvas(500,700);
  background(0);
}

function draw() {
  //fill(0xffff0000);  // no hexidecimal ?
  fill(255,255,0);
  ellipse(200,200,250);
  }

I’ve changed the title to something more descriptive in case someone has this same question in the future.

While Processing-Java can take hexidecimal via the color object, P5.Color does not support hexidecimal (as far as I know).

However, you can pass a string with hexcode, like this:

fill("#ffff00ff"); 

Does this answer your question?

4 Likes

Yes, thanks Tony. Maybe they will implement it in the future. Kinda disappointing though.

1 Like

Just trying to understand – what is an example of something that you cannot accomplish with

fill("#ffff00ff");

but would need

fill(0xffff0000);

?

Edit

I should mention that, if you have installed code with collections of numbers (any integer numbers, you could code them in hex or whatever, it is all binary underneath) then you can pass those numeric values into fill as strings with prefix 0x and .toString(16):

var num = 0x797e61;
var hexstr = "0x"+ num.toString(16);
fill(hexstr);

I’m not well-practiced in JavaScript, but I believe that you could just wrap that in a convenience function like this:

function hexfill (num) {
  fill("0x"+ num.toString(16));
}
var num = 0x797e61;
hexfill(num);
2 Likes