Jump to content
GreenSock

GreenSock Docs (HTML5/JS)

PixiPlugin.parseColor()

Added in version: 1.20.0
PixiPlugin.parseColor( color:string | number, format:string ) : array | number

Parameters

color: string | number

The color value the should be parsed which could be a string like #9F0 or rgb(255,102,51) or rgba(255,0,0,0.5) or it could be a number like 0xFF00CC or even a named color like red, blue, purple, etc.

format: string

By default, an rgb-based value will be returned, but if the format parameter is set to "hsl", an hsl() or hsla() value will be returned instead. Or if format is "number", then a numeric value will be returned, like 0xFF0000.

Returns : array | number

By default, an array containing red, green, and blue (and optionally alpha) in that order, or if the format parameter was "hsl", the array will contain hue, saturation and lightness (and optionally alpha) in that order. Or if format is defined as "number", it'll return a number like 0xFF0000.

Details

Parses a color (like #9F0, #FF9900, rgb(255,51,153) or hsl(108, 50%, 10%)) into an array with 3 elements (red, green, and blue, or if format parameter is "hsl", it will populate the array with hue, saturation, and lightness). Or if format parameter is "number", it'll return a numeric value like 0xFF0000 instead of an array. If a relative value is found in an hsl() or hsla() string, it will preserve those relative prefixes and all the values in the array will be strings instead of numbers (in all other cases the array will be populated with numbers). This is a useful method for converting color-related values into data that's more useful. PixiJS, for example, requires numeric values for most of its color-related values so it would be cumbersome to use "purple" or "#F00", for example, without this method. 
Copyright 2017, GreenSock. All rights reserved. This work is subject to theterms of useor for Club GreenSock members, the software agreement that was issued with the membership.
×