2012-11-26 17:52:06 +01:00
|
|
|
COOLDOWN_FACTOR = 0.995
|
|
|
|
|
|
|
|
BALANCE_RED = 7.0
|
|
|
|
BALANCE_GREEN = 2.0
|
|
|
|
BALANCE_BLUE = 1.5
|
|
|
|
|
|
|
|
num_modules = 20
|
|
|
|
center_module = 10
|
|
|
|
|
|
|
|
-- maximum energy value
|
|
|
|
maxEnergy = 1
|
|
|
|
|
|
|
|
-- output color buffers
|
|
|
|
red = {}
|
|
|
|
green = {}
|
|
|
|
blue = {}
|
|
|
|
|
|
|
|
tmpRed = {}
|
|
|
|
tmpGreen = {}
|
|
|
|
tmpBlue = {}
|
|
|
|
|
|
|
|
function weighted_avg(array, centerIndex)
|
2018-06-19 22:13:22 +02:00
|
|
|
return 0.20 * array[centerIndex - 1] +
|
|
|
|
0.60 * array[centerIndex] +
|
|
|
|
0.20 * array[centerIndex + 1]
|
2012-11-26 17:52:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function periodic()
|
|
|
|
local redEnergy = get_energy_in_band(0, 400) * BALANCE_RED
|
|
|
|
local greenEnergy = get_energy_in_band(400, 5000) * BALANCE_GREEN
|
|
|
|
local blueEnergy = get_energy_in_band(5000, 22000) * BALANCE_BLUE
|
|
|
|
local centerIndex = 2 * center_module + 1;
|
|
|
|
|
|
|
|
maxEnergy = maxEnergy * COOLDOWN_FACTOR
|
|
|
|
if redEnergy > maxEnergy then
|
|
|
|
maxEnergy = redEnergy
|
|
|
|
end
|
|
|
|
|
|
|
|
if greenEnergy > maxEnergy then
|
|
|
|
maxEnergy = greenEnergy
|
|
|
|
end
|
|
|
|
|
|
|
|
if blueEnergy > maxEnergy then
|
|
|
|
maxEnergy = blueEnergy
|
|
|
|
end
|
|
|
|
|
|
|
|
-- move the color buffers on by one in each direction
|
|
|
|
for i = 2,centerIndex,1 do
|
|
|
|
tmpRed[i-1] = tmpRed[i]
|
|
|
|
tmpGreen[i-1] = tmpGreen[i]
|
|
|
|
tmpBlue[i-1] = tmpBlue[i]
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = #tmpRed-1,centerIndex,-1 do
|
|
|
|
tmpRed[i+1] = tmpRed[i]
|
|
|
|
tmpGreen[i+1] = tmpGreen[i]
|
|
|
|
tmpBlue[i+1] = tmpBlue[i]
|
|
|
|
end
|
|
|
|
|
|
|
|
-- set the new value for the center module
|
|
|
|
tmpRed[centerIndex] = redEnergy / maxEnergy
|
|
|
|
tmpGreen[centerIndex] = greenEnergy / maxEnergy
|
|
|
|
tmpBlue[centerIndex] = blueEnergy / maxEnergy
|
|
|
|
|
|
|
|
for i = 1,num_modules do
|
2018-06-19 22:13:22 +02:00
|
|
|
--red[i] = tmpRed[i+centerIndex-num_modules/2]
|
|
|
|
--green[i] = tmpGreen[i+centerIndex-num_modules/2]
|
|
|
|
--blue[i] = tmpBlue[i+centerIndex-num_modules/2]
|
2012-11-26 17:52:06 +01:00
|
|
|
red[i] = weighted_avg(tmpRed, 2*i)
|
|
|
|
green[i] = weighted_avg(tmpGreen, 2*i)
|
|
|
|
blue[i] = weighted_avg(tmpBlue, 2*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,2*(nmod+1) do
|
|
|
|
tmpRed[i] = 0
|
|
|
|
tmpGreen[i] = 0
|
|
|
|
tmpBlue[i] = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
-- don't use fading
|
|
|
|
return 0
|
|
|
|
end
|