So after my color gradient thing, I decided to improve my rainbow echoes, so I can get truly beautiful rainbow crit echoes. Came across some stuff in my gradient work and bookmarked it, and now I've finished it.
Comes in three types. Type 0, the default, starts from one random color, and slowly moves across the spectrum back to itself when it hits the last color. A smooth, single cycle rainbow effect. Looks great, my personal favorite for crits.
Type 1 gives you the option of setting a frequency. This is basically how big of a step in color each character should take. Lower numbers mean bigger steps. A freq of 1 (and looks like 2) are solid colors. 4 gets a nice random version of that gradient thing I wrote earlier. Higher numbers mean fewer colors shown in return for repeating that cycle across the string. Take a look at the examples.
Type 2 is the old, ugly version I used to use for my crits, and which I posted here a long while back. It's basically a hard-coded type 1 with not-great colors. The other two are much slicker. Kept it mostly because I hate throwing things away.
Called like such:
rainbow("Hey there") -- type 0<br>rainbow("Hey there", 1) -- type 1, freq is 15<br>rainbow("Hey there", 1, 5) -- type 1, freq is 5<br>rainbow("Hey there", 2) -- type 2, if you really must
Examples here.Edit to add that, some might/be the same on that example. It's because of Lua's sucky random number generator, which is actually C's sucky random number generator, and even though I built in a better version to use I found in the Lua docs, it's still not going to be perfect. That said, you won't be able to tell unless you're rainbowing everything.
Code here. Code below. Just throw in a script thing in Mudlet.
Comments
It's a standard trigger, with a regex line that appears so:
Then, in the script window below, I have this:
This selects the line that was triggered, deletes it, then sends the matched line (matches[1] is the entire line that was captured) into the rainbow function, which is sent directly into hecho.
If you want to use the function elsewhere, you can also store it in a variable.
And then elsewhere, do this:
A little simplified, but it should show you how to use the function.
got gud
- Limb Counter - Fracture Relapsing -
"Honestly, I just love that it counts limbs." - Mizik Corten
selectCurrentLine()
hecho(" "..rainbow(matches[2]))
hecho("\n"..rainbow("PETRIFIED !!! EXTIRPATE THEM!"))
hecho("\n"..rainbow("PETRIFIED !!! EXTIRPATE THEM!"))
hecho("\n"..rainbow("PETRIFIED !!! EXTIRPATE THEM!"))
hecho("\n"..rainbow("PETRIFIED !!! EXTIRPATE THEM!"))
-- default settings, set to default if out-of-bounds
type = type or 0
if type > 2 or type < 0 then type = 0 end
freq = freq or 15
if freq < 0 or freq > 360 then freq = 15 end
local product = ""
local phase = 2 * math.pi / 3
local rand = betterRand()
if type == 0 then -- Non-repeating rainbow
freq = 2*math.pi / #str
for i = 1, #str do
if string.sub(str, i, i) == " " then
product = product..string.sub(str, i, i)
else
r = math.sin(freq*i + phase + rand*10) * 127 + 128
g = math.sin(freq*i + 0 + rand*10) * 127 + 128
b = math.sin(freq*i + 2*phase + rand*10) * 127 + 128
r = string.format("%x", r)
g = string.format("%x", g)
b = string.format("%x", b)
if #r < 2 then r = "0"..r end
if #g < 2 then g = "0"..g end
if #b < 2 then b = "0"..b end
product = product.."|c"..r..g..b..string.sub(str, i, i)
end
end
elseif type == 1 then -- Repeating rainbow
freq = freq * math.pi / 180
for i = 1, #str do
if string.sub(str, i, i) == " " then
product = product..string.sub(str, i, i)
else
r = math.sin(freq*i + phase + rand*10) * 127 + 128
g = math.sin(freq*i + 0 + rand*10) * 127 + 128
b = math.sin(freq*i + 2*phase + rand*10) * 127 + 128
r = string.format("%x", r)
g = string.format("%x", g)
b = string.format("%x", b)
if #r < 2 then r = "0"..r end
if #g < 2 then g = "0"..g end
if #b < 2 then b = "0"..b end
product = product.."|c"..r..g..b..string.sub(str, i, i)
end
end
elseif type == 2 then -- Old, uglier rainbow
local colours = { "|cFF0000", "|cFF6600", "|cFFEE00", "|c00FF00", "|c0099FF", "|c4400FF", "|c9900FF" }
local pass = math.random(7)
for char in str:gmatch"." do
if char == " " then
product = product .. char
else
product = product .. colours[pass] .. char
if pass == #colours then pass = 1 end
pass = pass + 1
end
end
end
return product.."|r"
end
function betterRand()
randomtable = {}
for i = 1, 97 do
randomtable[i] = math.random()
end
local x = math.random()
local i = 1 + math.floor(97*x)
x, randomtable[i] = randomtable[i], x
return x
end