function ass_alpha(aa) return string.format("&H%02X&",aa)endfunction alpha_ass(aa) return tonumber(aa, 16)endfunction identity(m) return mendfunction sinmult(m) return 4*math.sin(m/4)endfunction distance_1(a,b) return math.abs(a+b)endfunction distance_2(a,b) return math.sqrt(a^2+b^2)endfunction eval_string (str) return loadstring("return "..str)endfunction calc_time_stamp_line(stamp,line) local time_value = 0 for sign_precalc, value in string.gfind(stamp, "pD([%+%-])(%d+)D") do if sign_precalc == "-" then time_value = -value else time_value = value end end for ident, sign, value in string.gfind(stamp, "(%d+)D([%+%-])(%d+)M") do if ident == "3" then if sign == "+" then time_value = time_value + value * line.start_time else time_value = time_value - value * line.start_time end elseif ident == "4" then if sign == "+" then time_value = time_value + value * line.start_time else time_value = time_value - value * line.start_time end elseif ident == "6" then if sign == "+" then time_value = time_value + ( line.end_time - line.start_time ) else time_value = time_value - ( line.end_time - line.start_time ) end end end for sign, value in string.gfind(stamp, "oD([%+%-])(%d+)M") do if sign == "+" then time_value = time_value + value else time_value = time_value - value end end return time_valueendfunction calc_time_stamp_syl(stamp,syl) -- Check for precalced value, there should be only 1 local time_value = 0 for sign_precalc, value in string.gfind(stamp, "pD([%+%-])(%d+)D") do if sign_precalc == "-" then time_value = -value else time_value = value end end for ident, sign, value in string.gfind(stamp, "(%d)D([%+%-])(%d+)M") do if ident == "1" then if sign == "+" then time_value = time_value + value * syl.start_time else time_value = time_value - value * syl.start_time end elseif ident == "2" then if sign == "+" then time_value = time_value + value * syl.start_time else time_value = time_value - value * syl.start_time end elseif ident == "5" then if sign == "+" then time_value = time_value + value * ( syl.end_time - syl.start_time ) else time_value = time_value - value * ( syl.end_time - syl.start_time ) end end end return time_valueendfunction sumTotalValFun(val_function,max) local sumValFun = 0 for m=1, max do sumValFun = sumValFun + math.abs(val_function(m)) end return sumValFunend--[[ 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 outblurend--[[ Generalized angle blur, 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_angle_blur(line, diameter, value_function, angle, invert, posX, posY, animate, boost_factor) 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&", "") -- line.text = string.gsub(line.text, "\\bord[%d.]+", "") -- Sounds ugly, but since lambdas are not nice in lua, we're going for named function func1(n) return math.abs(value_function(n)-value_function(n-1)) end function func2(n) return math.abs(value_function(diameter+2-n)-value_function(diameter+1-n)) end local func0 = {} if invert==false then func0.valueF = func1 else func0.valueF = func2 end -- Proportional Factor local blurLevelLinearConst = 255/sumTotalValFun(func0.valueF, diameter+1) local baseline = copy_line(line) local baselinealpha = ass_alpha(255-blurLevelLinearConst*math.max(0,func0.valueF(0))/2*boost_factor) baseline.text = string.format("{\\shad0\\pos(%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX, posY, baselinealpha, baselinealpha, baselinealpha, baselinealpha) .. line.text table.insert(outblur, baseline) for m=1, diameter+1 do local newline = copy_line(line) local newline2 = copy_line(line) local blurLevelLinear = ass_alpha(255-blurLevelLinearConst*math.max(0,func0.valueF(m))/2*boost_factor) local posX1, posY1 = posX+math.cos(angle)*m, posY+math.sin(angle)*m,blurLevelLinear local posX2, posY2 = posX-math.cos(angle)*m, posY-math.sin(angle)*m,blurLevelLinear if animate == true then newline.text = string.format("{\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX, posY, posX1, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text newline2.text = string.format("{\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX, posY, posX2, posY2, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text else newline.text = string.format("{\\shad0\\pos(%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX1, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text newline2.text = string.format("{\\shad0\\pos(%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX2, posY2, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text end table.insert(outblur, newline) table.insert(outblur, newline2) end return outblurend--[[ Generalized \bord glow, please note that shadow is disabled(shadow is not alpha clipped and causes problems) Params: line - the line to glow using border diameter - glow diameter value_function - the function that gives the curve of the glow, please note that the function must be strictly growing for an acceptable result, for a simple traditional linear glow, use "identity" 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 Needs: sumTotalValFun - Function that allows calculation of the proportionality coefficient]]function generalized_glow(line, diameter, value_function, invert) local outblur = { n=0 } -- Strip away existing codes that can interfere line.text = string.gsub(line.text, "\\3a&H%x%x&", "") line.text = string.gsub(line.text, "\\bord[%d.]+", "") -- Sounds ugly, but since lambdas are not nice in lua, we're going for named function func1(n) return value_function(n)-value_function(n-1) end function func2(n) return value_function(diameter+2-n)-value_function(diameter+1-n) end local func0 = {} if invert==false then func0.valueF = func1 else func0.valueF = func2 end -- Proportional Factor local blurLevelLinearConst = 255/sumTotalValFun(func0.valueF, diameter+1) for m=1, (diameter+1) do local newline1 = copy_line(line) blurLevelLinear = ass_alpha(255-blurLevelLinearConst*(func0.valueF(m))) newline1.text = string.format("{\\bord%d\\shad0\\1a%s\\3a%s}", m, blurLevelLinear, blurLevelLinear) .. line.text table.insert(outblur, newline1) end table.insert(outblur, line) return outblurend--[[ for m=1, (diameter+1) do for n=0,m do local newline1 = copy_line(line) local newline2 = copy_line(line) local newline3 = copy_line(line) local newline4 = copy_line(line) local blurLevelLinear = ass_alpha(255-blurLevelLinearConst*math.max(0,func0.valueF(m))/diameter*boost_factor) local posX1, posY1 = posX+n*2, posY+(m-n)*2 local posX2, posY2 = posX-n*2, posY-(m-n)*2 if animate == true then newline1.text = string.format("{\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX, posY, posX1, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text newline2.text = string.format("{\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX, posY, posX1, posY2, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text newline3.text = string.format("{\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX, posY, posX2, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text newline4.text = string.format("{\\shad0\\move(%d,%d,%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX, posY, posX2, posY2, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text else newline1.text = string.format("{\\shad0\\pos(%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX1, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text newline2.text = string.format("{\\shad0\\pos(%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX1, posY2, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text newline3.text = string.format("{\\shad0\\pos(%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX2, posY1, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text newline4.text = string.format("{\\shad0\\pos(%d,%d)\\1a%s\\2a%s\\3a%s\\4a%s}", posX2, posY2, blurLevelLinear, blurLevelLinear, blurLevelLinear, blurLevelLinear) .. line.text end table.insert(outblur, newline1) table.insert(outblur, newline2) table.insert(outblur, newline3) table.insert(outblur, newline4) end end]]