- UID
- 2
- 积分
- 8682
- 帖子
- 2905
- 主题
- 199
- 论坛币
- 11741
- 威望
- 16
- EP值
- 2349
- MP值
- 15
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 2597 小时
- 最后登录
- 2024-8-28
|
特效工程 http://pan.baidu.com/s/1o61BDxg
视频预览http://pan.baidu.com/s/1pJBdfCZ- from tcaxPy import *
- from util.magick import *
- from util.tcAudio import *
- from util.tcCurve import *
- from pixLibs.ImageStone import *
- def tcaxPy_Init():
- global _Fs
- global _FD # 一帧的持续时间, 约40毫秒
- global _Spacing # 字体间距
- global Font # 首要字体
- global FontOut # 字体边框
- global FontOut2 # 字体边框2
- global COLORS # 边框二颜色
- global IMG_texs # 主要纹理
- global IMG_mask
- global IMG_eye
- global leading_frame_count
- global trailing_frame_count
- global channel
- global freq
- global avg_bar
- leading_frame_count = 10
- trailing_frame_count = 10
- _Fs = GetVal(val_FontSize)
- _FD = 1000 / GetVal(val_FXFPS)
- _FontFileName = GetVal(val_FontFileName)
- _FaceID = GetVal(val_FaceID)
- _Spacing = GetVal(val_Spacing)
- Font = InitFont(_FontFileName, _FaceID, _Fs, _Spacing, GetVal(val_SpaceScale), 0xFFFFFF, 0, 0)
- FontOut = InitFont(_FontFileName, _FaceID, _Fs, _Spacing, GetVal(val_SpaceScale), 0xFFFFFF, 3, 1)
- FontOut2 = InitFont(_FontFileName, _FaceID, _Fs, _Spacing, GetVal(val_SpaceScale), 0xFFFFFF, 2, 0)
- COLORS = ['000000', '000000', '88AA33', '88AA33', '88AA33', 'C60D65', 'C60D65', 'F17A3A', 'F17A3A']
- IMG_tex1 = Image('images\\blurred_noise.jpg')
- IMG_tex2 = Image('images\\blurred_noise2.jpg')
- IMG_tex3 = Image('images\\blurred_noise3.jpg')
- IMG_tex4 = Image('images\\blurred_noise4.jpg')
- # PIX = pmgToPix(IMG)
- # PIX = PixColorMul(PIX, 1, 1, 1, 1)
- # IMG_tex4 = pmgToImage(PIX)
- IMG_texs = [IMG_tex1, IMG_tex1, IMG_tex2, IMG_tex2, IMG_tex2, IMG_tex3, IMG_tex3, IMG_tex4, IMG_tex4]
- # PIX = BlankPix(60, 60, MakeRGBA(255, 255, 255, 255))
- # IMG_mask = pmgToImage(PIX)
- IMG_mask = Image('images\\radial.jpg')
- # create shaeru's purple magical eye
- img = Image(abspath('images\\purple_eye.jpg'))
- img.filterType(FilterTypes.CubicFilter)
- img.resize('100x100000')
- img.backgroundColor('Transparent')
- IMG = Image(img) # create a mask
- IMG.type(ImageType.GrayscaleType)
- PIX = pmgToPix(IMG)
- PIX_mask = r2a(PIX) # the mask
- PIX = BlankPix(IMG.columns(), IMG.rows(), MakeRGBA(255, 255, 255, 255)) # make the inner white color
- PIX_white = PixMask(PIX, PIX_mask)
- PIX = pmgToPix(img) # the original image
- PIX = PixMask(PIX, PIX_mask) # with the black masked out
- PIX = PixBlur(PIX, 10) # blur it
- PIX = PixColorMul(PIX, 1.2, 1, 1.2, 3.5) # make it more visible
- # PIX = PixColorMul(PIX, 5, 1, 20, 1)
- # PIX = pstSoftGlow(PIX, 10, 180, 160)
- PIX = CombinePixs(PIX, PIX_white)
- IMG = pmgToImage(PIX) # convert to image magick object
- IMG.backgroundColor('Transparent')
- IMG_eye = IMG
- # tc Audio
- tcAudioInit()
- channel = tcAudioOpen('OP.mp3')
- freq = tcAudioGetFreq(channel) # usually 44100 Hz
- avg_bar = 100
- def tcaxPy_Fin():
- tcAudioFin()
- FinFont(Font)
- FinFont(FontOut)
- FinFont(FontOut2)
- # 用户修订版的tcaxPy_Main函数, 保留原始tcaxPy_Main风格是为了减少额外记忆量, 实际上该函数形式可以非常多样化
- def tcaxPy_Main_Fake(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt, param):
- ASS_BUF = [] # 保存ASS特效
- TCAS_BUF = [] # 保存TCAS特效
- ##### 主要特效编写操作 ####
- # if _i == 3:
- # _x = GetVal(val_ResolutionX) - GetVal(val_TextLength)[_i] - GetVal(val_OffsetX) + GetVal(val_TextAdvanceDiff)[_i][_j]
- dx = _x - int((_a + _Spacing) / 2 + 0.5) # 一个固定操作, 将an5的坐标转换为an7
- dy = _y - int(_Fs / 2 + 0.5) # ASS特效默认采用an5坐标, TCAS特效则采用an7坐标
- # 一些时间的计算
- T0 = 10 * _start - 10 * _FD + 2 * _j * _FD
- T1 = T0 + 4 * _FD
- T2 = 10 * _end + 5 * _FD - 2 * (_n - _j - 1) * _FD
- T3 = T2 + _FD * 6
- TS = 10 * _start - 40 * _FD
- TK = 10 * (_start + _elapk)
- TE = 10 * _end + 10 * _FD
- # 文字主体
- PIX = TextPix(Font, _txt)
- IMG = Image(IMG_texs[_i])
- xoff = randint(0, IMG.columns() - PIX[1][0])
- yoff = (randint(0, 54), randint(90, IMG.rows() - PIX[1][1]))[randint(0, 1)]
- IMG.crop(Geometry(PIX[1][0], PIX[1][1], xoff, yoff))
- PIX_tex = pmgToPix(IMG)
- PIX_t = PixTexture(PIX, PIX_tex)
- # 边框主体
- PIX = TextPix(FontOut, _txt)
- PIX = PixColorRGB(PIX, DecRGB(COLORS[_i]))
- PIX = PixColorMul(PIX, 0.7, 0.7, 0.7, 0.8)
- PIX_o = PixBlur(PIX, 8)
- # 混合
- PIX = CombinePixs(PIX_o, PIX_t)
- PIX0 = PIX
-
- # 第一二句效果
- if _i < 2:
- ### 增加到 BIG_PIX 当中, BIG_PIX保存在param的第一个元素处, 关于BIG_PIX用法, 请看专门教程
- BigPixAdd(param[0], PIX0, dx, dy, 0)
- # 表现效果
- num = int(10 * _k / _FD + 0.5) + 1
- total_num = int(10 * (_end - _start) / _FD + 0.5) + leading_frame_count + trailing_frame_count
- for i in range(num):
- faX = i / num
- fa = 1 + 0.5 * faX
- PIX = PixResizeF(PIX0, PIX0[1][0] * fa, 0)
- PIX = BilinearFilter(PIX, dx, dy)
- PIX = PixColorMul(PIX, 200, 1, 150, 0.8 + 0.2 * (num - i) / num)
- PIX = PixBlur(PIX, (i + 1) * 2)
- # 坐标校正
- if _i % 2 == 0: # 第一句向右, 第二句向左移动
- PIX = PixPosShift(PIX, int(10 * _elapk / _FD + 0.5) + leading_frame_count + i, 0)
- else:
- PIX = PixPosShift(PIX, total_num - (int(10 * _elapk / _FD + 0.5) + leading_frame_count + i) - 1, 0)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 2)
- # 附加效果
- num = int(10 * _k / _FD + 0.5) + 10
- start_pic = randint(1, 30)
- for i in range(num):
- ts4 = 10 * (_start + _elapk) + i * _FD
- te4 = ts4 + _FD
- img_path = MakePath(1, i + start_pic, 'images', 'list', 'img', '.png', 'sys')
- PIX = ImagePix(abspath(img_path))
- if i < 5:
- PIX = PixColorMul(PIX, 1, 1, 1, (i + 1) / 5)
- elif i > num - 5:
- PIX = PixColorMul(PIX, 1, 1, 1, (num - i) / 5)
- # 坐标校正
- if _i % 2 == 0: # 第一句向右, 第二句向左移动
- PIX = PixPosShift(PIX, int(10 * _elapk / _FD + 0.5) + leading_frame_count + i, 0)
- else:
- PIX = PixPosShift(PIX, total_num - (int(10 * _elapk / _FD + 0.5) + leading_frame_count + i) - 1, 0)
- tcas_main(TCAS_BUF, PIX, ts4, te4, _x - PIX[1][0] / 2, _y - PIX[1][1] / 2, 0)
-
- # 第三四五句效果
- elif _i < 5:
-
- # 整体模糊
- PIX2 = PixBlur(PIX0, 2)
- ### 增加到 BIG_PIX 当中, BIG_PIX保存在param的第一个元素处, 关于BIG_PIX用法, 请看专门教程
- BigPixAdd(param[0], PIX2, dx, dy, 0)
-
- # 第三句有入场效果, 第五句有出场效果
- # 入场效果
- if _i == 2:
-
- # beat detect, initial beat
- tcAudioSetPos(channel, tcAudioSec2Bytes(channel, (10 * _start - _FD) / 1000))
- fft = tcAudioGetFFT(channel, 2048)
- bar = Spectrum(fft)[1]
- if bar > avg_bar:
- PIX2 = PixBlur(PIX2, sqr(bar / avg_bar))
-
- num = leading_frame_count // 2
- TS = 10 * _start - leading_frame_count * _FD + randint(0, leading_frame_count - num - 1) * _FD
- for i in range(num):
- ts1 = TS + i * _FD
- te1 = ts1 + _FD
- PIX = PixBlur(PIX2, (num - i) * 6)
- PIX = PixResize(PIX, PIX2[1][0], PIX[1][1] * (1 + 2 * (num - i) / num))
- PIX = PixColorMul(PIX, 1, 1, 1, 0.5 + 0.5 * (i + 1) / num)
- tcas_main(TCAS_BUF, PIX, ts1, te1, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX2, te1, 10 * _start, dx, dy, 0)
-
- elif _i == 4:
-
- # beat detect, initial beat
- tcAudioSetPos(channel, tcAudioSec2Bytes(channel, (10 * _end) / 1000))
- fft = tcAudioGetFFT(channel, 2048)
- bar = Spectrum(fft)[1]
- if bar > avg_bar:
- PIX2 = PixBlur(PIX2, sqr(bar / avg_bar))
-
- num = trailing_frame_count // 2
- TS = 10 * _end + randint(1, trailing_frame_count - num) * _FD
- tcas_main(TCAS_BUF, PIX2, 10 * _end, TS, dx, dy, 0)
- for i in range(num):
- ts1 = TS + i * _FD
- te1 = ts1 + _FD
- PIX = PixBlur(PIX2, (i + 1) * 6)
- PIX = PixResize(PIX, PIX2[1][0], PIX[1][1] * (1 + 2 * (i + 1) / num))
- PIX = PixColorMul(PIX, 1, 1, 1, 0.5 + 0.5 * (num - i) / num)
- tcas_main(TCAS_BUF, PIX, ts1, te1, dx, dy, 0)
-
- # 第六七句效果
- elif _i < 7:
- ### 增加到 BIG_PIX 当中, BIG_PIX保存在param的第一个元素处, 关于BIG_PIX用法, 请看专门教程
- BigPixAdd(param[0], PIX0, dx, dy, 0)
-
- # 存在效果
- tcas_main(TCAS_BUF, PIX0, 10 * _start, TK, dx, dy, 0)
-
- # 表现效果
- num = int(10 * _k / _FD + 0.5) + 1
- for i in range(num):
- faX = i / num
- fa = 1 + 0.4 * faX
- PIX = PixResizeF(PIX0, PIX0[1][0] * fa, 0)
- PIX = BilinearFilter(PIX, dx, dy)
- PIX = PixColorMul(PIX, 30, 30, 30, 0.5 + 0.5 * (num - i) / num)
- PIX = PixBlur(PIX, (i + 1) * 2)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 2)
-
- te2 = TK + num / 2 * _FD
-
- xv = [w for w in range(6, PIX0[1][0], 6)]
- yv = [h for h in range(6, PIX0[1][1], 6)]
- PIX_list = PixSubClips(PIX0, xv, yv)
- pix_num = len(PIX_list)
- P = []
- for i in range(pix_num):
- if i % 2 == 0:
- pt0 = (dx, dy)
- pt1 = (dx - 10, dy + 5)
- else:
- pt0 = (dx, dy)
- pt1 = (dx - 10, dy - 5)
- P.append((pt0, pt1))
- # 出场效果
- num = 15
- r1 = [randint(-4, -2), randint(2, 4)][randint(0, 1)]
- for i in range(num):
- for j in range(pix_num):
- ts3 = te2 + i * _FD
- te3 = ts3 + _FD
- x, y, a = LinearBezier(P[j][0], P[j][1], i / num)
- PIX = PixResizeF(PIX_list[j], PIX_list[j][1][0] * (0.6 + 0.4 * (num - i) / num), 0)
- PIX = PixPosShift(PIX, -0.3 * i - 2, r1)
- PIX = BilinearFilter(PIX, x, y)
- PIX = PixBlur(PIX, 1 + 6 * (i + 1) / num)
- PIX = PixColorMul(PIX, 1, 1, 1, 0.8 + 0.2 * (num - i) / num)
- tcas_main(TCAS_BUF, PIX, ts3, te3, x, y, 1)
-
- # 第八句效果
- elif _i < 8:
- ### 增加到 BIG_PIX 当中, BIG_PIX保存在param的第一个元素处, 关于BIG_PIX用法, 请看专门教程
- BigPixAdd(param[0], PIX0, dx, dy, 0)
-
- # 表现效果
- num = int(10 * _k / _FD + 0.5) + 1
- for i in range(num):
- faX = i / num
- fa = 1 + 0.4 * faX
- PIX = PixResizeF(PIX0, PIX0[1][0] * fa, 0)
- PIX = BilinearFilter(PIX, dx, dy)
- PIX = PixColorMul(PIX, 1, 1, 1, 0.7 + 0.3 * (num - i) / num)
- PIX = PixBlur(PIX, (i + 1) * 2)
- PIX = pstSoftGlow(PIX, 10, 160, 140)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 2)
-
- # 附加效果1
- if _j == _n - 1:
- num = int(10 * _k / _FD + 0.5) + 1
- else:
- num = int(10 * max(35, min(_k, 50)) * 2 / _FD + 0.5) + 1
- for i in range(num):
- img = Image(IMG_eye)
- img.rotate(360 * 0.8 * i / num)
- PIX = PixColorMul(pmgToPix(img), 1, 1, 1, linearFactor2(i / num))
- PIX = PixPos(PIX, PIX_t[0][0] + (PIX_t[1][0] - PIX[1][0]) / 2, PIX_t[0][1] + (PIX_t[1][1] - PIX[1][1]) / 2)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
-
- # 附加效果2
- if _j == _n - 1:
- num = 10
- else:
- num = 20
- for i in range(num):
- ts4 = 10 * (_start + _elapk) + i * _FD
- te4 = ts4 + _FD
- img_path = MakePath(3, 2 * i + 20, 'images', 'list', 'img', '.png', 'sys')
- PIX = ImagePix(abspath(img_path))
- if i > num - 12:
- PIX = PixColorMul(PIX, 1, 1, 1, (num - i) / 12)
- tcas_main(TCAS_BUF, PIX, ts4, te4, _x - PIX[1][0] / 2, _y - PIX[1][1] / 2, 0)
-
- # 第九句效果
- elif _i < 9:
-
- dx -= GetVal(val_OffsetX)
- dx += GetVal(val_ResolutionX) - GetVal(val_TextLength)[_i] - GetVal(val_OffsetX)
-
- _x -= GetVal(val_OffsetX)
- _x += GetVal(val_ResolutionX) - GetVal(val_TextLength)[_i] - GetVal(val_OffsetX)
- ### 增加到 BIG_PIX 当中, BIG_PIX保存在param的第一个元素处, 关于BIG_PIX用法, 请看专门教程
- BigPixAdd(param[0], PIX0, dx, dy, 0)
-
- # 表现效果
- if _j == _n - 1:
- num = int(10 * _k / _FD + 0.5) + 1
- else:
- num = int(10 * min(_k, 50) * 2 / _FD + 0.5) + 1
- for i in range(num):
- img = Image(IMG_eye)
- img.rotate(360 * 0.8 * i / num)
- PIX = PixColorMul(pmgToPix(img), 1, 1, 1, linearFactor2(i / num))
- PIX = PixPos(PIX, PIX_t[0][0] + (PIX_t[1][0] - PIX[1][0]) / 2, PIX_t[0][1] + (PIX_t[1][1] - PIX[1][1]) / 2)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
-
- # 表现效果
- # num = int(10 * _k / _FD + 0.5) + 1
- # for i in range(num):
- # faX = i / num
- # fa = 1 + 0.4 * faX
- # PIX = PixResizeF(PIX0, PIX0[1][0] * fa, 0)
- # PIX = BilinearFilter(PIX, dx, dy)
- # PIX = PixColorMul(PIX, 1, 1, 1, 0.5 + 0.5 * (num - i) / num)
- # PIX = PixBlur(PIX, (i + 1) * 2)
- # tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 2)
-
- # 表现效果
- num = int(10 * _k / _FD + 0.5) + 1
- for i in range(num):
- faX = i / num
- fa = 1 + 0.4 * faX
- PIX = PixResizeF(PIX0, PIX0[1][0] * fa, 0)
- PIX = BilinearFilter(PIX, dx, dy)
- PIX = PixColorMul(PIX, 1, 1, 1, 0.7 + 0.3 * (num - i) / num)
- PIX = PixBlur(PIX, (i + 1) * 2)
- PIX = pstSoftGlow(PIX, 10, 160, 140)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 2)
-
- # 附加效果
- if _j == _n - 1:
- num = int(10 * _k / _FD + 0.5) + 1
- else:
- num = int(10 * _k / _FD + 0.5) + 10
- start_pic = randint(1, 30)
- for i in range(num):
- ts4 = 10 * (_start + _elapk) + i * _FD
- te4 = ts4 + _FD
- img_path = MakePath(1, i + start_pic, 'images', 'list', 'img', '.png', 'sys')
- PIX = ImagePix(abspath(img_path))
- if i < 5:
- PIX = PixColorMul(PIX, 1, 1, 1, (i + 1) / 5)
- elif i > num - 5:
- PIX = PixColorMul(PIX, 1, 1, 1, (num - i) / 5)
- tcas_main(TCAS_BUF, PIX, ts4, te4, _x - PIX[1][0] / 2, _y - PIX[1][1] / 2, 0)
-
- # 第x句效果
- else:
- pass
-
- # 将结果返回给tcax进行处理 #####
- return (ASS_BUF, TCAS_BUF)
- def tcaxPy_User():
- file_name = GetVal(val_OutFile) + '.ass'
- ass_header = GetVal(val_AssHeader)
- ASS_FILE = CreateAssFile(file_name, ass_header)
-
- file_name = GetVal(val_OutFile) + '.tcas'
- fx_width = GetVal(val_ResolutionX)
- fx_height = GetVal(val_ResolutionY)
- fx_fps = GetVal(val_FXFPS)
- TCAS_FILE = CreateTcasFile(file_name, fx_width, fx_height, fx_fps)
- # basic metrics
- fontSize = GetVal(val_FontSize)
- marginX = GetVal(val_OffsetX)
- marginY = GetVal(val_OffsetY)
- spacing = GetVal(val_Spacing)
- lineNum = GetVal(val_nLines)
- textNum = GetVal(val_nTexts)
- start = GetVal(val_BegTime)
- end = GetVal(val_EndTime)
- kar = GetVal(val_KarTime)
- elapKar = GetVal(val_KarTimeDiff)
- text = GetVal(val_Text)
- textLength = GetVal(val_TextLength)
- advance = GetVal(val_TextAdvance)
- advDiff = GetVal(val_TextAdvanceDiff)
- # main loop
- for i in range(0, lineNum):
- initPosX = marginX #(fx_width - textLength[i]) / 2 + marginX # if marginX = 0, then it's just on the middle
- initPosY = fx_height - marginY - fontSize
- BIG_PIX = InitBigPix()
- for j in range(textNum[i]):
- if text[i][j] == '' or text[i][j] == ' ' or text[i][j] == ' ':
- continue
- posX = initPosX + advDiff[i][j] + advance[i][j] / 2
- posY = initPosY + fontSize / 2
- param = [BIG_PIX]
- ASS_BUF, TCAS_BUF = tcaxPy_Main_Fake(i, j, textNum[i], start[i], end[i], elapKar[i][j], kar[i][j], posX, posY, advance[i][j], text[i][j], param)
- if len(TCAS_BUF) != 0:
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- if len(ASS_BUF) != 0:
- WriteAssFile(ASS_FILE, ASS_BUF)
- Progress(i, j)
- # 一二句进出场以及显示效果
- if i < 2:
- num = int(10 * (end[i] - start[i]) / _FD + 0.5) + leading_frame_count + trailing_frame_count
- TS = start[i] * 10 - leading_frame_count * _FD
- PIX1 = ConvertBigPix(BIG_PIX)
- blur_flag = False
- counter = 0
- for ii in range(num):
- TCAS_BUF = []
- # position
- if i % 2 == 0: # 第一句向右, 第二句向左移动
- PIX = PixPosShift(PIX1, ii, 0)
- else:
- PIX = PixPosShift(PIX1, num - ii - 1, 0)
- # blur effect
- if ii < 10:
- PIX = PixBlur(PIX, (leading_frame_count - ii) * 4)
- elif ii > num - trailing_frame_count - 1:
- PIX = PixBlur(PIX, (ii - (num - trailing_frame_count - 1)) * 4)
- else:
- m = 2
- if blur_flag:
- PIX = PixBlur(PIX, 2 * fac_func(counter, m))
- counter += 1
- if counter == 2 * m:
- blur_flag = False
- counter = 0
- elif randint(0, 8) == 0:
- blur_flag = True
- tcas_main(TCAS_BUF, PIX, TS + ii * _FD, TS + (ii + 1) * _FD, 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- progress(ii + 1, num)
- # 三四五显示效果
- elif i < 5:
- num = int(10 * (end[i] - start[i]) / _FD + 0.5)
- TS = start[i] * 10
- PIX1 = ConvertBigPix(BIG_PIX)
- for ii in range(num):
- TCAS_BUF = []
- PIX = PIX1
- # beat detect
- tcAudioSetPos(channel, tcAudioSec2Bytes(channel, (TS + ii * _FD) / 1000))
- fft = tcAudioGetFFT(channel, 2048)
- bar = Spectrum(fft)[1]
- #PIX = PixColorMul(PIX, 1, 1, 1, bar / 333)
- #PIX = PixColorRGB(PIX, MakeRGB(bar * 255 / 333, 0, 0))
- if bar > avg_bar:
- PIX = PixBlur(PIX, sqr(bar / avg_bar))
- tcas_main(TCAS_BUF, PIX, TS + ii * _FD, TS + (ii + 1) * _FD, 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- progress(ii + 1, num)
- # 六七显示效果
- elif i < 7:
- # 入场效果
- num = leading_frame_count * 2
- PIX1 = ConvertBigPix(BIG_PIX)
- CANVAS = BlankPix(PIX1[1][0] * 3, PIX1[1][1] * 3, MakeRGBA(0, 0, 0, 0))
- for ii in range(num):
- TCAS_BUF = []
- theta = pi / 2 * (0.5 + 0.5 * (ii + 1) / num)
- #Ay = -12 - 1 * (num - ii)
- Ay = -15 - 1 * (num - ii)
- #orgX = 1.5 * PIX1[1][0] * ii / num
- orgX = 2 * PIX1[1][0] * ii / num
- PIX = PixMap_enlarge(CANVAS, PIX1, page_curl_core_ex, (theta, Ay, orgX))
- PIX = PixPos(PIX, PIX1[0][0] - PIX1[1][0], PIX1[0][1] - PIX1[1][1])
- PIX = PixStrip(PIX)
- blur_val = 2
- if ii > num / 2:
- blur_val = 1
- PIX = PixBlur(PIX, blur_val)
- PIX = PixColorMul(PIX, 1, 1, 1, (ii + 1) / num)
- time_start1 = 10 * start[i] - num * _FD + ii * _FD
- time_end1 = time_start1 + _FD
- tcas_main(TCAS_BUF, PIX, time_start1, time_end1, 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- progress(ii + 1, num)
- # 第八句效果
- elif i < 8:
-
- # 入场效果
- PIX1 = ConvertBigPix(BIG_PIX)
- mask_width = PIX1[1][0] // leading_frame_count
- mask_height = PIX1[1][1]
- num = leading_frame_count
- TS = start[i] * 10 - leading_frame_count * _FD
- for ii in range(num):
- TCAS_BUF = []
- ts1 = TS + ii * _FD
- te1 = ts1 + _FD
- IMG = Image(IMG_mask)
- IMG.filterType(FilterTypes.CubicFilter)
- IMG.resize('!{0}x{1}'.format(mask_width * (ii + 1), mask_height))
- PIX = pmgToPix(IMG)
- PIX = r2a(PIX)
- PIX = invertA(PIX)
- PIX = PixColorMul(PIX, 0, 0, 0, 2)
- PIX = PixPos(PIX, PIX1[0][0] + (PIX1[1][0] - PIX[1][0]) // 2, PIX1[0][1])
- mask = PIX
- PIX = PixMask(PIX1, mask)
- tcas_main(TCAS_BUF, PIX, ts1, te1, 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- progress(ii + 1, num)
-
- # 存在效果
- TCAS_BUF = []
- tcas_main(TCAS_BUF, PIX1, 10 * start[i], 10 * end[i], 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
-
- # 出场效果
- num = trailing_frame_count + 2
- PIX1 = ConvertBigPix(BIG_PIX)
- CANVAS = BlankPix(PIX1[1][0] * 3, PIX1[1][1] * 3, MakeRGBA(0, 0, 0, 0))
- for ii in range(num):
- TCAS_BUF = []
- theta = pi / 2 * (0.5 + 0.5 * (num - ii) / num)
- Ay = -15 - 1 * (ii + 1)
- orgX = 2 * PIX1[1][0] * (num - ii - 1) / num
- PIX = PixMap_enlarge(CANVAS, PIX1, page_curl_core_ex, (theta, Ay, orgX))
- PIX = PixPos(PIX, PIX1[0][0] - PIX1[1][0], PIX1[0][1] - PIX1[1][1])
- PIX = PixStrip(PIX)
- blur_val = 1
- if ii > num / 2:
- blur_val = 2
- PIX = PixBlur(PIX, blur_val)
- PIX = PixColorMul(PIX, 1, 1, 1, (num - ii) / num)
- time_start1 = 10 * end[i] + ii * _FD
- time_end1 = time_start1 + _FD
- tcas_main(TCAS_BUF, PIX, time_start1, time_end1, 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- progress(ii + 1, num)
-
- # 第九句效果
- elif i < 9:
-
- # 入场效果
- num = leading_frame_count * 2
- PIX1 = ConvertBigPix(BIG_PIX)
- CANVAS = BlankPix(PIX1[1][0] * 3, PIX1[1][1] * 3, MakeRGBA(0, 0, 0, 0))
- for ii in range(num):
- TCAS_BUF = []
- theta = pi / 2 * (0.5 + 0.5 * (ii + 1) / num)
- #Ay = -12 - 1 * (num - ii)
- Ay = -15 - 1 * (num - ii)
- #orgX = 1.5 * PIX1[1][0] * ii / num
- orgX = 2 * PIX1[1][0] * ii / num
- PIX = PixMap_enlarge(CANVAS, PIX1, page_curl_core_ex, (theta, Ay, orgX))
- PIX = PixPos(PIX, PIX1[0][0] - PIX1[1][0], PIX1[0][1] - PIX1[1][1])
- PIX = PixStrip(PIX)
- blur_val = 2
- if ii > num / 2:
- blur_val = 1
- PIX = PixBlur(PIX, blur_val)
- PIX = PixColorMul(PIX, 1, 1, 1, (ii + 1) / num)
- time_start1 = 10 * start[i] - num * _FD + ii * _FD
- time_end1 = time_start1 + _FD
- tcas_main(TCAS_BUF, PIX, time_start1, time_end1, 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- progress(ii + 1, num)
-
- # 存在效果
- TCAS_BUF = []
- tcas_main(TCAS_BUF, PIX1, 10 * start[i], 10 * end[i], 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
-
- # 出场效果
- PIX1 = ConvertBigPix(BIG_PIX)
- mask_width = PIX1[1][0] // leading_frame_count
- mask_height = PIX1[1][1]
- num = leading_frame_count
- TS = end[i] * 10
- for ii in range(num):
- TCAS_BUF = []
- ts1 = TS + ii * _FD
- te1 = ts1 + _FD
- IMG = Image(IMG_mask)
- IMG.filterType(FilterTypes.CubicFilter)
- IMG.resize('!{0}x{1}'.format(mask_width * (num - ii), mask_height))
- PIX = pmgToPix(IMG)
- PIX = r2a(PIX)
- PIX = invertA(PIX)
- PIX = PixColorMul(PIX, 0, 0, 0, 2)
- PIX = PixPos(PIX, PIX1[0][0] + (PIX1[1][0] - PIX[1][0]) // 2, PIX1[0][1])
- mask = PIX
- PIX = PixMask(PIX1, mask)
- tcas_main(TCAS_BUF, PIX, ts1, te1, 0, 0, 0)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- progress(ii + 1, num)
-
- # 第x句效果
- else:
- pass
-
- FinTcasFile(ASS_FILE)
- FinTcasFile(TCAS_FILE)
- def sqr(x):
- return x * x
- def fac_func(x, m):
- if x < m:
- return x + 1
- else:
- return 2 * m - x + 1
- def linearFactor2(x):
- if x < 0.5:
- return 1
- else:
- return 1 - 2 * (x - 0.5)
- SPECWIDTH = 368
- SPECHEIGHT = 127
- BANDS = 6
- def Spectrum(fft): # convert fft data to graph
- bars = []
- b0 = 0
- for x in range(BANDS):
- peak = 0 # peak of a certain bar
- b1 = pow(2, x * 10.0 / (BANDS - 1))
- if b1 > 1023:
- b1 = 1023
- if b1 <= b0:
- b1 = b0 + 1 # make sure it uses at least 1 FFT bin
- while b0 < b1:
- if peak < fft[1 + b0]:
- peak = fft[1 + b0]
- b0 += 1
- y = sqrt(peak) * 5 * SPECHEIGHT
- bars.append(y)
- return bars
- # page curl effect
- def page_curl_core_ex(Px, Py, param):
- theta, Ay, orgX = param
- Px -= orgX
- R = sqrt(Px * Px + (Py - Ay) * (Py - Ay))
- alpha = asin(Px / R)
- beta = alpha / sin(theta)
- r = R * sin(theta)
- Tx = r * sin(beta)
- Ty = R + Ay - r * (1 - cos(beta)) * sin(theta)
- Tz = r * (1 - cos(beta)) * cos(theta)
- return (Tx + orgX, Ty, Tz)
- def PixMap_enlarge(PIX_dst, PIX_src, map_func, param):
- buf_dst = list(PIX_dst[2])
- width_dst = PIX_dst[1][0]
- height_dst = PIX_dst[1][1]
-
- buf_src = list(PIX_src[2])
- width_src = PIX_src[1][0]
- height_src = PIX_src[1][1]
-
- for h in range(height_src):
- for w in range(width_src):
- P = map_func(w, h, param)
- x = int(P[0] + 0.5) + width_src
- y = int(P[1] + 0.5) + height_src
- if x in range(width_dst) and y in range(height_dst):
- index_src = 4 * (h * width_src + w)
- index_dst = 4 * (y * width_dst + x)
- buf_dst[index_dst + 0] = buf_src[index_src + 0]
- buf_dst[index_dst + 1] = buf_src[index_src + 1]
- buf_dst[index_dst + 2] = buf_src[index_src + 2]
- buf_dst[index_dst + 3] = buf_src[index_src + 3]
- return (PIX_dst[0], PIX_dst[1], tuple(buf_dst))
- def PixSubClips(PIX, xv, yv):
- PIX_list = []
- xv = list(xv)
- yv = list(yv)
- xv.append(PIX[1][0])
- yv.append(PIX[1][1])
- xv.sort()
- yv.sort()
- xn = len(xv)
- yn = len(yv)
- y_off = 0
- for j in range(yn):
- x_off = 0
- for i in range(xn):
- PIX_sub_pos = (PIX[0][0] + x_off, PIX[0][1] + y_off)
- PIX_sub_res = (xv[i] - x_off, yv[j] - y_off)
- PIX_sub_rgba = []
- for h in range(PIX_sub_res[1]):
- for w in range(PIX_sub_res[0]):
- idx = 4 * ((h + y_off) * PIX[1][0] + w + x_off)
- PIX_sub_rgba.append(PIX[2][idx])
- PIX_sub_rgba.append(PIX[2][idx + 1])
- PIX_sub_rgba.append(PIX[2][idx + 2])
- PIX_sub_rgba.append(PIX[2][idx + 3])
- PIX_list.append((PIX_sub_pos, PIX_sub_res, tuple(PIX_sub_rgba)))
- x_off = xv[i]
- y_off = yv[j]
- return PIX_list
- def r2a(PIX):
- buf = []
- width = PIX[1][0]
- height = PIX[1][1]
- for h in range(height):
- for w in range(width):
- index = 4 * (h * width + w)
- # if PIX[2][index] != PIX[2][index + 1] or PIX[2][index] != PIX[2][index + 2]:
- # print('note1')
- # if PIX[2][index + 3] != 255:
- # print('note2')
- buf.append(0)
- buf.append(0)
- buf.append(0)
- buf.append(PIX[2][index + 0])
- return (PIX[0], PIX[1], tuple(buf))
- def invertA(PIX):
- buf = list(PIX[2])
- width = PIX[1][0]
- height = PIX[1][1]
- for h in range(height):
- for w in range(width):
- index = 4 * (h * width + w) + 3
- buf[index] = 255 - buf[index]
- return (PIX[0], PIX[1], tuple(buf))
复制代码 |
-
2
查看全部评分
-
|