Get an Epic Experience with Premium

LibPrism-1.0

Libraries Login to Add Favorites
  • 0 Likes
  • Project Manager: Aiue
  • World of Warcraft
  • 46 Monthly Downloads
  • Supports: 5.4.1
  • 230 Total Downloads
  • Updated 12/05/2013
  • Created 11/13/2013
  • 0 Favorites
  • Project Site
  • Release Type: Release
  • License: CC BY-NC-SA 3.0
  • Newest File: v1.0.2
or

About LibPrism-1.0

A library intended to supply color manipulation tools.

Until I get the documenter working, I suppose I'll just type it in here manually. Also, for the purposes of this documentation, ℝ is to be considered redefined as "computer-real", which is actually closer to ℚ, but.. myeah.


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 ∈ ℝ: 0 ≤ rMin ≤ 1}
rMax
The red color value at your ending point, {rMax ∈ ℝ: 0 ≤ rMax ≤ 1}
gMin
The green color value at your starting point, {gMin ∈ ℝ: 0 ≤ gMin ≤ 1}
gMax
The green color value at your ending point, {gMax ∈ ℝ: 0 ≤ gMax ≤ 1}
bMin
The blue color value at your starting point, {bMin ∈ ℝ: 0 ≤ bMin ≤ 1}
bMax
The blue color value at your ending point, {bMax ∈ ℝ: 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 ∈ ℝ: 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 ∈ ℝ: 0 ≤ r ≤ 1}
[3]
The g value, where {g ∈ ℝ: 0 ≤ g ≤ 1}
[4]
The b value, where {b ∈ ℝ: 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 ∈ ℝ: 0 ≤ r ≤ 1}
g
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
b
The blue color value, {b ∈ ℝ: 0 ≤ b ≤ 1}

Return values

[1]
The hue value, where {h ∈ ℝ: 0 ≤ h ≤ 360}
[2]
The saturation value, where {s ∈ ℝ: 0 ≤ s ≤ 1}
[3]
The brightness value, where {v ∈ ℝ: 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 ∈ ℝ: 0 ≤ h ≤ 360}
s
The saturation value, where {s ∈ ℝ: 0 ≤ s ≤ 1}
v
The brightness value, where {v ∈ ℝ: 0 ≤ v ≤ 1}

Return values

[1]
The red color value, {r ∈ ℝ: 0 ≤ r ≤ 1}
[2]
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
[3]
The blue color value, {b ∈ ℝ: 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 ∈ ℝ: 0 ≤ r ≤ 1}
g
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
b
The blue color value, {b ∈ ℝ: 0 ≤ b ≤ 1}
m
By how much the saturation should be increased, {m ∈ ℝ: -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 ∈ ℝ: 0 ≤ r ≤ 1}
[2]
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
[3]
The blue color value, {b ∈ ℝ: 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 ∈ ℝ: 0 ≤ r ≤ 1}
g
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
b
The blue color value, {b ∈ ℝ: 0 ≤ b ≤ 1}
m
By how much the saturation should be decreased, {m ∈ ℝ: -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 ∈ ℝ: 0 ≤ r ≤ 1}
[2]
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
[3]
The blue color value, {b ∈ ℝ: 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 ∈ ℝ: 0 ≤ r ≤ 1}
g
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
b
The blue color value, {b ∈ ℝ: 0 ≤ b ≤ 1}
m
By how much the brightness should be increased, {m ∈ ℝ: -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 ∈ ℝ: 0 ≤ r ≤ 1}
[2]
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
[3]
The blue color value, {b ∈ ℝ: 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 ∈ ℝ: 0 ≤ r ≤ 1}
g
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
b
The blue color value, {b ∈ ℝ: 0 ≤ b ≤ 1}
m
By how much the brightness should be decreased, {m ∈ ℝ: -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 ∈ ℝ: 0 ≤ r ≤ 1}
[2]
The green color value, {g ∈ ℝ: 0 ≤ g ≤ 1}
[3]
The blue color value, {b ∈ ℝ: 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)

tag v1.0.2
cb7604d25d8cf01b653a390fac672937e29c43fb
Aiue <aiue@aiue.se>
2013-12-05 14:54:32 +0100

Tagging as v1.0.2

--------------------

Aiue:
    - Attempt at giving things more appropriate names. Also added support for RGB gradients, silly as they may be.
    - Added function Prism:Gradient(), rewrote :GetAngleGradient() to call this for backwards compatibility.
    - Removed unnecessarily silly conditionals from multiplicative saturate/brightness value functions.
    - Allow for multiplicative operations in the saturation/brightness manipulation functions.
    - Fix for :RGBtoHSV()
    - Fix for :RGBtoHSV() with all three color values being identical to one another.
    - Added functions :Saturate(), :Desaturate(), :Lighten() and :Darken()
    - Made the previous fix actually work rather than breaking the function completely. (0/0 = -1.#IND = ALL the numbers\!)
    - A factor of 0/0 will now be defined as 0 within GetAngleGradient() rather than being neither validated nor redefined.
    - #@debug@ in .toc does more than advertised and also adds a space, apparently. Fix due to this.
    - Less zealous validation provides behaviour more closely matching definitions.
    - Minor versioning pokage.
    - Fixed a few errors that should've been caught by testing before even making it to alpha.
    - \'@project-timestamp@\' makes for a bad minor version.
    - Added validation to the conversion functions.
    - :GetAngleGradient() rewritten to only accept raw numbers rather than tables or strings. (Thanx Phanx)
    - Rewrote documentation a bit.
    - Fixed undefined division error.
    - Another attempt at getting documentation parsed.
    - Documentation poke due to me being silly a moment ago.
Jens Nilsson Sahlin:
    - Documentation poke due to me being silly a moment ago.
    - Initial commit.

Login to Curse

Don't have an account? Create One.

Get an epic experience with Curse Premium
  • Faster addon downloads
  • Premium-Only Beta Giveaways
  • Ad-Free Curse experience
  • Premium Curse Client
  • and many More Features
  • Learn More »

Landmark Beta Key Giveaway!

Get My Code!