Download
(10Kb)
Download
Updated: 10-31-19 09:49 AM
Compatibility:
BfA content patch (8.2.5)
Updated:10-31-19 09:49 AM
Created:10-19-19 06:35 PM
Downloads:332
Favorites:0
MD5:

LibPrism-1.0

Version: v1.0.7
by: Aiue [More]

A library intended to supply color manipulation tools. Only uses native Lua functions, so should be compatible with any WoW version.

Repository can be found on GitHub.

Lazily defining F as the set of all values the 'number' type can have.

Assuming Prism = LibStub("LibPrism-1.0"):

Prism:Gradient(type, rMin, rMax, gMin, gMax, bMin, bMax, x)
Call with 2*rgb values representing the colors at x = 0 and x = 1 respectively, alongside the x coordinate you wish to get the value for and the type of gradient to use.

Parameters
type Which gradient type to use. Currently supports HSV and RGB. More may be added at a later date.
rMin The red color value at your starting point, {rMin ∈ F: 0 ≤ rMin ≤ 1}
rMax The red color value at your ending point, {rMax ∈ F: 0 ≤ rMax ≤ 1}
gMin The green color value at your starting point, {gMin∈ F:*0 ≤ gMin ≤ 1}
gMax The green color value at your ending point, {gMax ∈ F: 0 ≤ gMax ≤ 1}
bMin The blue color value at your starting point, {bMin ∈ F: 0 ≤ bMin ≤ 1}
bMax The blue color value at your ending point, {bMax ∈ F: 0 ≤ bMax ≤ 1}
x The x coordinate, or in other words a percentage describing how far the point the desired color is from the two end points, {x ∈ F: 0 ≤ x ≤ 1} is expected, but if x < 0 it will default to 0, and if x > 1 it will default to 1. For convenience, 0/0 will be defined as 0 for the purposes of this function.

Return values
[1] Hexadecimal string, [00,ff][00,ff][00,ff]
[2] The r value, where {r ∈ F: 0 ≤ r ≤ 1}
[3] The g value, where {g ∈ F: 0 ≤ g ≤ 1}
[4] The b value, where {b ∈ F: 0 ≤ b ≤ 1}

Usage
Prism:Gradient("hsv", 1, 0, 0, 1, 0, 0, .5) -- Would return the values "ffff00", 1, 1, 0
Prism:Gradient("hsv", 0, 1, 1, 1, 1, 0, .25) -- Would return the values "00ff7f", 0, 1, 0.5

Gradient types
HSV The path between two points in a HSV cylinder. Which is to say, a three-dimensional approach to movement will be observed, as the function will move along the hue axis (circumference; periodical, with the period 360, as in not radians), the saturation axis (the radius) and the value (aka brightness) axis (height).
RGB Linear progression along each of the RGB values, which makes for a seemingly less natural progression than the above method.

Prism:RGBtoHSV(r, g, b)
Converts a color from RGB to HSV.

Parameters
r The red color value, {r ∈ F: 0 ≤ r ≤ 1}
g The green color value, {g ∈ F: 0 ≤ g ≤ 1}
b The blue color value, {b ∈ F: 0 ≤ b ≤ 1}

Return values
[1] The hue value, where {h ∈ F: 0 ≤ h ≤ 360}
[2] The saturation value, where {s ∈ F: 0 ≤ s ≤ 1}
[3] The brightness value, where {v ∈ F: 0 ≤ v ≤ 1}

Usage
Prism:RGBtoHSV(0, 1, 0) -- Would return the values 120, 1, 1

Prism:HSVtoRGB(h, s, v)
Converts a color from HSV to RGB.

Parameters
h The hue value, where {h ∈ F: 0 ≤ h ≤ 360}
s The saturation value, where {s ∈ F: 0 ≤ s ≤ 1}
v The brightness value, where {v ∈ F: 0 ≤ v ≤ 1}

Return values
[1] The red color value, {r ∈ F: 0 ≤ r ≤ 1}
[2] The green color value, {g ∈ F: 0 ≤ g ≤ 1}
[3] The blue color value, {b ∈ F: 0 ≤ b ≤ 1}

Usage
Prism:RGBtoHSV(90, 1, 1) -- Would return the values 0.5, 1, 0

Prism:Saturate(r, g, b, m[, operation])
Increases the saturation of a color.

Parameters
r The red color value, {r ∈ F: 0 ≤ r ≤ 1}
g The green color value, {g ∈ F: 0 ≤ g ≤ 1}
b The blue color value, {b ∈ F: 0 ≤ b ≤ 1}
m By how much the saturation should be increased, {m ∈ F: -1 ≤ m ≤ 1} for additive, m ∈ F*for multiplicative.
operation Which type of operation to perform. "add" for additive or "multi" for multiplicative. Defaults to additive.

Return values
[1] The red color value, {r ∈ F: 0 ≤ r ≤ 1}
[2] The green color value, {g ∈ F: 0 ≤ g ≤ 1}
[3] The blue color value, {b ∈ F: 0 ≤ b ≤ 1}

Usage
Prism:Saturate(.1, .2, .3, .4, "add") -- Would return the values 0, 0.15, 0.3
Prism:Saturate(.1, .2, .3, .4, "multi") -- Would return the values 0.02, 0.16, 0.3

Prism:Desaturate(r, g, b, m[, operation])
Decreases the saturation of a color.

Parameters
r The red color value, {r ∈ F: 0 ≤ r ≤ 1}
g The green color value, {g ∈ F: 0 ≤ g ≤ 1}
b The blue color value, {b ∈ F: 0 ≤ b ≤ 1}
m By how much the saturation should be decreased, {m ∈ F: -1 ≤ m ≤ 1} for additive, m ∈ ℝ for multiplicative.
operation Which type of operation to perform. "add" for additive or "multi" for multiplicative. Defaults to additive.

Return values
[1] The red color value, {r ∈ F: 0 ≤ r ≤ 1}
[2] The green color value, {g ∈ F: 0 ≤ g ≤ 1}
[3] The blue color value, {b ∈ F: 0 ≤ b ≤ 1}

Usage
Prism:Desaturate(.1, .2, .3, .4, "add") -- Would return the values 0.22, 0.26, 0.3
Prism:Desaturate(.1, .2, .3, .4, "multi") -- Would return the values 0.18, 0.24, 0.3

Prism:Lighten(r, g, b, m[, operation])
Brightens a color.

Parameters
r The red color value, {r ∈ F: 0 ≤ r ≤ 1}
g The green color value, {g ∈ F: 0 ≤ g ≤ 1}
b The blue color value, {b ∈ F: 0 ≤ b ≤ 1}
m By how much the brightness should be increased, {m ∈ F: -1 ≤ m ≤ 1} for additive, m ∈ ℝ for multiplicative.
operation Which type of operation to perform. "add" for additive or "multi" for multiplicative. Defaults to additive.

Return values
[1] The red color value, {r ∈ F: 0 ≤ r ≤ 1}
[2] The green color value, {g ∈ F: 0 ≤ g ≤ 1}
[3] The blue color value, {b ∈ F: 0 ≤ b ≤ 1}

Usage

Prism:Lighten(.1, .2, .3, .4, "add") -- Would return the values 0.233..., 0.466..., 0.7
Prism:Lighten(.1, .2, .3, .4, "multi") -- Would return the values 0.14, 0.28, 0.42

Prism:Darken(r, g, b, m[, operation])
Darkens a color.

Parameters
r The red color value, {r ∈ F: 0 ≤ r ≤ 1}
g The green color value, {g ∈ F: 0 ≤ g ≤ 1}
b The blue color value, {b ∈ F: 0 ≤ b ≤ 1}
m By how much the brightness should be decreased, {m ∈ F: -1 ≤ m ≤ 1} for additive, m ∈ ℝ for multiplicative.
operation Which type of operation to perform. "add" for additive or "multi" for multiplicative. Defaults to additive.

Return values
[1] The red color value, {r ∈ F: 0 ≤ r ≤ 1}
[2] The green color value, {g ∈ F: 0 ≤ g ≤ 1}
[3] The blue color value, {b ∈ F: 0 ≤ b ≤ 1}

Usage
Prism:Darken(.1, .2, .3, .4, "add") -- Would return the values 0, 0, 0
Prism:Darken(.1, .2, .3, .4, "multi") -- Would return the values 0.06, 0.12, 0.18

Lib: Prism-1.0
v1.0.7 (2019-10-31)
Full Changelog
  • Encode default color properly.
  • Tiny bit more sensible name for the function.
  • Remove unused iterator variables.
  • Add function Prism:AlterStringColors() (closes #1)
  • Lots of call to string.format, despite a local format = string.format.
  • Remove backwards compatibility. It's long since past the point where it's relevant to keep this in the code.
  • Include luarocks package.
  • Run luacheck with --no-self on untagged commits as well.
  • Always run luacheck, run packager on tags.
  • Facepalm yaml fix.
  • Run luacheck.
  • Code cleanup.
  • Run packager for both game versions.
Optional Files (0)


There have been no comments posted to this file.
Be the first to add one.



Category Jump: