2012-07-28 01:30:20 +02:00
|
|
|
COOLDOWN_FACTOR = 0.9998
|
|
|
|
|
2018-06-19 22:13:22 +02:00
|
|
|
num_modules = 160
|
|
|
|
center_module = 80
|
2012-07-28 01:30:20 +02:00
|
|
|
|
|
|
|
-- maximum energy values for each band
|
|
|
|
maxRedEnergy = 1
|
|
|
|
maxGreenEnergy = 1
|
|
|
|
maxBlueEnergy = 1
|
|
|
|
|
|
|
|
-- output color buffers
|
|
|
|
red = {}
|
|
|
|
green = {}
|
|
|
|
blue = {}
|
|
|
|
|
2012-07-29 22:28:41 +02:00
|
|
|
tmpRed = {}
|
|
|
|
tmpGreen = {}
|
|
|
|
tmpBlue = {}
|
|
|
|
|
|
|
|
function weighted_avg(array, centerIndex)
|
|
|
|
return 0.2 * array[centerIndex - 1] +
|
|
|
|
0.6 * array[centerIndex] +
|
|
|
|
0.2 * array[centerIndex + 1]
|
|
|
|
end
|
|
|
|
|
2012-07-28 01:30:20 +02:00
|
|
|
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);
|
2012-07-29 23:46:03 +02:00
|
|
|
local centerIndex = 2 * center_module + 1;
|
2012-07-28 01:30:20 +02:00
|
|
|
|
|
|
|
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 in each direction
|
2012-07-29 22:28:41 +02:00
|
|
|
for i = 2,centerIndex,1 do
|
|
|
|
tmpRed[i-1] = tmpRed[i]
|
|
|
|
tmpGreen[i-1] = tmpGreen[i]
|
|
|
|
tmpBlue[i-1] = tmpBlue[i]
|
2012-07-28 01:30:20 +02:00
|
|
|
end
|
|
|
|
|
2012-07-29 22:28:41 +02:00
|
|
|
for i = #tmpRed-1,centerIndex,-1 do
|
|
|
|
tmpRed[i+1] = tmpRed[i]
|
|
|
|
tmpGreen[i+1] = tmpGreen[i]
|
|
|
|
tmpBlue[i+1] = tmpBlue[i]
|
2012-07-28 01:30:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- set the new value for the center module
|
2012-07-29 22:28:41 +02:00
|
|
|
tmpRed[centerIndex] = redEnergy / maxRedEnergy
|
|
|
|
tmpGreen[centerIndex] = greenEnergy / maxGreenEnergy
|
|
|
|
tmpBlue[centerIndex] = blueEnergy / maxBlueEnergy
|
|
|
|
|
|
|
|
for i = 1,num_modules do
|
|
|
|
red[i] = weighted_avg(tmpRed, 2*i)
|
|
|
|
green[i] = weighted_avg(tmpGreen, 2*i)
|
|
|
|
blue[i] = weighted_avg(tmpBlue, 2*i)
|
|
|
|
end
|
2012-07-28 01:30:20 +02:00
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
2012-07-29 22:28:41 +02:00
|
|
|
for i = 1,2*(nmod+1) do
|
|
|
|
tmpRed[i] = 0
|
|
|
|
tmpGreen[i] = 0
|
|
|
|
tmpBlue[i] = 0
|
|
|
|
end
|
|
|
|
|
2012-07-28 01:30:20 +02:00
|
|
|
-- don't use fading
|
|
|
|
return 0
|
|
|
|
end
|