101 lines
2 KiB
Lua
101 lines
2 KiB
Lua
COOLDOWN_FACTOR = 0.9998
|
|
FADE_FACTOR = 1
|
|
OVERDRIVE = 1.30
|
|
EXPONENT = 1.8
|
|
|
|
SHIFT=2
|
|
|
|
num_modules = 20
|
|
center_module = 10
|
|
|
|
-- maximum energy values for each band
|
|
maxRedEnergy = 1
|
|
maxGreenEnergy = 1
|
|
maxBlueEnergy = 1
|
|
|
|
-- output color buffers
|
|
red = {}
|
|
green = {}
|
|
blue = {}
|
|
|
|
tmpRed = {}
|
|
tmpGreen = {}
|
|
tmpBlue = {}
|
|
|
|
function limit(val)
|
|
if val > 1 then
|
|
return 1
|
|
else
|
|
return val
|
|
end
|
|
end
|
|
|
|
function periodic()
|
|
local redEnergy = get_energy_in_band(0, 400);
|
|
local greenEnergy = get_energy_in_band(400, 4000);
|
|
local blueEnergy = get_energy_in_band(4000, 22000);
|
|
local centerIndex = 2 * center_module + 1;
|
|
|
|
maxRedEnergy = maxRedEnergy * COOLDOWN_FACTOR
|
|
if redEnergy > maxRedEnergy then
|
|
maxRedEnergy = redEnergy
|
|
end
|
|
|
|
maxGreenEnergy = maxGreenEnergy * COOLDOWN_FACTOR
|
|
if greenEnergy > maxGreenEnergy then
|
|
maxGreenEnergy = greenEnergy
|
|
end
|
|
|
|
maxBlueEnergy = maxBlueEnergy * COOLDOWN_FACTOR
|
|
if blueEnergy > maxBlueEnergy then
|
|
maxBlueEnergy = blueEnergy
|
|
end
|
|
|
|
-- move the color buffers on by one
|
|
for i = num_modules-SHIFT,1,-1 do
|
|
tmpRed[i+SHIFT] = FADE_FACTOR * tmpRed[i]
|
|
tmpGreen[i+SHIFT] = FADE_FACTOR * tmpGreen[i]
|
|
tmpBlue[i+SHIFT] = FADE_FACTOR * tmpBlue[i]
|
|
end
|
|
|
|
-- set the new value for the center module
|
|
newRed = redEnergy / maxRedEnergy
|
|
newGreen = greenEnergy / maxGreenEnergy
|
|
newBlue = blueEnergy / maxBlueEnergy
|
|
|
|
for i = 1,SHIFT do
|
|
tmpRed[i] = newRed
|
|
tmpGreen[i] = newGreen
|
|
tmpBlue[i] = newBlue
|
|
end
|
|
|
|
for i = 1,num_modules do
|
|
red[i] = limit(OVERDRIVE * math.pow(tmpRed[i], EXPONENT))
|
|
green[i] = limit(OVERDRIVE * math.pow(tmpGreen[i], EXPONENT))
|
|
blue[i] = limit(OVERDRIVE * math.pow(tmpBlue[i], EXPONENT))
|
|
end
|
|
|
|
-- return the 3 color arrays
|
|
return red, green, blue
|
|
end
|
|
|
|
function init(nmod, cmod)
|
|
num_modules = nmod
|
|
center_module = cmod
|
|
|
|
for i = 1,nmod do
|
|
red[i] = 0
|
|
green[i] = 0
|
|
blue[i] = 0
|
|
end
|
|
|
|
for i = 1,nmod do
|
|
tmpRed[i] = 0
|
|
tmpGreen[i] = 0
|
|
tmpBlue[i] = 0
|
|
end
|
|
|
|
-- don't use fading
|
|
return 0
|
|
end
|