Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Improper color values(?)

Status
Not open for further replies.

mpalmer12345

Programmer
Feb 16, 2004
59
US
What happens when you feed numbers higher than 255 into the three hex slots of a font color (strColor)? I am getting some pretty, but unpredictable, effects I would like to reproduce, if possible, but within a setting where the values are within the proper range and won't produce error messages.
strColor = "#" + RedHex + GreenHex + BlueHex

So if color1 = 255 it keeps being incremented, which makes it rise above 255!

function fnNextColor(color1, color2) {
if (color1 < color2)
{
NextColor = color1 - 1;

} else
{
NextColor = color1 + 1;
}
return NextColor;
}

Then turn NextColor into hex color value, RedHex etc.
 

As far as I know, the values simply wrap around after hitting 255... So effectively, 256 becomes 1, 257 becomes 2, 258 = 3... and so on.

I haven't tested this theory, but it's the kind of behaviour I would expect, anyway ;o)

Hope this helps!

Dan
 
Yeah, my guess would be that it just truncates the end.

So FFFFFF0 would truncate to
FFFFFF

and 0FFFFFF to
0FFFFF

But I really don't know for sure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top