Raised This Month: $ Target: $400
 0% 

RGB, RGBA, Hex


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-17-2012 , 10:47   RGB, RGBA, Hex
Reply With Quote #1

Some shitty tutorial. (Copy most text from wiki)

There have been this new chat color feature in few source games for a while,
let's look how we could "make" these color values.

Custom chat color use a hex triplet (three-byte hexadecimal number), where bytes represent the red, green and blue components of the color (RGB).
In hexadecimal FFFFFF.
Where one color channel range is in hex 00 - FF, in decimal 0 - 255

"Note that if any one of the three color values is less than 16 (decimal) or 10 (hex), it must be represented with a leading zero so that the triplet always has exactly six digits."
For example, wrong way (%X)
PHP Code:
PrintToChatAll("%X%X%X"4816); // Show RGB decimal-triplet in hex, would be 4810 
Same example but with advanced formatting (%02X)
  • %: always required
  • flag 0: Pads with 0s instead of spaces when needed
  • width 2: Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
  • precision : skipped
  • specifier X: Hexadecimal representation of the binary value
PHP Code:
PrintToChatAll("%02X%02X%02X"4816); // Show RGB decimal-triplet in hex, would be 040810 
Ok, we have get hex-triplet output with three separate decimal places.
But this can be more easier. (Found from google, but seems bl4nk have also posted before)
This how combine all three color channels to one. (RGB to Hex)
PHP Code:
    new my_color;
    
my_color |=    ( (5   0xFF) << 16);        // Red    05----
    
my_color |=    ( (200 0xFF) << );        // Green  --C8--
    
my_color |=    ( (255 0xFF) << );        // Blue   ----FF

    
PrintToChatAll("%06X"my_color); // Output will be 05C8FF 
Explain to me


These above (RGB) now works with chat color character "\x07"
PHP Code:
PrintToChatAll("\x07%06XMy color"my_color); 
-------------


Another chat color character "\x08", require four color channel (RGBA) where last channel is Alpha, modify text opacity/transparency.
Almost same way as above but we add one more hex byte = two hex digits.
And now remember also that formating, 8 hex digit (%08X)
PHP Code:
    new my_color;
    
my_color |=    ( (5   255) << 24);        // Red    05------
    
my_color |=    ( (200 255) << 16);        // Green  --C8----
    
my_color |=    ( (255 255) << );        // Blue   ----FF--
    
my_color |=    ( (50  255) << );        // Alpha  ------32

    
PrintToChatAll("%08X"my_color);    // 05C8FF32 
Example with RGBA
PHP Code:
PrintToChatAll("\x08%08XMy color"my_color); 
------


Yes, can do even more simple than those before. Just add straight Hex color value in output text, or use text.

PHP Code:
PrintToChatAll("\07%sRed \x0800FF00A0Green \x07%06XBlue",        "FF0000"0x0000FF); 
---

We can do also this in translation files, not need edit plugin
I attached test translation phrase, hope those characters not get erased after uploading here.


More here #22


Sry for bad english and lot of text with misspellings, typos, wrong info.
*edit
Use NotePad++
Attached Thumbnails
Click image for larger version

Name:	testphrase.png
Views:	942
Size:	26.4 KB
ID:	173137  
Attached Files
File Type: txt test.phrases.txt (648 Bytes, 319 views)

Last edited by Bacardi; 01-05-2019 at 18:17. Reason: clarify =|
Bacardi is offline
 


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 23:25.


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