Raised This Month: $32 Target: $400
 8% 

Rainbow HUD messages using the HSV color model


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
[DeathTV] Sid 6.7
Member
Join Date: Oct 2007
Old 03-02-2008 , 16:43   Rainbow HUD messages using the HSV color model
Reply With Quote #1

This is something I gave up on because I don't have the time but for those wanting to know how it could be done, here it is.

To make a rainbow HUD message (assuming you know how to do HUD syncs and work HUD msg's) you will need to setup a synchronized hud msg and redraw it with a new color each time. For the color, we are going to rotate around this cone to get the rainbow effect



Using the Hue value which is measured in degrees. To travel along the outer edge, set saturation and value to 1.0 (100%). You will have to keep a static Float value for hue and increment it, say by 3.0, each time. To get your r,g,b values, we are going to call on this function

Code:
 
//Used for color cycling the HSV model
//Code adapted from http://www.buena.com/articles.shtml, "Adventures in HSV Space"
//saturation: 0 is dull gray, 1 is full color, value: 0.0 is dark, 1.0 is full luminance
HSVtoRGB(&Float:h, Float:s, Float:v, &Float:r, &Float:g, &Float:b){
 if(h > 360.0) h -= 360.0
 else if(h < 0.0) h += 360.0
 if (s == 0) {
  r = v;  g = v;  b = v;
 } else {
  new Float:fHue, Float:fValue, Float:fSaturation;
  new i;  new Float:f;  new Float:p,Float:q,Float:t;
  if (h == 360.0) h = 0.0;
  fHue = h / 60.0;
  i = floatround(fHue,floatround_floor);
  f = fHue - i;
  fValue = v;
  fSaturation = s;
  p = fValue * (1.0 - fSaturation);
  q = fValue * (1.0 - (fSaturation * f));
  t = fValue * (1.0 - (fSaturation * (1.0 - f)));
  switch (i) {
   case 0: {r = fValue; g = t; b = p;}
   case 1: {r = q; g = fValue; b = p; }
   case 2: {r = p; g = fValue; b = t;}
   case 3: {r = p; g = q; b = fValue;}
   case 4: {r = t; g = p; b = fValue;}
   case 5: {r = fValue; g = p; b = q; }
  }
 }
}
This will also make sure your hue value doesn't get out of range, so don't worry about infinitely incrementing your hue value.
The r,g,b values passed back by this function are in the range of 0.0 to 1.0, so do this to them
floatround(r*255.0)
to get them normalized. Then call this on every clock tick you define

set_hudmessage(floatround(r*255.0),floatround (g*255.0),floatround(b*255.0),xpos,ypos,0)

then show it.
Buena suerte~
__________________
Power Votes Core << Democracy at your fingertips
Get Mortal Kombat Miscstats for CS

Last edited by [DeathTV] Sid 6.7; 03-07-2008 at 22:20. Reason: typo
[DeathTV] Sid 6.7 is offline
Styles
Veteran Member
Join Date: Jul 2004
Location: California
Old 03-07-2008 , 14:00   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #2

wow this looks very cool...
Styles is offline
Send a message via AIM to Styles
JFeldon
Member
Join Date: Feb 2007
Location: United Kingdom
Old 03-07-2008 , 16:50   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #3

Sweet, looks good. Might use it
__________________
+Karma if I helped! ;)
JFeldon is offline
Send a message via MSN to JFeldon
Shaman
Senior Member
Join Date: Dec 2006
Location: Istanbul, Turkey
Old 05-15-2008 , 16:12   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #4

You should use "while" loops so the function can work with hue values greater and lesser than 720:
Code:
HSVtoRGB(Float:hue, Float:saturation, Float:value, &red, &green, &blue)
    {
    //Check input
    while(hue=>360.0)
        h-= 360.0
    while(hue<360.0)
        h+= 360.0
    
    saturation= floatclamp(saturation, 0.0, 1.0)
    
    value= floatclamp(value, 0.0, 1.0)
    
    //Convert
    new i= floatround(hue/60.0, floatround_floor);
    new Float:f= hue/60.0-i;
    new Float:p= value*(1.0-saturation)
    new Float:q= value*(1.0-(saturation*f))
    new Float:t= value*(1.0-(saturation*(1.0-f)))
    
    new Float:fRed
    new Float:fGreen
    new Float:fBlue
    
    switch (i)
        {
        case 0:
            {
            fRed= value
            fGreen= t
            fBlue= p
            }
        case 1:
            {
            fRed= q
            fGreen= value
            fBlue= p
            }
        case 2:
            {
            fRed= p
            fGreen= value
            fBlue= t
            }
        case 3:
            {
            fRed= p
            fGreen= q
            fBlue= value
            }
        case 4:
            {
            fRed= t
            fGreen= p
            fBlue= value
            }
        case 5:
            {
            fRed= value
            fGreen= p
            fBlue= q
            }
        }
    
    red= floatround(fRed)
    green= floatround(fGreen)
    blue= floatround(fBlue)
    }
__________________
Shaman is offline
Send a message via ICQ to Shaman Send a message via AIM to Shaman Send a message via MSN to Shaman Send a message via Yahoo to Shaman
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 06-23-2009 , 17:34   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #5

Quote:
Originally Posted by Shaman View Post
You should use "while" loops so the function can work with hue values greater and lesser than 720:
Code:
    while(hue=>360.0)
        h-= 360.0
    while(hue<360.0)
        h+= 360.0
Do you know how to use this magical operator %?
You simply delete the loops and replace them with

hue = hue % 360;

It also eliminates negative values.
Code:
server_print("360: %d", 360 % 360);  server_print("-360: %d", -360 % 360);  server_print("-90: %d", -90 % 360);  server_print("90: %d", 90 % 360);    /*  * 360: 0  * -360: 0  * -90: 270  * 90: 90  */

Last edited by [ --<-@ ] Black Rose; 06-23-2009 at 17:36.
[ --<-@ ] Black Rose is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-23-2009 , 21:28   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #6

I would REALLY like to use this, but I need to learn how to script..
__________________
+|- KARMA Respectively

HLM is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 06-23-2009 , 22:33   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #7

Quote:
Originally Posted by Superiority View Post
Do you know how to use this magical operator %?
You simply delete the loops and replace them with

hue = hue % 360;

It also eliminates negative values.
Code:
server_print("360: %d", 360 % 360);  server_print("-360: %d", -360 % 360);  server_print("-90: %d", -90 % 360);  server_print("90: %d", 90 % 360);    /*  * 360: 0  * -360: 0  * -90: 270  * 90: 90  */
IIRC the % operator does not work with floats
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-24-2009 , 08:55   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #8

Quote:
Originally Posted by Emp` View Post
IIRC the % operator does not work with floats
I just checked and there's no float modulus function. I might write one up myself.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-24-2009 , 09:17   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #9

Here, try this. It's untested:

PHP Code:
stock Float:floatmodFloat:aFloat:nmode )
{
    new 
Float:result floatround)
    if ( 
mode )
        if ( 
result = -floatabsresult )
        else 
result floatabsresult )
    else
        if ( 
result = -floatabsresult )
        else 
result floatabsresult 

    return 
result

__________________
Hawk552 is offline
Send a message via AIM to Hawk552
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 06-24-2009 , 12:00   Re: Rainbow HUD messages using the HSV color model
Reply With Quote #10

Quote:
Originally Posted by Emp` View Post
IIRC the % operator does not work with floats
Then make it an int.
[ --<-@ ] Black Rose is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode