Page 1 of 1

Rainbow Memrec Coloring

Posted: Mon Aug 09, 2021 10:14 pm
by EpicBirdi
I'm trying to create a lua function that will cycle the color of a memrec through a rainbow gradient, and I'm certain I'm close to success here, but I feel like my math is off or something.. it continues flashing to incorrect colors randomly but otherwise works as it should.

If somebody could help I'd greatly appreciate it. Attached is my demo table, comments included for every script. Table's lua script needs to run to function. There's a commented-out debug print where the color is generated in the main lua.

The color is determined by combining three out-of-phase sinewaves and combining them as RGB.
Image
LuaColorCycle.CT
(11.55 KiB) Downloaded 156 times

Re: Rainbow Memrec Coloring

Posted: Tue Aug 10, 2021 12:16 am
by aSwedishMagyar
I suspect it's an issue with your biasing. When it suddenly flashes to another color you can assume that the value wrapped around to 257 or -1.

Here's what I came up with that seems to work ok:

Re: Rainbow Memrec Coloring

Posted: Tue Aug 10, 2021 1:16 am
by EpicBirdi
Yours works perfectly, thanks a million for the help!
I'll have to see what I can change in mine, or simply adapt yours a bit.. using it as a way to highlight things for a tutorial script lol.
Is there a particular reason you're using n×pi/4 as phases versus their closest counterparts? I couldn't notice much of a difference, but I'd like to know what you think on it.

Re: Rainbow Memrec Coloring

Posted: Tue Aug 10, 2021 1:21 am
by aSwedishMagyar
EpicBirdi wrote:
Tue Aug 10, 2021 1:16 am
Yours works perfectly, thanks a million for the help!
I'll have to see what I can change in mine, or simply adapt yours a bit.. using it as a way to highlight things for a tutorial script lol.
Is there a particular reason you're using n×pi/4 as phases versus their closest counterparts? I couldn't notice much of a difference, but I'd like to know what you think on it.
It's mostly just because that's how I think of phase offsets with radians..

I modified that script to also have a background function so you can really see the difference since I can't really tell with the small text on the records.

Oh and the transition will be less choppy if you change the update timer:

Code: Select all

local upTimer = getUpdateTimer()
upTimer.SetInterval(1)