Created
September 9, 2019 19:20
-
-
Save Ereza/ae2b1c07f94f03320680cc6ecc043c93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Efecte d'aparició i desaparició i degradat central | |
-- Aplica un efecte d'aparició i desaparició i degradat central a cada caràcter | |
local tr = aegisub.gettext | |
script_name = "Efecte d'aparició i desaparició i degradat central" | |
script_description = "Aplica un efecte d'aparició i desaparició i degradat central a cada caràcter" | |
script_author = "Ereza" | |
script_version = "1" | |
include("unicode.lua") | |
appear_time_ms = 400 | |
disappear_time_ms = 400 | |
origin_r = 165 | |
target_r = 165 | |
origin_g = 119 | |
target_g = 119 | |
origin_b = 119 | |
target_b = 200 | |
blur = 5 | |
function apply_effect(subtitles, selected_lines, active_line) | |
for z, i in ipairs(selected_lines) do | |
local l = subtitles[i] | |
aegisub.debug.out(string.format('Processing line %d: "%s"\n', i, l.text)) | |
aegisub.debug.out("Chars: \n") | |
local in_tags = false | |
local newtext = "" | |
local fadein_start = 0 | |
local fadein_end = appear_time_ms | |
local fadeout_start = l.end_time - l.start_time - disappear_time_ms - disappear_time_ms | |
local fadeout_end = l.end_time - l.start_time - disappear_time_ms | |
local length = 0 | |
local color_r = origin_r | |
local color_g = origin_g | |
local color_b = origin_b | |
for c in unicode.chars(l.text) do | |
if c == "{" then | |
in_tags = true | |
end | |
if in_tags then | |
-- nothing | |
else | |
length = length + 1 | |
end | |
if c == "}" then | |
in_tags = false | |
end | |
end | |
for c in unicode.chars(l.text) do | |
aegisub.debug.out(c .. ' -> ') | |
if c == "{" then | |
in_tags = true | |
end | |
if in_tags then | |
aegisub.debug.out(c .. " (ignored, in tags)\n") | |
newtext = newtext .. c | |
else | |
aegisub.debug.out(c .. " (converted)\n") | |
newtext = newtext .. "{\\r" .. l.effect .. "\\blur" .. blur .. "\\3c&H" .. string.format("%x", color_r) .. string.format("%x", color_g) .. string.format("%x", color_b) .. "&\\alpha&HFF&\\t(" .. fadein_start .. "," .. fadein_end .. ",\\alpha&H00&)\\t(" .. fadeout_start .. "," .. fadeout_end .. ",\\alpha&HFF&)}" .. c | |
fadein_start = fadein_start + appear_time_ms / length | |
fadein_end = fadein_end + appear_time_ms / length | |
fadeout_start = fadeout_start + disappear_time_ms / length | |
fadeout_end = fadeout_end + disappear_time_ms / length | |
if (fadein_start > appear_time_ms/2) then | |
--We are beyond the half of the syllable, start going back to original color | |
color_r = color_r - (target_r-color_r)*2/length | |
color_g = color_g - (target_g-color_g)*2/length | |
color_b = color_b - (target_b-color_b)*2/length | |
else | |
--We are before the half of the syllable, go to target color gradually | |
color_r = color_r + (target_r-color_r)*2/length | |
color_g = color_g + (target_g-color_g)*2/length | |
color_b = color_b + (target_b-color_b)*2/length | |
end | |
end | |
if c == "}" then | |
in_tags = false | |
end | |
end | |
l.text = newtext | |
subtitles[i] = l | |
end | |
aegisub.set_undo_point("Efecte d'aparició i desaparició i degradat central") | |
end | |
aegisub.register_macro("Efecte d'aparició i desaparició i degradat central", "Aplica un efecte d'aparició i desaparició i degradat central a cada caràcter", apply_effect) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment