musiclight2/old_scripts/pulsecircle.lua

113 lines
2.3 KiB
Lua
Raw Normal View History

2012-08-08 22:59:43 +02:00
COOLDOWN_FACTOR = 0.9998
FADE_FACTOR = 1
OVERDRIVE = 1.30
EXPONENT = 1.8
2012-08-08 22:59:43 +02:00
num_modules = 160
center_module = 80
2012-08-08 22:59:43 +02:00
-- 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
2012-08-08 22:59:43 +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);
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
tmpRed[1] = newRed
--if newRed > tmpRed[num_modules] then
-- tmpRed[1] = newRed
--else
-- tmpRed[1] = tmpRed[num_modules]
--end
2012-08-08 22:59:43 +02:00
newGreen = greenEnergy / maxGreenEnergy
tmpGreen[1] = newGreen
--if newGreen > tmpGreen[num_modules] then
-- tmpGreen[1] = newGreen
--else
-- tmpGreen[1] = tmpGreen[num_modules]
--end
2012-08-08 22:59:43 +02:00
newBlue = blueEnergy / maxBlueEnergy
tmpBlue[1] = newBlue
--if newBlue > tmpBlue[num_modules] then
-- tmpBlue[1] = newBlue
--else
-- tmpBlue[1] = tmpBlue[num_modules]
--end
2012-08-08 22:59:43 +02:00
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))
2012-08-08 22:59:43 +02:00
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