123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|519|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> RGB to Web Hex?

Wed, 21 Oct 2009, 02:26
LostUser
How do you convert RGB to Hex as seen in web CSS colors in Blitz?

ie: 255, 255, 255 = FFFFFF

I tried using the Hex() function but it doesn't return the correct values.

Are you meant to add the R,G and B together, or something?


Wed, 21 Oct 2009, 03:22
JL235
I agree with Agent Smith. Your not shifting the values. But I'd say you should also hide the shifting away, so as an alternative you can use some functions I had built for this gradients code snippet.

Here are two functions I've pulled from it:
  • newRGB(red, green, blue)
  • newARGB(alpha, red, green, blue)


So your code can just be:

Wed, 21 Oct 2009, 04:50
Jayenkai
Bloody 'ell, talk about making things complex!

bitshifting!?!

It's a string!!!


-=-=-
''Load, Next List!''
Wed, 21 Oct 2009, 05:30
LostUser
Thanks for your help.
Wed, 21 Oct 2009, 05:32
JL235
Yours presumes that he only wants to convert the currently set colour to hex. It's better to move the conversion code out, so it can be used separately.


Wed, 21 Oct 2009, 06:42
Jayenkai
Assuming you're running it in DebugMode your point is valid, but even my celeron could happily run that all day!

(and by "all day" I actually mean "for about 20 mins before it overheats due to having to cope with DirectX doing it's thing.. poor celeron)

-=-=-
''Load, Next List!''
Wed, 21 Oct 2009, 07:22
Evil Roy Ferguso
Since the Blitz angle is already taken care of, I'd like to note that you do not actually have to convert colors to Hex for CSS, because the following is possible:



It's part of the CSS standard, and even IE6 supports it.
Wed, 21 Oct 2009, 08:26
Jayenkai
Indeed, and RGBA(r,g,b,a) lets you add alpha, too, which is nice.

-=-=-
''Load, Next List!''
Wed, 21 Oct 2009, 12:12
LostUser
I require the hex because I do this to style things, and I just wanted a way of grabbing the hex of colors that were either set elsewhere, or randomly generated.



Thanks for all your help.