Created
April 26, 2012 04:12
-
-
Save Alquimista/2495752 to your computer and use it in GitHub Desktop.
NANA MIZUKI - SILENT BIBLE karaoke effect (powered by Eyecandy)
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
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
from __future__ import division | |
import random | |
import eyecandy | |
from eyecandy.asstags import * | |
FILEINPUT = "(BD) NANA MIZUKI - SILENT BIBLE [ROMAJI1]" | |
FILEOUTPUT = FILEINPUT + "[FX]" | |
def draw(tipo, x, y): #TODO: move to eyecandy.asstags or drawtags | |
return '{:s} {:d} {:d} '.format(tipo, x, y) | |
# Pentagono | |
#TODO: move polar2rec to math library or someting similar (eyecandy) | |
def pentagon(r): | |
ppoints = (polar2rec(r, 90), polar2rec(r, 162), polar2rec(r, 234), | |
polar2rec(r, 306), polar2rec(r, 378)) | |
i = 0 | |
pdraw = [] | |
for x, y in ppoints: | |
x, y = int(round(x, 0)), int(round(y, 0)) | |
if i == 0: | |
dcommand = 'm' | |
else: | |
dcommand = 'l' | |
pdraw.append(draw(dcommand, x, y)) | |
i += 1 | |
return "".join(pdraw) | |
pentagondraw = pentagon(r=10) | |
@core.timeit | |
def simple_fx(inputfile, output): | |
subs = eyecandy.load(inputfile) | |
SUBS = eyecandy.progressbar(it=subs.getlines(), prefix='Processing', | |
sufix='Dialog Lines') | |
RESX, RESY = subs.getresolution() | |
CWHITE = eyecandy.asscolor.Color.from_name('white') | |
#zen master II: http://kuler.adobe.com/index.cfm#themeID/1842975 | |
_C1, _C2, _C3, _C4, _C5 = ( | |
eyecandy.asscolor.Color.from_hex('4F443A'), | |
eyecandy.asscolor.Color.from_hex('7F8E98'), | |
eyecandy.asscolor.Color.from_hex('B2CBD9'), | |
eyecandy.asscolor.Color.from_hex('E5EEF5'), | |
eyecandy.asscolor.Color.from_hex('EFDAAD')) | |
_c1, _c2, _c3, _c4, _c5 = (c.bgrhex for c in (_C1, _C2, _C3, _C4, _C5)) | |
C1A, C2A, C3A, C4A, C5A = ( | |
eyecandy.asscolor.Color.from_hex('622E08'), | |
eyecandy.asscolor.Color.from_hex('E9C6A5'), | |
eyecandy.asscolor.Color.from_hex('D4C8B8'), | |
eyecandy.asscolor.Color.from_hex('FFFFFF'), | |
eyecandy.asscolor.Color.from_hex('622E08')) | |
c1a, c2a, c3a, c4a, c5a = (c.bgrhex for c in (C1A, C2A, C3A, C4A, C5A)) | |
# an7: pos(.left, .top) | |
# an8: pos(.center, .top) | |
# an9: pos(.right, .top) | |
# an4: pos(.left, .middle) | |
# an5: pos(.center, .middle) | |
# an6: pos(.right, .middle) | |
# an1: pos(.left, .bottom) | |
# an2: pos(.center, .bottom) | |
# an3: pos(.right, .bottom) | |
for line in SUBS: | |
if line.effect == 'alt': | |
c1, c2, c3, c4, c5 = c1a, c2a, c3a, c4a, c5a | |
C2, C3 = C2A, C3A | |
cluz = "C7ECF9" | |
else: | |
c1, c2, c3, c4, c5 = _c1, _c2, _c3, _c4, _c5 | |
C2, C3, = _C2, _C3 | |
cluz = 'FAE7C8' | |
GRADIENT = C2.gradient( | |
CWHITE, int(line.height), eyecandy.interpolate.cosine) | |
GRADIENT2 = C3.gradient( | |
CWHITE, int(line.height), eyecandy.interpolate.cosine) | |
# POS | |
x, y = line.center, line.middle | |
tempo = 0 | |
subs.setdefaultdialog( | |
start=line.start - 50, | |
end=line.end, | |
text=line.text, | |
style=line.style.name, | |
layer=3) | |
if line.style.name == 'es': | |
# Entrada/Salida traduccion | |
subs.adddialog( | |
start=line.start - 80, | |
end=line.end + 80, | |
tag=('{' + an(5) + pos(x, y) + be() + | |
fad(80, 80) + c('FFFFFF') + c(3, c1) + '}')) | |
for syl in line.getsyls(): | |
# Default values | |
subs.setdefaultdialog( | |
start=syl.start - 50, | |
end=syl.end, | |
text=syl.text, | |
style=line.style.name, | |
layer=0) | |
x = syl.center | |
if line.style.name == 'rom' or line.style.name == 'jp': | |
# Entrada/Salida | |
subs.adddialog( | |
start=line.start - 200, | |
end=line.start - 50, | |
tag=('{' + an(5) + imove(x-5, y, 5, 0) + c(c2) + c(3, c1) + | |
blur() + fad(200, 0) + '}')) | |
subs.adddialog( | |
start=line.end, | |
end=line.end + 200, | |
tag=('{' + an(5) + imove(x, y, 5, 0) + c(c3) + c(3, c1) + | |
blur() + fad(0, 200) + '}')) | |
# Silaba Cantada | |
FADTIME = syl.dur / 4 | |
subs.adddialog( | |
layer=1, | |
tag=('{' + an(5) + pos(x, y) + c(c4) + c(3, c5) + bord(2) + | |
blur(2) + t(c(3, c1) + blur() + bord(1.6)) + '}')) | |
# Silaba Cantada (Borde que crece) | |
subs.adddialog( | |
layer=2, | |
end=syl.end + 300, | |
tag=('{' + an(5) + pos(x, y) + c(c4) + c(3, c5) + | |
a(1, 255) + bord(1.6) + blur(1) + fad(FADTIME.ms, 500) + | |
t(fsc(180) + c(3, c3)) + '}')) | |
if line.style.name == 'rom': | |
# Silaba por cantar | |
for i, clr in enumerate(GRADIENT): | |
#TODO: Problema con dialog.right (eyecandy) | |
LLEFT = int(line.left - 8) | |
LTOP = int(line.top + 6) | |
LRIGHT = int(RESX) | |
CLIP = clip(LLEFT, LTOP + i, LRIGHT, LTOP + i + 1) | |
CLR = clr.bgrhex | |
subs.adddialog( | |
start=line.start - 50, | |
end=syl.start, | |
tag=('{' + an(5) + pos(x, y) + c(CLR) + c(3, c1) + | |
CLIP + blur() + '}')) | |
# Silabas Cantadas | |
for i, clr in enumerate(GRADIENT2): | |
#TODO: Problema con dialog.right (eyecandy) | |
LLEFT = int(line.left - 8) | |
LTOP = int(line.top + 6) | |
LRIGHT = int(RESX) | |
CLIP = clip(LLEFT, LTOP + i, LRIGHT, LTOP + i + 1) | |
CLR = clr.bgrhex | |
subs.adddialog( | |
start=line.start - 50, | |
end=line.end, | |
tag=('{' + an(5) + pos(x, y) + c(CLR) + c(3, c1) + | |
CLIP + blur() + '}')) | |
# Nieve (luces/pentagono) | |
for i in xrange(5): | |
x1 = x + random.uniform(-18, 18) | |
x2 = x + random.uniform(-20, 5) | |
y1 = y + random.uniform(-15, 16) | |
y2 = y + random.uniform(18, 24) | |
ALPHA = a(random.randint(80, 180)) | |
FAD = fad(random.randint(50, 200), | |
random.randint(50, 500)) | |
subs.adddialog( | |
layer=0, | |
start=syl.start + random.randint(1, 100), | |
end=syl.end + random.randint(200, 1200), | |
text=p(2, pentagondraw), | |
tag=('{' + an(5) + | |
move(x1, y1, x2, y2) + c(cluz) + | |
fad(100, 200) + ALPHA + | |
bord(0) + fsc(random.randint(70, 120)) + '}')) | |
elif line.style.name == 'jp': | |
# Silaba por cantar | |
subs.adddialog( | |
start=line.start - 50, | |
end=syl.start, | |
tag=('{' + an(5) + pos(x, y) + c(c2) + c(3, c1) + | |
blur() + '}')) | |
# Silabas Cantadas | |
subs.adddialog( | |
start=line.start - 50, | |
end=line.end, | |
tag=('{' + an(5) + pos(x, y) + c(c3) + c(3, c1) + | |
blur() + '}')) | |
tempo += 1000 / line.syl_n | |
# Save to disk | |
subs.save(output) | |
if __name__ == '__main__': | |
simple_fx(FILEINPUT + '.ass', FILEOUTPUT + '.ass') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment