-
Notifications
You must be signed in to change notification settings - Fork 3
API Reference
This constructor returns a new instance of the OKColor struct to hold a color data.
Check out How to use section for basics.
With this method, you can set a color for OKColor struct in GameMaker format.
Parameters:
Name | Type | Description |
---|---|---|
color | Constant.Color |
The color definition in GameMaker supported format, can be c_color constant, #rrggbb, $bbggrr or a decimal number. |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color for OKColor struct in a string format.
Parameters:
Name | Type | Description |
---|---|---|
hex | String |
The color definition in hex format as a string "#rrggbb". |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in sRGB format. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[red] | Real |
The red component definition of RGB color (in 0-255 range). |
[green] | Real |
The green component definition of RGB color (in 0-255 range). |
[blue] | Real |
The blue component definition of RGB color (in 0-255 range). |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in non-gamma corrected Linear RGB format. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[red] | Real |
The red component definition of Linear RGB color (in 0-1 range). |
[green] | Real |
The green component definition of Linear RGB color (in 0-1 range). |
[blue] | Real |
The blue component definition of Linear RGB color (in 0-1 range). |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in HSV format. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[hue] | Real |
The hue component definition of HSV color (in 0-360 range). |
[saturation] | Real |
The saturation component definition of HSV color (in 0-1 range). |
[value] | Real |
The value component definition of HSV color (in 0-1 range). |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in HSL format. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[hue] | Real |
The hue component definition of HSL color (in 0-360 range). |
[saturation] | Real |
The saturation component definition of HSL color (in 0-1 range). |
[lightness] | Real |
The lightness component definition of HSL color (in 0-1 range). |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in CIELab format. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[lightness] | Real |
The lightness component definition of CIELab color (in 0-100 range). |
[a] | Real |
The a component definition of CIELab color (in -125 to 125 range). |
[b] | Real |
The b component definition of CIELab color (in -125 to 125 range). |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in CIELCH format. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[lightness] | Real |
The lightness component definition of CIELCH color (in 0-100 range). |
[chroma] | Real |
The chroma component definition of CIELCH color (in 0-150 range). |
[hue] | Real |
The hue component definition of CIELCH color (in 0-360 range). |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in OKLab format. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[lightness] | Real |
The lightness component definition of OKLab color (in 0-1 range). |
[a] | Real |
The a component definition of OKLab color (in -0.4 to 0.4 range). |
[b] | Real |
The b component definition of OKLab color (in -0.4 to 0.4 range). |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in OKLCH format. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[lightness] | Real |
The lightness component definition of OKLCH color (in 0-1 range). |
[chroma] | Real |
The chroma component definition of OKLCH color (in 0 to 0.4 range). |
[hue] | Real |
The hue component definition of OKLCH color (in 0-360 range). |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in LMS format that is mostly used for technical needs. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[long] | Real |
The long wavelength definition of LMS color. |
[medium] | Real |
The medium wavelength definition of LMS color. |
[short] | Real |
The short wavelength definition of LMS color. |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method, you can set a color in CIE XYZ format that is mostly used for technical needs. Arguments are optional so you can set components separately.
Parameters:
Name | Type | Description |
---|---|---|
[x] | Real |
The X component definition of CIE XYZ color. |
[y] | Real |
The Y component definition of CIE XYZ color. |
[z] | Real |
The Z component definition of CIE XYZ color. |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
Important
Values generated by these functions will contain the raw components of the chosen color model and can lay outside of sRGB gamut! To get color values ready for rendering use Color Getters.
With this method, you can get a color in raw RGB format. Rendering-safe version: colorRGB()
.
Returns: Struct { r : Real, g : Real, b : Real }
With this method, you can get a color in raw non-gamma corrected Linear RGB format.
Returns: Struct { r : Real, g : Real, b : Real }
With this method, you can get a color in raw HSV format. Rendering-safe versions: colorHSV()
and colorGMHSV()
.
Warning
Hue in the resulting struct can be NaN
, if the saturation is 0, for example. NaN
hue can be safely treated as 0 in outside use.
Returns: Struct { h : Real, s : Real, v : Real }
With this method, you can get a color in raw HSL format. Rendering-safe version: colorHSL()
.
Warning
Hue in the resulting struct can be NaN
, if the saturation is 0, for example. NaN
hue can be safely treated as 0 in outside use.
Returns: Struct { h : Real, s : Real, l : Real }
With this method, you can get a color in raw CIELab format.
Returns: Struct { l : Real, a : Real, b : Real }
With this method, you can get a color in raw CIELCH format.
Returns: Struct { l : Real, c : Real, h : Real }
With this method, you can get a color in raw OKLab format.
Returns: Struct { l : Real, a : Real, b : Real }
With this method, you can get a color in raw OKLCH format.
Returns: Struct { l : Real, c : Real, h : Real }
With this method, you can get a color in raw LMS format that is mostly used for technical needs.
Returns: Struct { l : Real, m : Real, s : Real }
With this method, you can get a color in raw CIE XYZ format that is mostly used for technical needs.
Returns: Struct { x : Real, y : Real, z : Real }
When dealing with different color models you can retrieve a color that lies outside of the renderable range called "gamut". Gamut mapping is the process of taking a color that is out of gamut and adjusting it such that it fits within it. Currently, OKColor only supports 24-bit sRGB color gamut that GameMaker can render on screen.
OKColorMapping
enum sets the type of gamut mapping method in Color Getters, Mixing and other functions.
Won't do any gamut mapping and pass the color values unchanged. It may produce colors outside of gamut that will render incorrectly.
The naive version of gamut mapping clamping RGB values to 0-255 range. The fastest to compute (aside from no mapping at all) but gives mostly poor results.
Here in the example is a number of colors generated outside of gamut, in the form of gradients from lowest to maximum lightness. Clip method doesn't reflect the lightness, distributes colors non-linearly and performs hue shifts so generally it's not recommended to use. Clipping is still very important and can be used to trim minor channel noise after certain color operations.
The method is based on the geometric representation of gamut triangle finding the intersection of the outside color with the gamut and moving it inside. Self-invented by me for this library. Works faster than chroma reduction algorithms shown below and produces results similar to Chroma method but worse than OKChroma.
Here in the example is a number of colors generated outside of gamut, in the form of gradients from lowest to maximum lightness. Geometric method copes better with preserving lightness and color distribution, but with hue shifts to purple on reds and blues and some artefacts on darker colors.
It's a chroma reduction algorithm in CIELCH color space with deltaEOK distance function. Along with the OKChroma method it is the slowest to compute but provides more consistent results.
Here in the example is a number of colors generated outside of gamut, in the form of gradients from lowest to maximum lightness. Chroma handles lighting better with little to no artefacts on the dark but with a hue shift to yellow on reds and less to purple on blues. Worse than OKChroma in terms of lightness linearity but someone may want to use this instead as CIELCH is a more well-understood color space.
It's a chroma reduction algorithm in OKLCH color space with deltaEOK distance function. Along with the Chroma method it is the slowest to compute but provides the most consistent results. Currently the default gamut mapping method.
Here in the example is a number of colors generated outside of gamut, in the form of gradients from lowest to maximum lightness. OKChroma provides the best results on color distributions, no hue shifts and constant linear lightness. OKLCH is a relatively new color model and may have certain quirks, but generally it is a preferable option. Also recommended as a default method in CSS.
With this method you can get a color value valid for rendering in GameMaker format usable for any system function like draw_set_color
.
Parameters:
Name | Type | Description |
---|---|---|
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma. |
Returns: Constant.Color
With this method you can get a color value valid for rendering in hex format as a string "#rrggbb".
Parameters:
Name | Type | Description |
---|---|---|
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma. |
Returns: String
With this method you can get color values valid for rendering in RGB format.
Parameters:
Name | Type | Description |
---|---|---|
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma. |
Returns: Struct { r : Real, g : Real, b : Real }
With this method you can get color values valid for rendering in HSV format.
Parameters:
Name | Type | Description |
---|---|---|
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma. |
Returns: Struct { h : Real, s : Real, v : Real }
With this method you can get color values valid for rendering in GameMaker HSV format with 0-255 range.
Parameters:
Name | Type | Description |
---|---|---|
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma |
Returns: Struct { h : Real, s : Real, v : Real }
With this method you can get color values valid for rendering in HSL format.
Parameters:
Name | Type | Description |
---|---|---|
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma. |
Returns: Struct { h : Real, s : Real, l : Real }
Mixing is a process of merging two colors to produce a new color. OKColor have several mixing algorithms that interpolate colors with different color models. You can learn more about the specifics of different mixing methods here. Here is a quick example:
OKColorMixing
enum sets the mixing colors method.
Performs the mixing in RGB color space. Basically the same as the GameMaker's system merge_color
.
Performs the mixing in Lab color space.
Performs the mixing in OKLab color space. Currently is the default method of color mixing.
With this method you can mix additional color to the current one with a specified amount. Pure version is also available that returns new color instead of mutating current one.
Parameters:
Name | Type | Description |
---|---|---|
mixColor | Struct.OKColor |
Additional color to mix with. |
amount | Real |
How much to mix a color in 0-1 range. |
[colorMixing] | Enum.OKColorMixing |
Color mixing type, default is OKColorMixing.OKLab. |
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma. |
Returns: Struct.OKColor
The same OKColor instance that the method was called on, for method chaining.
With this method you can get a new copy of OKColor struct with the same color.
Returns: Struct.OKColor
New OKColor instance.
With this method you can get a new copy of OKColor struct with the same color mapped for rendering.
Parameters:
Name | Type | Description |
---|---|---|
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma. |
Returns: Struct.OKColor
New OKColor instance.
With this method you can get a new copy of OKColor struct with the additional color mixed.
Parameters:
Name | Type | Description |
---|---|---|
mixColor | Struct.OKColor |
Additional color to mix with. |
amount | Real |
How much to mix a color in 0-1 range. |
[colorMixing] | Enum.OKColorMixing |
Color mixing type, default is OKColorMixing.OKLab. |
[gamutMapping] | Enum.OKColorMapping |
Gamut mapping type, default is OKColorMapping.OKChroma. |
Returns: Struct.OKColor
New OKColor instance.
- Constructor
-
Setters
- setColor(color)
- setHex(hex)
- setRGB([red], [green], [blue])
- setLinearRGB([red], [green], [blue])
- setHSV([hue], [saturation], [value])
- setHSL([hue], [saturation], [lightness])
- setLab([lightness], [a], [b])
- setLCH([lightness], [chroma], [hue])
- setOKLab([lightness], [a], [b])
- setOKLCH([lightness], [chroma], [hue])
- setLMS([long], [medium], [short])
- setXYZ([x], [y], [z])
- Getters
- Gamut Mapping
- Color Getters
- Mixing
- Cloning