Skip to content

Instantly share code, notes, and snippets.

/color.js
Created Feb 15, 2015

Embed
What would you like to do?
Purebasic.2DDrawing to Javascript port (colors only)
/**
* @description Returns the 24-bit color value corresponding to the Red, Green, Blue components.
* @param Red
* @param Green
* @param Blue
* @returns {number}
* @constructor
*/
function RGB(Red, Green, Blue) {
return Blue << 16 | Green << 8 | Red
}
/**
* @description Returns the 32-bit color value corresponding to the Red, Green, Blue and Alpha values.
* @param Red
* @param Green
* @param Blue
* @param Alpha
* @returns {number}
* @constructor
*/
function RGBA(Red, Green, Blue, Alpha) {
return Alpha << 24 | Blue << 16 | Green << 8 | Red
}
/**
* @description Returns the red component of a color value.
* @param Color
* @returns {number}
* @constructor
*/
function Red(Color) {
return Color & 255;
}
/**
* @description Returns the green component of a color value.
* @param Color
* @returns {number}
* @constructor
*/
function Green(Color) {
return Color >> 8 & 255;
}
/**
* @description Returns the blue component of a color value.
* @param Color
* @returns {number}
* @constructor
*/
function Blue(Color) {
return Color >> 16 & 255;
}
/**
* @description Returns the alpha component of a color value.
* @param Color
* @returns {number}
* @constructor
*/
function Alpha(Color) {
return Color >> 24 & 255;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.