TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua

 找回密码
 新人加入
查看: 25869|回复: 87

[完整特效] [J]040_HorizonII_OP特效脚本 (附完整工程)   [复制链接]

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2012-8-13 20:36:40 |显示全部楼层
完整工程下载(注意, 请直接用浏览器下载):
游客,本帖隐藏的内容需要积分高于 10 才可浏览,您当前积分为 0
  1. from tcaxPy import *
  2. from util.gdiFont import *
  3. from util.tcCurve import *
  4. from util.cairo import *
  5. from pixLibs.ImageStone import *

  6. def tcaxPy_Init():
  7.     global _Fs
  8.     global _FD          # 一帧的持续时间, 约40毫秒
  9.     global Font         # 首要字体
  10.     global FontOut      # 字体边框
  11.     global FontShad      # 加粗字体
  12.     global GdiFontThin
  13.     global GdiFontThin2
  14.     _Fs = GetVal(val_FontSize)
  15.     _FD = 1000 / GetVal(val_FXFPS)
  16.     _FontFileName = GetVal(val_FontFileName)
  17.     _FaceID = GetVal(val_FaceID)
  18.     Font = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(0, 0, 0), 0, False)
  19.     FontOut = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(0, 0, 0), 2, True)
  20.     FontShad = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(0, 0, 0), 4, False)
  21.     GdiFontThin = gfInitFont(GetVal(val_FontFaceName), _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), -3, False)
  22.     GdiFontThin2 = gfInitFont(GetVal(val_FontFaceName), _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), -2, False)
  23.     # cairo
  24.     global surface
  25.     global ctx
  26.     fx_width = GetVal(val_ResolutionX)
  27.     fx_height = GetVal(val_ResolutionY)
  28.     width = fx_width
  29.     height = fx_height
  30.     surface = ImageSurface(FORMAT_ARGB32, width, height)
  31.     ctx = Context(surface)

  32. def tcaxPy_Fin():
  33.     FinFont(Font)
  34.     FinFont(FontOut)
  35.     FinFont(FontShad)
  36.     gfFinFont(GdiFontThin)
  37.     gfFinFont(GdiFontThin2)
  38.     #sys.exit()      # 自动关闭执行窗口 auto close the window

  39. def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
  40.     ASS_BUF  = []        # 保存ASS特效
  41.     TCAS_BUF = []        # 保存TCAS特效
  42.     ##### 主要特效编写操作 ####
  43.     dx = _x - int((_a + GetVal(val_Spacing)) / 2 + 0.5)     # 一个固定操作, 将an5的坐标转换为an7
  44.     dy = _y - int(_Fs / 2 + 0.5)    # ASS特效默认采用an5坐标, TCAS特效则采用an7坐标
  45.     # 文字主体
  46.     PIX = TextPix(Font, _txt)
  47.     PIX_t0 = PixColorRGB(PIX, DecRGB('FFFFFF'))     # 未增加内部填充
  48.     if _txt == '/' or _txt == '「' or _txt == '」':
  49.         PIX = PixFromPoints(gfGetPoints(GdiFontThin2, _txt))
  50.         PIX = PixColorRGB(PIX, DecRGB('002200'))
  51.         PIX_thin = PixBlur(PIX, 2)      # 内部填充
  52.         PIX_t = CombinePixs(PIX_t0, PIX_thin)    # 增加了内部填充的主体
  53.     else:
  54.         PIX = PixFromPoints(gfGetPoints(GdiFontThin, _txt))
  55.         PIX = PixColorRGB(PIX, DecRGB('002200'))
  56.         PIX_thin = PixBlur(PIX, 4)      # 内部填充
  57.         PIX_t = CombinePixs(PIX_t0, PIX_thin)    # 增加了内部填充的主体
  58.     # 边框
  59.     PIX = TextPix(FontOut, _txt)
  60.     PIX = PixColorRGB(PIX, DecRGB('FFFFFF'))
  61.     PIX_o = PixBlur(PIX, 6)
  62.     # 底色
  63.     PIX = TextPix(FontShad, _txt)
  64.     PIX = PixColorRGB(PIX, DecRGB('0042CA'))
  65.     PIX_s = PixBlur(PIX, 8)
  66.     # 混合
  67.     PIX = CombinePixs(PIX_s, PIX_o)
  68.     PIX_0 = CombinePixs(PIX, PIX_t0)
  69.     PIX_1 = CombinePixs(PIX, PIX_t)
  70.     # 一些时间的计算
  71.     T0 = 10 * _start - 12 * _FD + 1 * _j * _FD
  72.     T1 = T0 + 4 * _FD
  73.     T2 = 10 * _end + 4 * _FD - 1 * (_n - _j - 1) * _FD
  74.     T3 = T2 + 8 * _FD
  75.     # IN 入场方式
  76.     xv = [w for w in range(6, PIX_1[1][0], 6)]
  77.     yv = [h for h in range(6, PIX_1[1][1], 6)]
  78.     PIX_list = PixSubClips(PIX_1, xv, yv)
  79.     pix_num = len(PIX_list)
  80.     P = []
  81.     pix_num = len(PIX_list)
  82.     for i in range(pix_num):
  83.         if i % 2 == 0:
  84.             pt0 = (dx + 10, dy - 5)
  85.             pt1 = (dx, dy)
  86.         else:
  87.             pt0 = (dx + 10, dy + 5)
  88.             pt1 = (dx, dy)
  89.         P.append((pt0, pt1))
  90.     num = 10
  91.     for i in range(num):
  92.         for j in range(pix_num):
  93.             ts0 = T0 + i * _FD
  94.             te0 = ts0 + _FD
  95.             x, y, a = LinearBezier(P[j][0], P[j][1], (i + 1) / num)
  96.             PIX = PixResizeF(PIX_list[j], PIX_list[j][1][0] * (i + 1) / num, 0)
  97.             if num - i - 1 > 0:
  98.                 PIX = PixBlur(PIX, 2 * (num - i - 1))
  99.             PIX = BilinearFilter(PIX, x, y)
  100.             tcas_main(TCAS_BUF, PIX, ts0, te0, x, y, 0)
  101.     # MAIN 存在方式 part1
  102.     ts1 = te0
  103.     te1 = 10 * (_start + _elapk)
  104.     tcas_main(TCAS_BUF, PIX_1, ts1, te1, dx, dy, 0)
  105.     # EFT 表现方式 MAIN 存在方式 part2
  106.     ts2 = te1
  107.     te2 = T2
  108.     PIX = pstSoftGlow(PIX_1, 10, 100, 120)
  109.     tcas_keyframe(TCAS_BUF, PIX, PIX_1, ts2, te2, dx, dy, 1, 0)
  110.     # EXT 附加效果
  111.     points = PixPoints(PIX_thin)
  112.     pt_num = len(points)
  113.     dx0 = dx + PIX_thin[0][0]
  114.     dy0 = dy + PIX_thin[0][1]
  115.     num = int((te2 - te1) / _FD + 0.5)
  116.     for i in range(num):        # 逐帧绘制
  117.         ts = te1 + _FD * i
  118.         te = ts + _FD
  119.         for j in range(pt_num):
  120.             ctx.save()
  121.             y = dy0 + points[j][1]
  122.             if y < _y:
  123.                 ag = (y - _y - 5) / PIX_thin[1][1] * pi / 4
  124.             else:
  125.                 ag = (y - _y + 5) / PIX_thin[1][1] * pi / 4
  126.             ctx.translate(dx0 + points[j][0], dy0 + points[j][1])
  127.             ctx.scale(1/8, 1/8)
  128.             AssDraw(ctx, DrawLight2(160))
  129.             path_trans(ctx, ca_frz, -ag)
  130.             path_trans(ctx, ca_fry, pi * i / num)
  131.             ctx.set_source_rgba(0xFF/0xFF, 0x88/0xFF, 0x68/0xFF, 0x0A/0xFF)
  132.             ctx.fill()
  133.             AssDraw(ctx, DrawLight3(40))
  134.             path_trans(ctx, ca_frz, -ag)
  135.             path_trans(ctx, ca_fry, pi * i / num)
  136.             ctx.set_source_rgba(1, 1, 1, 0.2)
  137.             ctx.fill()
  138.             ctx.restore()
  139.         PIX = surface.get_pix()     # 获取图案
  140.         surface_clear(ctx)          # 清空画布
  141.         PIX = PixStrip(PIX)         # 裁剪空白边框提升后续操作效率
  142.         PIX = PixBlur(PIX, 1)       # 模糊效果
  143.         if i > num - 5:
  144.             PIX = PixColorMul(PIX, 1, 1, 1, (num - i) / 5)
  145.         tcas_main(TCAS_BUF, PIX, ts, te, 0, 0, 1)
  146.         progress(i + 1, num)
  147.     # OUT 出场方式
  148.     P = []
  149.     pix_num = len(PIX_list)
  150.     for i in range(pix_num):
  151.         if i % 2 == 0:
  152.             pt0 = (dx, dy)
  153.             pt1 = (dx - 10, dy + 5)
  154.         else:
  155.             pt0 = (dx, dy)
  156.             pt1 = (dx - 10, dy - 5)
  157.         P.append((pt0, pt1))
  158.     num = 10
  159.     for i in range(num):
  160.         for j in range(pix_num):
  161.             ts3 = te2 + i * _FD
  162.             te3 = ts3 + _FD
  163.             x, y, a = LinearBezier(P[j][0], P[j][1], i / num)
  164.             PIX = PixResizeF(PIX_list[j], PIX_list[j][1][0] * (num - i) / num, 0)
  165.             if i > 0:
  166.                 PIX = PixBlur(PIX, 2 * i)
  167.             PIX = BilinearFilter(PIX, x, y)
  168.             tcas_main(TCAS_BUF, PIX, ts3, te3, x, y, 0)
  169.     ##### 将结果返回给tcax进行处理 #####
  170.     return (ASS_BUF, TCAS_BUF)


  171. # 辅助函数
  172. def PixSubClips(PIX, xv, yv):
  173.     PIX_list = []
  174.     xv = list(xv)
  175.     yv = list(yv)
  176.     xv.append(PIX[1][0])
  177.     yv.append(PIX[1][1])
  178.     xv.sort()
  179.     yv.sort()
  180.     xn = len(xv)
  181.     yn = len(yv)
  182.     y_off = 0
  183.     for j in range(yn):
  184.         x_off = 0
  185.         for i in range(xn):
  186.             PIX_sub_pos = (PIX[0][0] + x_off, PIX[0][1] + y_off)
  187.             PIX_sub_res = (xv[i] - x_off, yv[j] - y_off)
  188.             PIX_sub_rgba = []
  189.             for h in range(PIX_sub_res[1]):
  190.                 for w in range(PIX_sub_res[0]):
  191.                     idx = 4 * ((h + y_off) * PIX[1][0] + w + x_off)
  192.                     PIX_sub_rgba.append(PIX[2][idx])
  193.                     PIX_sub_rgba.append(PIX[2][idx + 1])
  194.                     PIX_sub_rgba.append(PIX[2][idx + 2])
  195.                     PIX_sub_rgba.append(PIX[2][idx + 3])
  196.             PIX_list.append((PIX_sub_pos, PIX_sub_res, tuple(PIX_sub_rgba)))
  197.             x_off = xv[i]
  198.         y_off = yv[j]
  199.     return PIX_list

  200. def DrawLight2(l):
  201.     return 'm 0 0 l -{length} 0 0 8 c'.format(length = int(l * 8))

  202. def DrawLight3(l):
  203.     return 'm 0 0 l -{length} 0 0 4 c'.format(length = int(l * 8))
复制代码
2

查看全部评分

Rank: 4

发表于 2012-8-13 21:47:43 |显示全部楼层
辛苦了 感谢分享

Moderator

疯子

Rank: 5Rank: 5

发表于 2012-8-13 22:08:25 |显示全部楼层
已经整40个了

Rank: 4

发表于 2012-8-14 00:23:59 |显示全部楼层
shine 嗯 shine  sunshine

Rank: 5Rank: 5

发表于 2012-8-14 02:46:59 |显示全部楼层
奶大高效率啊...

Rank: 4

发表于 2012-8-14 02:58:13 |显示全部楼层
辛苦了

Rank: 4

发表于 2012-8-14 20:24:36 |显示全部楼层
支持一下 顺便学习

Rank: 4

发表于 2012-8-18 22:50:48 |显示全部楼层
学习学习~~~

Rank: 4

发表于 2012-8-19 10:03:30 |显示全部楼层
奶大好厉害啊

Rank: 4

发表于 2012-8-22 23:07:00 |显示全部楼层
好强大,回复看看

Rank: 4

发表于 2012-8-23 16:26:14 |显示全部楼层
好巨大的tcas字幕文件,500m
捕获.JPG
1

查看全部评分

Rank: 1

发表于 2012-8-27 14:37:33 |显示全部楼层
分不够 杯具啊

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2012-8-27 21:35:53 |显示全部楼层
coo 发表于 2012-8-27 14:37
分不够 杯具啊

10分很快的, 去水几帖就到了

Rank: 1

发表于 2012-10-30 18:39:03 |显示全部楼层

Rank: 1

发表于 2012-10-30 18:40:12 |显示全部楼层
望楼主体谅

Rank: 1

发表于 2012-10-30 18:40:18 |显示全部楼层
好了

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2012-10-30 21:59:06 |显示全部楼层
zhore 发表于 2012-10-30 18:40
好了

分不够可以去水区嘛...

下回别怪我手滑..

Rank: 4

发表于 2012-11-14 00:04:20 |显示全部楼层
好好学习,天天向上
1

查看全部评分

Rank: 4

发表于 2012-11-17 17:02:50 |显示全部楼层
刚刚接触制作特效字幕,还是小白,很多都不太懂,但是要支持楼主!

Rank: 4

发表于 2012-12-7 12:27:04 |显示全部楼层
奶大的新工程啊!!不过感觉工程文件好庞大的说!!
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-3-29 14:38

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH