- UID
- 2
- 积分
- 8682
- 帖子
- 2905
- 主题
- 199
- 论坛币
- 11739
- 威望
- 16
- EP值
- 2349
- MP值
- 15
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 2597 小时
- 最后登录
- 2024-8-28
|
说明, 如果要直接执行本脚本, 请升级TCAX到最新版 (1.1.8), 附件为完整工程
说明2, 本特效用到的一些效果会陆续写成教程...
其一, TCAS fade流- from tcaxPy import *
- from util.magick 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_tex # 主要纹理
- _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', '00BB00', 'FF0000', '00AA00', '0000FF', 'FFFF00', 'FF0000', '00FFFF', 'FFFFFF']
- IMG_tex = Image('images\\blood.jpg')
- def tcaxPy_Fin():
- 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坐标
- # 文字主体
- PIX = TextPix(Font, _txt)
- IMG = Image(IMG_tex)
- 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, 1, 1, 1, 0.8)
- PIX_o = PixBlur(PIX, 6)
- # 边框
- PIX = TextPix(FontOut2, _txt)
- PIX = PixColorRGB(PIX, DecRGB('0000BB'))
- PIX_b = PixBlur(PIX, 2)
- # 混合
- PIX = CombinePixs(PIX_o, PIX_b)
- PIX = CombinePixs(PIX, PIX_t)
- PIX0 = PIX
- # 一些时间的计算
- 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
- # 第一句效果
- if _i == 0:
- IMG = Image(IMG_tex)
- IMG.type(ImageType.GrayscaleType)
- IMG.filterType(FilterTypes.CubicFilter)
- IMG.resize('!{0}x{1}'.format(PIX0[1][0], PIX0[1][1]))
- PIX = pmgToPix(IMG)
- PIX = PixColorMul(PIX, 2, 1, 1, 1)
- PIX = PixPos(PIX, PIX0[0][0], PIX0[0][1])
- PIX = r2a(PIX)
- mask0 = invertA(PIX)
- num = int(10 * _k / _FD + 0.5) + 10
- for i in range(num):
- mask = addA(mask0, 255 * i / num)
- PIX = PixMask(PIX0, mask)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX0, TK + num * _FD, TE, dx, dy, 0)
- IMG = Image('images\\blurred_noise.jpg')
- xoff = randint(0, IMG.columns() - PIX0[1][0])
- yoff = randint(0, IMG.rows() - PIX0[1][1])
- IMG.crop(Geometry(PIX0[1][0], PIX0[1][1], xoff, yoff))
- PIX = pmgToPix(IMG)
- PIX = PixPos(PIX, PIX0[0][0], PIX0[0][1])
- PIX = r2a(PIX)
- mask0 = invertA(PIX)
- num = 40
- for i in range(num):
- mask = addA(mask0, 255 * (num - 2 * i) / num)
- PIX = PixMask(PIX0, mask)
- tcas_main(TCAS_BUF, PIX, TE + i * _FD, TE + (i + 1) * _FD, dx, dy, 0)
- # 第二句效果
- elif _i == 1:
- IMG = Image('images\\blurred_noise.jpg')
- xoff = randint(0, IMG.columns() - PIX0[1][0])
- yoff = randint(0, IMG.rows() - PIX0[1][1])
- IMG.crop(Geometry(PIX0[1][0], PIX0[1][1], xoff, yoff))
- PIX = pmgToPix(IMG)
- PIX = PixPos(PIX, PIX0[0][0], PIX0[0][1])
- PIX = r2a(PIX)
- mask0 = invertA(PIX)
- num = 40
- for i in range(num):
- mask = addA(mask0, 255 * (2 * i - num) / num)
- PIX = PixMask(PIX0, mask)
- tcas_main(TCAS_BUF, PIX, TS + i * _FD, TS + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX0, TS + num * _FD, TK, dx, dy, 0)
-
- PIX = PixBlur(PIX_t, 9) # 8, 11
- tcas_keyframe(TCAS_BUF, PIX0, PIX, TK, TK + 10 * _k + 4 * _FD, dx, dy, 2, 0)
- tcas_keyframe(TCAS_BUF, PIX, PixColorMul(PIX, 1, 1, 1, 0), TK + 10 * _k + 4 * _FD, T3, dx, dy, 1, 0)
- # 第三句效果
- elif _i == 2:
- IMG = Image(IMG_tex)
- IMG.type(ImageType.GrayscaleType)
- IMG.filterType(FilterTypes.CubicFilter)
- IMG.resize('!{0}x{1}'.format(PIX0[1][0], PIX0[1][1]))
- PIX = pmgToPix(IMG)
- PIX = PixColorMul(PIX, 4, 1, 1, 1)
- PIX = PixPos(PIX, PIX0[0][0], PIX0[0][1])
- PIX = r2a(PIX)
- mask0 = invertA(PIX)
- num = int(10 * _k / _FD + 0.5) + 10
- for i in range(num):
- mask = addA(mask0, 255 * i / num)
- PIX = PixMask(PIX0, mask)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX0, TK + num * _FD, T2, dx, dy, 0)
- IMG = Image('images\\noise.jpg')
- xoff = randint(0, IMG.columns() - PIX0[1][0])
- yoff = randint(0, IMG.rows() - PIX0[1][1])
- IMG.crop(Geometry(PIX0[1][0], PIX0[1][1], xoff, yoff))
- PIX = pmgToPix(IMG)
- PIX = PixColorMul(PIX, 3, 1, 1, 1)
- PIX = PixPos(PIX, PIX0[0][0], PIX0[0][1])
- PIX = r2a(PIX)
- mask0 = invertA(PIX)
- num = 40
- for i in range(num):
- mask = addA(mask0, 255 * (num - 2 * i) / num)
- PIX = PixMask(PIX0, mask)
- tcas_main(TCAS_BUF, PIX, T2 + i * _FD, T2 + (i + 1) * _FD, dx, dy, 0)
- # 第四五句效果
- elif _i == 3 or _i == 4:
- IMG = Image('images\\radial.jpg')
- IMG.filterType(FilterTypes.CubicFilter)
- IMG.resize('!{0}x{1}'.format(PIX0[1][0], PIX0[1][1]))
- PIX = pmgToPix(IMG)
- PIX = PixColorMul(PIX, 2, 1, 1, 1)
- PIX = PixPos(PIX, PIX0[0][0], PIX0[0][1])
- PIX = r2a(PIX)
- if _i == 3:
- mask0 = PIX
- else:
- mask0 = invertA(PIX)
- num = int(10 * _k / _FD + 0.5) + 4
- for i in range(num):
- mask = addA(mask0, 255 * (2 * i - num) / num)
- PIX = PixMask(PIX0, mask)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX0, TK + num * _FD, T2, dx, dy, 0)
- num = 10
- for i in range(num):
- mask = addA(mask0, 255 * (num - 2 * i) / num)
- PIX = PixMask(PIX0, mask)
- tcas_main(TCAS_BUF, PIX, T2 + i * _FD, T2 + (i + 1) * _FD, dx, dy, 0)
- # 第六句效果
- elif _i == 5:
- ### 增加到 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)
- PIX2 = CombinePixs(PIX_o, PIX_b)
- num = int(10 * _k / _FD + 0.5) + 10
- for i in range(num):
- IMG = Image(IMG_tex)
- IMG.rotate(360 * 1.5 * i / num)
- PIX = pmgToPix(IMG)
- 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)
- PIX = PixMask(PIX, PIX_t)
- PIX = PixStrip(PIX)
- PIX = CombinePixs(PIX2, PIX) # crash on '合' if without PixStrip, need a bug-fix, fixed in the latest tcaxLib.pyd, but PixStrip is still preferred due to performance issue
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX, TK + num * _FD, T2, dx, dy, 0)
- PIX3 = PIX
- num = 6
- for i in range(num):
- IMG = pmgToImage(PIX3)
- IMG.motionBlur(0, 6 * i, 90)
- PIX = PixPos(pmgToPix(IMG), PIX3[0][0], PIX3[0][1])
- PIX = PixColorMul(PIX, 1, 1, 1, 0.5 + 0.5 * (num - i) / num)
- tcas_main(TCAS_BUF, PIX, T2 + i * _FD, T2 + (i + 1) * _FD, dx, dy, 0)
- # 第七句效果
- elif _i == 6:
- num = 6
- for i in range(num):
- IMG = pmgToImage(PIX0)
- IMG.channel(ChannelType.MatteChannel)
- IMG.motionBlur(0, 6 * (num - i), -90)
- PIX = PixPos(pmgToPix(IMG), PIX0[0][0], PIX0[0][1])
- PIX = PixColorMul(PIX, 1, 1, 1, 0.6 + 0.4 * i / num)
- tcas_main(TCAS_BUF, PIX, T0 + i * _FD, T0 + (i + 1) * _FD, dx, dy, 0)
- TM0 = T0 + num * _FD
- TM1 = TM0 + 6 * _FD
- tcas_keyframe(TCAS_BUF, PIX, PIX0, TM0, TM1, dx, dy, 1, 0)
- tcas_main(TCAS_BUF, PIX0, TM1, TK, dx, dy, 0)
- num = int(10 * _k / _FD + 0.5) + 4
- for i in range(num):
- fa = i
- if fa > num // 2:
- fa = num - i
- if randint(0, 2) == 0:
- PIX = pstEffect(PIX0, 22, 1 + 1.2 * fa)
- else:
- PIX = pstEffect(PIX0, 25, 1 + 1.2 * fa)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX0, TK + num * _FD, T2, dx, dy, 0)
- tcas_keyframe(TCAS_BUF, PIX0, PixColorMul(PixBlur(PIX, 12), 1, 1, 1, 0.4), T2, T3, dx, dy, 1, 0)
- # 第八句效果
- elif _i == 7:
- if _k < 200:
- num = int(10 * _k / _FD + 0.5) + 1
- for i in range(num):
- faX = i / num
- if faX < 2 / 3:
- fa = 0.8 + 0.6 * faX
- else:
- fa = 1.6 - 0.6 * faX
- PIX = PixResizeF(PIX0, PIX0[1][0] * fa, 0)
- PIX = BilinearFilter(PIX, dx, dy)
- PIX = PixColorMul(PIX, 1, 1, 1, 0.6 + 0.4 * i / num)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX0, TK + num * _FD, T2, dx, dy, 0)
- PIX = PIX0
- else: # {\K205}だ
- PIX2 = CombinePixs(PIX_o, PIX_b)
- num = int(10 * _k / _FD + 0.5) - 2
- for i in range(num):
- IMG = Image(IMG_tex)
- IMG.rotate(360 * 1.5 * i / num)
- PIX = pmgToPix(IMG)
- 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)
- PIX = PixMask(PIX, PIX_t)
- PIX = PixStrip(PIX)
- PIX3 = CombinePixs(PIX2, PIX)
- fa = 1 + 0.4 * (num - i) / num
- PIX = PixResizeF(PIX3, PIX3[1][0] * fa, 0)
- PIX = BilinearFilter(PIX, dx, dy)
- PIX = PixColorMul(PIX, 1, 1, 1, 0.6 + 0.4 * i / num)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX, TK + num * _FD, T2, dx, dy, 0)
- tcas_keyframe(TCAS_BUF, PIX, PixPosShift(PixColorMul(PIX, 0, 0, 0, 0), 0, 50), T2, T3, dx, dy, 2, 0)
- # 第九句效果
- elif _i == 8:
- ### 增加到 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)
- # IMG = Image('400x60', 'black')
- # IMG.backgroundColor('black')
- # IMG.fillColor('white')
- # IMG.draw(DrawableRectangle(0, 28, 400, 32))
- # IMG.wave(2, 100)
- # IMG.randomThreshold('40%x60%')
- # IMG.blur(0, 4)
- # IMG.write('stroke.jpg')
- IMG = Image('images\\stroke.jpg')
- IMG.filterType(FilterTypes.CubicFilter)
- IMG.resize('!{0}x{1}'.format(PIX0[1][0], PIX0[1][1]))
- PIX_black = BlankPix(PIX0[1][0], PIX0[1][1], MakeRGBA(0, 0, 0, 255))
- num = int(10 * _k / _FD + 0.5)
- for i in range(num):
- img = Image(IMG)
- img.crop(Geometry(int(PIX0[1][0] * (i + 1) / num + 0.5) + 1, PIX0[1][1], 0, 0))
- PIX = pmgToPix(img)
- PIX = CombinePixs(PIX_black, PIX)
- PIX = PixPos(PIX, PIX0[0][0], PIX0[0][1])
- PIX = r2a(PIX)
- mask = invertA(PIX)
- PIX = PixMask(PIX0, mask)
- tcas_main(TCAS_BUF, PIX, TK + i * _FD, TK + (i + 1) * _FD, dx, dy, 0)
- tcas_main(TCAS_BUF, PIX, TK + num * _FD, 10 * _end, dx, dy, 0)
- PIX2 = PIX
- IMG.blur(0, 8)
- PIX = pmgToPix(IMG)
- PIX = PixColorMul(PIX, 2, 1, 1, 1)
- PIX = PixPos(PIX, PIX0[0][0], PIX0[0][1])
- PIX = r2a(PIX)
- mask0 = invertA(PIX)
- num = 30
- for i in range(num):
- mask = addA(mask0, 255 * (num - 2 * i) / num)
- PIX = PixMask(PIX2, mask)
- tcas_main(TCAS_BUF, PIX, 10 * _end + i * _FD, 10 * _end + (i + 1) * _FD, dx, dy, 0)
- # 将结果返回给tcax进行处理 #####
- return (ASS_BUF, TCAS_BUF)
- def tcaxPy_User():
- 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(lineNum):
- initPosX = marginX #(fx_width - textLength[i]) / 2 + marginX # if marginX = 0, then it's just on the middle
- initPosY = marginY
- 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)
- Progress(i, j)
- if i == 5:
- num = 20
- PIX1 = ConvertBigPix(BIG_PIX)
- TCAS_BUF = []
- tcas_main(TCAS_BUF, PIX1, start[i] * 10 - num * _FD, start[i] * 10, 0, 0, 1)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- mask = PIX1
- PIX = CombinePixs(ImagePix('images\\flare3.png'), switchRB(ImagePix('images\\flare1.png')))
- #SavePix('f.png', PIX)
- PIX = PixStrip(PIX)
- PIX2 = PixResize(PIX, PIX1[1][0], PIX1[1][1])
- for l in range(num):
- TCAS_BUF = []
- PIX = PixPos(PIX2, PIX1[0][0] + PIX1[1][0] * (l - num / 2) / num, PIX1[0][1])
- PIX = PixMask(PIX, mask)
- tcas_main(TCAS_BUF, PIX, start[i] * 10 - num * _FD + l * _FD, start[i] * 10 - num * _FD + (l + 1) * _FD, 0, 0, 1)
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- #progress(l + 1, num)
- elif i == 8:
- num = 40
- PIX1 = ConvertBigPix(BIG_PIX)
- IMG = Image(Geometry(PIX1[1][1], PIX1[1][0]), 'transparent')
- IMG.read('gradient:black-white')
- IMG.rotate(90)
- IMG.type(ImageType.GrayscaleType)
- IMG2 = Image(IMG)
- IMG.randomThreshold('0x100%')
- IMG.type(ImageType.GrayscaleType)
- PIX = pmgToPix(IMG2)
- PIX = r2a(PIX)
- mask = invertA(PIX)
- PIX = PixMask(pmgToPix(IMG), mask)
- #SavePix('gradient_noise.png', PIX)
- PIX = PixPos(PIX, PIX1[0][0], PIX1[0][1])
- mask0 = r2a(PIX)
- for l in range(num):
- TCAS_BUF = []
- mask = addA(mask0, 255 * (2 * l - num) / num)
- PIX = PixMask(PIX1, mask)
- tcas_main(TCAS_BUF, PIX, start[i] * 10 - num * _FD + l * _FD, start[i] * 10 - num * _FD + (l + 1) * _FD, 0, 0, 1)
- if len(TCAS_BUF) > 0:
- WriteTcasFile(TCAS_FILE, TCAS_BUF)
- #progress(l + 1, num)
- FinTcasFile(TCAS_FILE)
- 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))
- def addA(PIX, step):
- 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] += int(step + 0.5)
- if buf[index] < 0:
- buf[index] = 0
- if buf[index] > 255:
- buf[index] = 255
- return (PIX[0], PIX[1], tuple(buf))
- def switchRB(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)
- temp = buf[index]
- buf[index] = buf[index + 2]
- buf[index + 2] = temp
- return (PIX[0], PIX[1], tuple(buf))
复制代码 |
-
2
查看全部评分
-
|