We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › convert string to color
Page Index Toggle Pages: 1
convert string to color (Read 519 times)
convert string to color
Jul 21st, 2009, 10:22am
 
Hi, I've got a problem with colors.
The following code draws a red background,
Code:
String hs = "E4010A";
color hi = unhex(hs);
background(hi);


whereas this code won't fill my box with red color.
Code:
String hs = "E4010A";
color hi = unhex(hs);
fill(hi);
stroke(255);
rect(30, 20, 55, 55);


What's wrong? How do I convert a hex color value (without #) saved in a string to a color?
Re: convert string to color
Reply #1 - Jul 21st, 2009, 10:37am
 
Classical issue: the color is an ARGB one, ie. with transparency, set to 00 by unhex, so fully transparent.
background() ignore transparency, so it works.
For fill, you can do:
Code:
String hs = "E4010A";
color hi = unhex("FF" + hs);
fill(hi);
stroke(255);
rect(30, 20, 55, 55);
for example.
Page Index Toggle Pages: 1