Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-16-2010, 08:19 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
HSLtoRGB

Converts colors from the HSL color space to the RGB color space. I copied and converted this from a toolkit for C#. Judging from my tests, it works well.

PHP Code:
function HSLtoRGB(HSL) {
  
temp.0;
  
temp.0;
  
temp.0;
  
  
: (H);
  
: (S);
  
: (L);
  
  if (
== 0) {
    
0;
  } else {
    if (
== 0) {
      
L;
    } else {
      
temp.v1 <= 0.5 * (S) : - (S);
      
temp.v2 temp.v1;
      
      
temp.t3  = { 3H};
      
temp.clr = new[3];
      
      for (
temp.03i++) {
        if (
temp.t3[i] < 0)
          
temp.t3[i]++;
        if (
temp.t3[i] > 1)
          
temp.t3[i]--;
        
        if (
temp.t3[i] * 1)
          
temp.clr[i] = temp.v2 + (temp.v1 temp.v2)
                        * 
temp.t3[i] * 6;
        else if (
temp.t3[i] * 1)
          
temp.clr[i] = temp.v1;
        else if (
temp.t3[i] * 2)
          
temp.clr[i] = temp.v2 + (temp.v1 temp.v2)
                        * (
temp.t3[i]) * 6;
        else
          
temp.clr[i] = temp.v2;
      }
    }
  }
  
  
temp.clr[0];
  
temp.clr[1];
  
temp.clr[2];
  return { 
RG};


Example usage:
PHP Code:
temp.rgb HSLtoRGB(0.010.70.5); // slightly desaturated medium red
echo(temp.rgb); // echoes "0.85,0.192,0.15" 

H, S and L have to be values between 0 and 1. The returned RGB values are also between 0 and 1.

Enjoy!
Reply With Quote
  #2  
Old 02-17-2010, 02:09 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Very nice
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #3  
Old 03-15-2010, 06:40 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Props for the function AND that avatar! Best platformer ever.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
Reply


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 +2. The time now is 02:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.