Module GradientMaker
Module which provides for creating color gradients for your text.
Original functions found on the Lusternia Forums
I added functions to work with hecho.
I also made performance enhancements by storing already calculated gradients after first use for the session and only including the colorcode in the returned string if the color changed.
Info:
- Copyright: 2018 Sylphas,2020 Damian Monogue
- Author: Sylphas on the Lusternia forums,Damian Monogue
Functions
color_name(r, g, b) | Returns the closest color name to a given r,g,b color |
dgradient(text, first_color, second_color, next_color) | Returns the text, with the defined color gradients applied and formatted for us with decho. |
cgradient(text, first_color, second_color, next_color) | Returns the text, with the defined color gradients applied and formatted for us with cecho. |
hgradient(text, first_color, second_color, next_color) | Returns the text, with the defined color gradients applied and formatted for us with hecho. |
cgradient_table(text, first_color, second_color, next_color) | Returns a table, each element of which is a table, the first element of which is the color name to use and the character which should be that color |
dgradient_table(text, first_color, second_color, next_color) | Returns a table, each element of which is a table, the first element of which is the color({r,g,b} format) to use and the character which should be that color |
hgradient_table(text, first_color, second_color, next_color) | Returns a table, each element of which is a table, the first element of which is the color(in hex) to use and the second element of which is the character which should be that color |
install_global() | Creates global copies of the c/d/hgradient(_table) functions and color_name for use without accessing the module table |
Functions
- color_name(r, g, b) line 228
-
Returns the closest color name to a given r,g,b color
Parameters:
- r The red component. Can also pass the full color as a table, IE { 255, 0, 0 }
- g The green component. If you pass the color as a table as noted above, this param should be empty
- b the blue components. If you pass the color as a table as noted above, this param should be empty
Usage:
closest_color = GradientMaker.color_name(128,200,30) -- returns "ansi_149" closest_color = GradientMaker.color_name({128, 200, 30}) -- this is functionally equivalent to the first one
- dgradient(text, first_color, second_color, next_color) line 244
-
Returns the text, with the defined color gradients applied and formatted for us with decho. Usage example below produces the following text
Parameters:
- text string The text you want to apply the color gradients to
- first_color The color you want it to start at. Table of colors in { r, g, b } format
- second_color The color you want the gradient to transition to first. Table of colors in { r, g, b } format
- next_color Keep repeating if you want it to transition from the second color to a third, then a third to a fourth, etc
See also:
Usage:
decho(GradientMaker.dgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {255,0,0}, {255,128,0}, {255,255,0}, {0,255,0}, {0,255,255}, {0,128,255}, {128,0,255})) decho(GradientMaker.dgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {255,0,0}, {0,0,255})) decho(GradientMaker.dgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {50,50,50}, {0,255,0}, {50,50,50}))
- cgradient(text, first_color, second_color, next_color) line 260
-
Returns the text, with the defined color gradients applied and formatted for us with cecho. Usage example below produces the following text
Parameters:
- text string The text you want to apply the color gradients to
- first_color The color you want it to start at. Table of colors in { r, g, b } format
- second_color The color you want the gradient to transition to first. Table of colors in { r, g, b } format
- next_color Keep repeating if you want it to transition from the second color to a third, then a third to a fourth, etc
See also:
Usage:
cecho(GradientMaker.cgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {255,0,0}, {255,128,0}, {255,255,0}, {0,255,0}, {0,255,255}, {0,128,255}, {128,0,255})) cecho(GradientMaker.cgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {255,0,0}, {0,0,255})) cecho(GradientMaker.cgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {50,50,50}, {0,255,0}, {50,50,50}))
- hgradient(text, first_color, second_color, next_color) line 276
-
Returns the text, with the defined color gradients applied and formatted for us with hecho. Usage example below produces the following text
Parameters:
- text string The text you want to apply the color gradients to
- first_color The color you want it to start at. Table of colors in { r, g, b } format
- second_color The color you want the gradient to transition to first. Table of colors in { r, g, b } format
- next_color Keep repeating if you want it to transition from the second color to a third, then a third to a fourth, etc
See also:
Usage:
hecho(GradientMaker.hgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {255,0,0}, {255,128,0}, {255,255,0}, {0,255,0}, {0,255,255}, {0,128,255}, {128,0,255})) hecho(GradientMaker.hgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {255,0,0}, {0,0,255})) hecho(GradientMaker.hgradient("a luminescent butterly floats about lazily on brillant blue and lilac wings\n", {50,50,50}, {0,255,0}, {50,50,50}))
- cgradient_table(text, first_color, second_color, next_color) line 286
-
Returns a table, each element of which is a table, the first element of which is the color name to use and the character which should be that color
Parameters:
- text string The text you want to apply the color gradients to
- first_color The color you want it to start at. Table of colors in { r, g, b } format
- second_color The color you want the gradient to transition to first. Table of colors in { r, g, b } format
- next_color Keep repeating if you want it to transition from the second color to a third, then a third to a fourth, etc
See also:
- dgradient_table(text, first_color, second_color, next_color) line 296
-
Returns a table, each element of which is a table, the first element of which is the color({r,g,b} format) to use and the character which should be that color
Parameters:
- text string The text you want to apply the color gradients to
- first_color The color you want it to start at. Table of colors in { r, g, b } format
- second_color The color you want the gradient to transition to first. Table of colors in { r, g, b } format
- next_color Keep repeating if you want it to transition from the second color to a third, then a third to a fourth, etc
See also:
- hgradient_table(text, first_color, second_color, next_color) line 306
-
Returns a table, each element of which is a table, the first element of which is the color(in hex) to use and the second element of which is the character which should be that color
Parameters:
- text string The text you want to apply the color gradients to
- first_color The color you want it to start at. Table of colors in { r, g, b } format
- second_color The color you want the gradient to transition to first. Table of colors in { r, g, b } format
- next_color Keep repeating if you want it to transition from the second color to a third, then a third to a fourth, etc
See also:
- install_global() line 314
-
Creates global copies of the c/d/hgradient(_table) functions and color_name for use without accessing the module table
Usage:
GradientMaker.install_global() cecho(cgradient(...)) -- use cgradient directly now