--[[
Generalized blur, uses a diamond shaped placement and uses the curves
Params:
line - the line to glow using border
diameter - blur diameter
value_function - the function that gives the curve of the blur, for a simple traditional linear blur, use "identity"
angle - angle of the blur(in radian)
invert - this makes the curve inverted, while this can be done with the reciprocal function of value_function, it might be faster to use this
posX, posY - position of the original line
animate - if set to true, the blur is animated to grow, else it's constant
boost_factor - since the blur might look too weak, the boost_factor allows to give an overall boost, making everything brighter(typical value is 2)
Needs:
sumTotalValFun - Function that allows calculation of the proportionality coefficient
]]
function generalized_blur(line, diameter, value_function, distance_function, posX, posY, animate, animateIn, smooth, boost_factor, resolution)
local outblur = { n=0 }
-- Strip away existing codes that can interfere
line.text = string.gsub(line.text, "\\pos%(%d+,%d+%)", "")
line.text = string.gsub(line.text, "\\3a&H%x%x&", "")
--out("params are, diam=" .. diameter .. " animate=" .. animate .. " animateIn=" .. animateIn .. " boost_factor=" .. boost_factor .. " resolution=" .. resolution)
local sumTotal = 0
--Precalc coefficient
for m=0, (diameter-1)/resolution do
for n=0, (diameter-1)/resolution do
sumTotal= sumTotal + value_function(distance_function(m*resolution-diameter/2,n*resolution-diameter/2))
end
end
--circling around
for m=0, (diameter-1)/resolution do
for n=0, (diameter-1)/resolution do
local blurLevelLinear = ass_alpha(255-value_function(distance_function(m*resolution-diameter/2,n*resolution-diameter/2))*255/sumTotal*boost_factor)
local newline1 = copy_line(line)
local posX1, posY1 = posX+m*resolution-diameter/2, posY+n*resolution-diameter/2
if animate == "1" then
if animateIn == "1" then
if smooth == 0 then
newline1.text = string.format("{\\be0\\bord0\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX, posY, posX1, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text
else
newline1.text = string.format("{\\be0\\bord0\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", (100*posX+smooth*posX1)/(100+smooth), (100*posY+smooth*posY1)/(100+smooth), posX1, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text
end
else
if smooth == 0 then
newline1.text = string.format("{\\be0\\bord0\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX1, posY1, posX, posY, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text
else
newline1.text = string.format("{\\be0\\bord0\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX1, posY1, (100*posX+smooth*posX1)/(100+smooth), (100*posY+smooth*posY1)/(100+smooth), blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text
end
end
else
newline1.text = string.format("{\\be0\\bord0\\shad0\\pos(%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX1, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text
end
table.insert(outblur, newline1)
end
end
return outblur
end