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

Support hex color strings in color functions

Open kadamwhite opened this issue 12 years ago • 11 comments

Given the primacy of hex color values on the web, I'd like to propose enhancing fill, background and the other color-related methods to be able to take a hex value string in addition to the RGB color values or color array. This will make it easier to integrate other JS color libs into p5, because almost all of them are able to spit out hex values one way or another.

Example:

// same:
fill( '#45ab31' );
fill( 69, 171, 49 );

kadamwhite avatar Jun 10 '14 16:06 kadamwhite

Ah yes! This was on my radar! I think it makes total sense. Some people in the workshop even expected to be able to type CSS strings like 'red' into the functions. I really liked that idea.

evhan55 avatar Jun 10 '14 18:06 evhan55

yes!

lmccart avatar Jun 10 '14 22:06 lmccart

Yes this would be great! And bring it more inline with processing.

brysonian avatar Jun 11 '14 00:06 brysonian

@evhan55 points out that we're setting the returned value from getNormalizedColor and getCSSRGBAColor directly onto the canvas context, and the canvas context speaks CSS color strings. Passing strings like 'red' or '#45ab12' directly through should work. I am updating the patch.

kadamwhite avatar Jun 11 '14 20:06 kadamwhite

But what if I do:

var c = color("pink");
...
int red_value = red(c);

brysonian avatar Jun 11 '14 20:06 brysonian

Hi, I am Hrishit. New to this project and I was looking at the issues to find out where I can start. I would like to work on this one. Does it make sense as a beginner?

hrishit avatar Aug 12 '14 11:08 hrishit

I know @kadamwhite started on this, not sure where it's at right now, but he could probably say better whether it's at a point someone could jump in.

@hrishit if you are looking for a self-contained issue to start with, maybe this one? https://github.com/lmccart/p5.js/issues/226

lmccart avatar Aug 12 '14 13:08 lmccart

@hrishit Lauren's correct, I worked on this a bit in #223 and some of the work from that branch is salvageable; I've just not had the time to finish it up since then :) I've been working to update my patch for all the changes that have happened since June, and will hopefully have more to show for it soon; if you have a solution, though, don't let me hold you up!

kadamwhite avatar Aug 13 '14 12:08 kadamwhite

@kadamwhite just wanted to confirm before starting on this one. Knowing that you are working on it I've already started on #226. Nevertheless please let me know if you need any helping hand.

hrishit avatar Aug 13 '14 14:08 hrishit

yeah, sorry @kadamwhite, had to rework things a bit when I started hitting some real performance issues. let me know if you have any questions about how things are laid out now, happy to walk you through it.

lmccart avatar Aug 13 '14 17:08 lmccart

:))

lmccart avatar Apr 13 '15 01:04 lmccart