Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Usefull snippet - hsv - or hsb - to dword

Author
Message
Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 23rd Dec 2006 17:56 Edited at: 23rd Dec 2006 18:02
I personally prefer working in HSV - I find it easier to visualise than RGB. It also has other advantages... For example... I want to create 100 random colours of the same brightness and saturation but only varying the colour. In this case I want to vary only the hue and not the saturation or brightness. This is either impossible or damn difficult using RGB.

I searched the code snippets database and the forum and found nothing so here is a function to convert HSV into a colour DWORD (as produced by the RGB function).



EDIT: Here is the Codebase Entry.
http://www.thegamecreators.com/?m=codebase_view&i=f376aeef790b43846bccc9e70be8a45e

[center]
RiiDii
21
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 23rd Dec 2006 18:20
Very nice and very, very useful Nic. Something I can definately see using.


Open MMORPG: It's your game!
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Dec 2006 18:24
Very nice. I think it would be kind of odd trying to work with hue, I guess because you have to remember all the colors. Maybe a "RGBSB2DWORD" function would be good

Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 23rd Dec 2006 18:32
Quote: "Maybe a "RGBSB2DWORD" function would be good"

Heh... Interesting!

One thing that COULD be possible is a function where you pass it an RGB colour, saturation and value and it would convert the RGB to HSV, take the Hue from that and the Saturation and Value you WANT and return THAT colour (if that makes sense)

If you need to know more about HSV...
http://en.wikipedia.org/wiki/HSV_color_space

[center]
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Dec 2006 18:45
I have to say, this is a very interesting image.


I never knew the Hue would be represented as an angle

Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 23rd Dec 2006 18:51
Yup - hence it being 360 degree's (usually).

Thats also a rather large (in dimensions) image

[center]
Scraggle
Moderator
22
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 23rd Dec 2006 19:04 Edited at: 23rd Dec 2006 19:07
Very handy snippet nic - thanks

I have changed the code slightly to better demonstrate it, although the function remains intact.
Press H,S or V and move the mouse up or down to change the value.


Nicholas Thompson
21
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 23rd Dec 2006 19:10
ahhhhhh good idea!!!

[center]

Login to post a reply

Server time is: 2026-07-01 10:44:40
Your offset time is: 2026-07-01 10:44:40