We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am looking to convert a value that is in rgba to its respective hexadecimal value. With the code written I get - 15538: Uncaught TypeError: Cannot read property 'toString' of undefined.
Can someone tell me what I may be doing wrong?
Here is the code:
var hexcol = hex(hc,mc,sc); // variables in hex() are set up earlier in code text(hexcol, 6,130);
Answers
1st of all, do not post code as a picture. They can't be copied & pasted! [-(
2nd, how would be possible to determine what's wrong at
var hexcol = hex(hc, mc, sc);
if we got no idea where hc, mc and sc were declared or assigned some value? :-<https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
@tomstuder : the problem seems to be that color isn't working as documented:
Yet your c variable is an object:
You're getting an error because hex accepts a number or array; but you're unwittingly passing an Object :(|)
Looks to me like a bug - or some update that hasn't been documented :/
Here is an update in a gist:
https://gist.github.com/tomstuder/45fc62023a660a2a2b1dede2c8727977
Function color() acts as a custom constructor for class p5.Color in the same vein as createVector() is for class p5.Vector and many other cases.
BtW, we can access the RGBa values via its levels array property:
Thank You @GoToLoop for the info and clarity on this! With a bit of tweaking below, it works as I was looking for!
Glad it's solved! :D Just 1 lil' performance detail: Do not unnecessarily invoke color(): L-)
Above you're creating 2 p5.Color instance objects. Why not just 1?: *-:)
Hi, posted a tweaked version online at the link below: :ar!
http://p5ide.HerokuApp.com/editor#?sketch=57527089ac4cb30300d64828