Better Rainbows!

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

  • Oh, dammit. It was defaulting to the crappy rainbow. Fixed script here. Blergh.
  • So, someone asked how this all really works, so I thought I'd show you my own crit trigger, and you can copy it, modify it into your own crit triggers, or make new stuff based off it.

    It's a standard trigger, with a regex line that appears so:
    ^You have scored an? ([A-Z\-\s]+) hit!!?!?$
    Then, in the script window below, I have this:

    selectCurrentLine()<br>deleteLine()<br>hecho(rainbow("\n"..matches[1]))
    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.
    rainbow_string = rainbow(string)
    And then elsewhere, do this:
    hecho("This is a rainbow string: " .. rainbow_string)
    A little simplified, but it should show you how to use the function.
  • Hey @Tydas : Is there a way that this can be tied into the Svof politics system?
  • @Tydas this works amazingly well. Thanks!
    Omor Ceberek - Targossas

    got gud
  • Tahquil said:
    Hey @Tydas : Is there a way that this can be tied into the Svof politics system?
    Not that I know of. I'm actually working on ripping that out of svof, since it and the custom prompt are the only two things in svof I really want anymore, and I already did the latter. I figured I'd share it when I finished, and I can probably work this into it. No idea when I'll get that done, though.
  • KenwayKenway San Francisco
    Oh you did the two things I was gonna edit your gradient thing to do for me. Thanks yo.

    - Limb Counter - Fracture Relapsing -
    "Honestly, I just love that it counts limbs." - Mizik Corten
  • KresslackKresslack Florida, United States
    Sorry if I'm missing the obvious, but out of my element here with this stuff. How do I set the type and frequency? Am wanting to use type 1 with frequency of 1.


  • Kresslack said:
    Sorry if I'm missing the obvious, but out of my element here with this stuff. How do I set the type and frequency? Am wanting to use type 1 with frequency of 1.
    He answered that in the second post, for crits!
  • KresslackKresslack Florida, United States
    Pyori said:
    Kresslack said:
    Sorry if I'm missing the obvious, but out of my element here with this stuff. How do I set the type and frequency? Am wanting to use type 1 with frequency of 1.
    He answered that in the second post, for crits!
    Oh, RIP me. Sorry really tired, thank you!


  • How do i get this to start?

  • Sorry to necro this thread, but darned if I can get this going. I put Tydas' code in a script as shown, but am having trouble getting it to work - I suspect I'm missing a line or two in my trigger, but not sure exactly what.

    What *should* the trigger code look like for this?

  • edited May 2020
    My trigger looks like this:

    ^You have scored an? ([A-Z\-\s]+) hit!!?!?$

    Then:
    deleteLine()
    selectCurrentLine()
    hecho(" "..rainbow(matches[2]))

    And when someone is petrified and ready to be extiprated (So I notice it more easily):

    hecho("\n"..rainbow("PETRIFIED !!!  EXTIRPATE THEM!"))
    hecho("\n"..rainbow("PETRIFIED !!!  EXTIRPATE THEM!"))
    hecho("\n"..rainbow("PETRIFIED !!!  EXTIRPATE THEM!"))
    hecho("\n"..rainbow("PETRIFIED !!!  EXTIRPATE THEM!"))
    hecho("\n"..rainbow("PETRIFIED !!!  EXTIRPATE THEM!"))


    This is the code I have for the rainbow function / script:

    function rainbow(str, type, freq)
        -- 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





Sign In or Register to comment.