Skip to content

GradientMaker: Examples

Damian Monogue edited this page Feb 7, 2021 · 1 revision

Make with the pretty colors coder man

Check out the API docs for more info, but the following picture:

Was created using the following code (sorry about the typo in butterfly):

-- require the module. This will work with the mpackage released with the mdk
local GM = require("MDK.gradientmaker")

-- store the string and gradients I am going to work with
local myString = "  a luminescent butterly floats about lazily on brillant blue and lilac wings\n"
local firstGradient = { {255,0,0}, {255,128,0}, {255,255,0}, {0,255,0}, {0,255,255}, {0,128,255}, {128,0,255} }
local secondGradient = {{255,0,0}, {0,0,255}}
local thirdGradient = {{50,50,50}, {0,255,0}, {50,50,50}}

-- make local copies of the functions with short names for less keystrokes
local cgrad = GM.cgradient
local dgrad = GM.dgradient
local hgrad = GM.hgradient

-- fancy loop to show how you can store the gradients in tables like above and feed them into the function
for _, gradient in ipairs({ firstGradient, secondGradient, thirdGradient }) do
  echo("\n")
  cecho(cgrad(myString, unpack(gradient)))
  decho(dgrad(myString, unpack(gradient)))
  hecho(hgrad(myString, unpack(gradient)))
  echo("\n")
end

-- less fancy method showing how to call the functions directly.
echo("----- cecho -----\n")
cecho(cgrad(myString, {255,0,0}, {255,128,0}, {255,255,0}, {0,255,0}, {0,255,255}, {0,128,255}, {128,0,255}))
cecho(cgrad(myString, {255,0,0}, {0,0,255}))
cecho(cgrad(myString, {50,50,50}, {0,255,0}, {50,50,50}))
echo("\n")

echo("----- decho -----\n")
decho(dgrad(myString, {255,0,0}, {255,128,0}, {255,255,0}, {0,255,0}, {0,255,255}, {0,128,255}, {128,0,255}))
decho(dgrad(myString, {255,0,0}, {0,0,255}))
decho(dgrad(myString, {50,50,50}, {0,255,0}, {50,50,50}))
echo("\n")

echo("----- hecho -----\n")
hecho(hgrad(myString, {255,0,0}, {255,128,0}, {255,255,0}, {0,255,0}, {0,255,255}, {0,128,255}, {128,0,255}))
hecho(hgrad(myString, {255,0,0}, {0,0,255}))
hecho(hgrad(myString, {50,50,50}, {0,255,0}, {50,50,50}))
echo("\n")