100 lines
2 KiB
Lua
100 lines
2 KiB
Lua
|
COOLDOWN_FACTOR = 0.9998
|
||
|
FADE_FACTOR = 0.985
|
||
|
|
||
|
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 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-1,1,-1 do
|
||
|
tmpRed[i+1] = FADE_FACTOR * tmpRed[i]
|
||
|
tmpGreen[i+1] = FADE_FACTOR * tmpGreen[i]
|
||
|
tmpBlue[i+1] = FADE_FACTOR * tmpBlue[i]
|
||
|
end
|
||
|
|
||
|
-- set the new value for the center module
|
||
|
newRed = redEnergy / maxRedEnergy
|
||
|
if newRed > tmpRed[num_modules] then
|
||
|
tmpRed[1] = newRed
|
||
|
else
|
||
|
tmpRed[1] = tmpRed[num_modules]
|
||
|
end
|
||
|
|
||
|
newGreen = greenEnergy / maxGreenEnergy
|
||
|
if newGreen > tmpGreen[num_modules] then
|
||
|
tmpGreen[1] = newGreen
|
||
|
else
|
||
|
tmpGreen[1] = tmpGreen[num_modules]
|
||
|
end
|
||
|
|
||
|
newBlue = blueEnergy / maxBlueEnergy
|
||
|
if newBlue > tmpBlue[num_modules] then
|
||
|
tmpBlue[1] = newBlue
|
||
|
else
|
||
|
tmpBlue[1] = tmpBlue[num_modules]
|
||
|
end
|
||
|
|
||
|
for i = 1,num_modules do
|
||
|
red[i] = tmpRed[i]
|
||
|
green[i] = tmpGreen[i]
|
||
|
blue[i] = tmpBlue[i]
|
||
|
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
|