LibPrism-1.0

A library intended to supply color manipulation tools.

 

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

 

 

Kept for backwards compatibility (as in, do not use, scheduled to be removed eventually):

  • Prism:GetAngleGradient(rMin, rMax, gMin, gMax, bMin, bMax, modifier)

Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

  • Project ID
    69005
  • Created
    Nov 13, 2013
  • Last Released File
    Jul 25, 2016
  • Total Downloads
    1,292
  • License

Categories

Members

Recent Files