View unanswered posts | View active topics
It is currently Sat May 17, 2025 1:49 am
|
Page 1 of 1
|
[ 4 posts ] |
|
More programming stuff...
Author |
Message |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Hi Guys,
I'm trying to do some work with colours (RGB values, etc...).
The control that I have returns an integer and I have found a function that converts the integer into separate red, green and blue values.
But it isn't working.
The function I found is...
input colourvalue.
redvalue = colourvalue MOD 256. greenvalue = (colourvalue / 256) MOD 256. bluevalue = (colourvalue / 256 / 256) MOD 256.
This seems to almost work but not quite.
I have put the same formulae into Excel to check it is working correctly and it does.
For instance, when I click a cyan like colour RGB(0,255,255). The int returned is 16776960. Excel turns this into 0,255,255 but my program thyinks it is 0,255,0.
Simililarly when I select white, Excel says it is 255,255,255 but my program thinks it is 255,0,0.
Not sure what could be going on here.
Any ideas?!
|
Fri Dec 11, 2009 9:31 am |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Woohoo!
Truncate is your freind!
Stupid thing
|
Fri Dec 11, 2009 9:34 am |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
I'd check the double-division for the blue one and add some extra brackets to be safe/clear.
|
Fri Dec 11, 2009 9:35 am |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
That's what I thought is might be but it's down to rounding. The program was being too clever and turning 255.56738239... into 256. I needed to truncate instead.
|
Fri Dec 11, 2009 9:42 am |
|
|
|
Page 1 of 1
|
[ 4 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 4 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum
|
|