starling-framework
Version:
A fast, productive library for 2D cross-platform development.
135 lines (118 loc) • 4.5 kB
JavaScript
// Class: starling.utils.Color
var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this
$global.Object.defineProperty(exports, "__esModule", {value: true});
var __map_reserved = {};
// Imports
var $hxClasses = require("./../../hxClasses_stub").default;
var $import = require("./../../import_stub").default;
function openfl__$Vector_Vector_$Impl_$() {return require("./../../openfl/_Vector/Vector_Impl_");}
function _$UInt_UInt_$Impl_$() {return require("./../../_UInt/UInt_Impl_");}
function Std() {return require("./../../Std");}
// Constructor
var Color = function(){}
// Meta
Color.__name__ = ["starling","utils","Color"];
Color.prototype = {
};
Color.prototype.__class__ = Color.prototype.constructor = $hxClasses["starling.utils.Color"] = Color;
// Init
// Statics
Color.getAlpha = function(color) {
return color >>> 24 & 255;
}
Color.getRed = function(color) {
return color >>> 16 & 255;
}
Color.getGreen = function(color) {
return color >>> 8 & 255;
}
Color.getBlue = function(color) {
return color & 255;
}
Color.setAlpha = function(color,alpha) {
return color & 16777215 | (alpha & 255) << 24;
}
Color.setRed = function(color,red) {
return color & -16711681 | (red & 255) << 16;
}
Color.setGreen = function(color,green) {
return color & -65281 | (green & 255) << 8;
}
Color.setBlue = function(color,blue) {
return color & -256 | blue & 255;
}
Color.rgb = function(red,green,blue) {
return red << 16 | green << 8 | blue;
}
Color.argb = function(alpha,red,green,blue) {
return alpha << 24 | red << 16 | green << 8 | blue;
}
Color.toVector = function(color,out) {
if(out == null) {
out = (openfl__$Vector_Vector_$Impl_$().default)._new(4,true);
}
(openfl__$Vector_Vector_$Impl_$().default).set(out,0,(_$UInt_UInt_$Impl_$().default).toFloat(color >>> 16 & 255) / 255.0);
(openfl__$Vector_Vector_$Impl_$().default).set(out,1,(_$UInt_UInt_$Impl_$().default).toFloat(color >>> 8 & 255) / 255.0);
(openfl__$Vector_Vector_$Impl_$().default).set(out,2,(_$UInt_UInt_$Impl_$().default).toFloat(color & 255) / 255.0);
(openfl__$Vector_Vector_$Impl_$().default).set(out,3,(_$UInt_UInt_$Impl_$().default).toFloat(color >>> 24 & 255) / 255.0);
return out;
}
Color.multiply = function(color,factor) {
if(factor == 0.0) {
return 0;
}
var alpha = (Std().default)["int"]((_$UInt_UInt_$Impl_$().default).toFloat(color >>> 24 & 255) * factor);
var red = (Std().default)["int"]((_$UInt_UInt_$Impl_$().default).toFloat(color >>> 16 & 255) * factor);
var green = (Std().default)["int"]((_$UInt_UInt_$Impl_$().default).toFloat(color >>> 8 & 255) * factor);
var blue = (Std().default)["int"]((_$UInt_UInt_$Impl_$().default).toFloat(color & 255) * factor);
if((_$UInt_UInt_$Impl_$().default).gt(alpha,255)) {
alpha = 255;
}
if((_$UInt_UInt_$Impl_$().default).gt(red,255)) {
red = 255;
}
if((_$UInt_UInt_$Impl_$().default).gt(green,255)) {
green = 255;
}
if((_$UInt_UInt_$Impl_$().default).gt(blue,255)) {
blue = 255;
}
return Color.argb(alpha,red,green,blue);
}
Color.interpolate = function(startColor,endColor,ratio) {
var startA = startColor >>> 24 & 255;
var startR = startColor >>> 16 & 255;
var startG = startColor >>> 8 & 255;
var startB = startColor & 255;
var endA = endColor >>> 24 & 255;
var endR = endColor >>> 16 & 255;
var endG = endColor >>> 8 & 255;
var endB = endColor & 255;
var b = (_$UInt_UInt_$Impl_$().default).toFloat(endA - startA) * ratio;
var newA = (Std().default)["int"]((_$UInt_UInt_$Impl_$().default).toFloat(startA) + b);
var b1 = (_$UInt_UInt_$Impl_$().default).toFloat(endR - startR) * ratio;
var newR = (Std().default)["int"]((_$UInt_UInt_$Impl_$().default).toFloat(startR) + b1);
var b2 = (_$UInt_UInt_$Impl_$().default).toFloat(endG - startG) * ratio;
var newG = (Std().default)["int"]((_$UInt_UInt_$Impl_$().default).toFloat(startG) + b2);
var b3 = (_$UInt_UInt_$Impl_$().default).toFloat(endB - startB) * ratio;
var newB = (Std().default)["int"]((_$UInt_UInt_$Impl_$().default).toFloat(startB) + b3);
return newA << 24 | newR << 16 | newG << 8 | newB;
}
Color.WHITE = 16777215
Color.SILVER = 12632256
Color.GRAY = 8421504
Color.BLACK = 0
Color.RED = 16711680
Color.MAROON = 8388608
Color.YELLOW = 16776960
Color.OLIVE = 8421376
Color.LIME = 65280
Color.GREEN = 32768
Color.AQUA = 65535
Color.TEAL = 32896
Color.BLUE = 255
Color.NAVY = 128
Color.FUCHSIA = 16711935
Color.PURPLE = 8388736
// Export
exports.default = Color;