- UID
- 2443
- 积分
- 1311
- 帖子
- 78
- 主题
- 21
- 论坛币
- 909
- 威望
- 8
- EP值
- 449
- MP值
- 0
- 阅读权限
- 100
- 注册时间
- 2015-3-7
- 在线时间
- 121 小时
- 最后登录
- 2018-7-21
|
本帖最后由 面麻 于 2015-9-11 17:54 编辑
说明:这是milk前辈从X大写的效果移植过来的,用了种子填充算法,正好应Alex的要求。
具体见脚本,就不解释了(我也还没看)。
用TCAS生成了,渲染效率高点。
附上工程,可以 prase 看看。附件去掉了片源和字体,体积太大就不放了。
munto_ed_shanzhai_temp.zip
(8.45 KB, 下载次数: 2902)
如果有疑问,直接跟帖。- ##### 基本函数库, 必须包含 #####
- from tcaxPy import *
- ##### 额外的一些库 #####
- from collections import deque
- def RandomDouble_Gauss(l, h):
- return RandomDouble_Gauss_(l, h, 6)
- def RandomDouble_Gauss_(l, h, g):
- sum = 0
- for i in range(g):
- sum += RandomDouble(l, h)
- return sum / g
- def RandomDouble(l, h):
- return l + (h - l) * random()
- ##### 初始化函数, 用于设定一些全局变量 #####
- def tcaxPy_Init():
- ##### 声明全局变量 #####
- global _FontFileName # 字体文件名
- global _FaceID # 字体Face序号
- global _Fs # 字体大小
- global _TextWidth # 文字宽度
- global _TextHeight # 文字高度
- global _TextLength
- global _TextAdvDiff
- global _ResolutionX
- global _OffsetX
- global _FD # 一帧的持续时间, 40毫秒
- global Font # 首要字体
- global FontOut # 字体边框
- ##### 获取预定义的值 #####
- _FontFileName = GetVal(val_FontFileName)
- _FaceID = GetVal(val_FaceID)
- _Fs = GetVal(val_FontSize)
- _TextHeight = GetVal(val_TextHeight)
- _TextWidth = GetVal(val_TextWidth)
- _TextLength = GetVal(val_TextLength)
- _TextAdvDiff = GetVal(val_TextAdvanceDiff)
- _ResolutionX = GetVal(val_ResolutionX)
- _OffsetX = GetVal(val_OffsetX)
- _FD = 1000 / GetVal(val_FXFPS)
- ##### 设置自定义变量的值 #####
- Font = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0xFFFFFF, 0, 0) # 0xFFFFFF为16进制表示的白色
- FontOut = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0xFFFFFF, 4, 1) # 最后一个参数置为1表示只提取边框
- ##### 结束函数, 用于一些收尾工作 #####
- def tcaxPy_Fin():
- ##### 清理一些全局变量 #####
- FinFont(Font)
- FinFont(FontOut)
- ##### 脚本主函数, 会对每个文字执行一次 #####
- # _i 第_i句, 即当前操作的文字所在的句子序号
- # _j 第_i句中的第_j个文字, 即当前操作文字的序号
- # _n 第_i句中有_n个文字, 即当前句子所包含的文字数
- # _start 句子的开始时间
- # _end 句子的结束时间
- # _elapk 到第_j个字经过的时间, _start + _elapk 到 _start + _elapk + _k 即为当前文字的存在时间
- # _k 第_j个文字的卡拉OK时间
- # _x 第_j个文字的水平坐标
- # _y 第_j个文字的垂直坐标
- # _a 第_j个文字的水平跨距, 可以看作文字的宽度, 同样_Fs也可近似看成文字的高度
- # _txt 第_j个文字的内容
- def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
- ASS_BUF = [] # 保存ASS特效
- TCAS_BUF = [] # 保存TCAS特效
- ##### 主要特效编写操作 #####
- if _i > 2 and _i % 2 == 1:
- _x = _ResolutionX - _TextLength[_i] - _OffsetX + _TextAdvDiff[_i][_j]
- t0 = _start - 60 + 5 * _j
- t1 = t0 + 40
- t2 = _end + 60 + 5 * _j
- t3 = t2 + 40
- for i in range(1, 5):
- ass_main(ASS_BUF, SubL(t0 + 3 * i, t1 + 3 * i), \
- mov(_x + 30, _y - 30, _x, _y) + alpha1(255) + blur(2) + \
- fad(20 * (t1 - t0), 0) + fry(-180) + \
- animation1(0, 10 * (t1 - t0), fry(0)), _txt)
- ass_main(ASS_BUF, SubL(t0, t1), \
- mov(_x + 30, _y - 30, _x, _y) + alpha1(255) + blur(2) + \
- fad(10 * (t1 - t0), 0) + fry(-180) + \
- animation1(0, 10 * (t1 - t0), fry(0)), _txt)
- ass_main(ASS_BUF, SubL(_start + _elapk, t2), \
- pos(_x + 1, _y + 1) + alpha1(255) + alpha3(119) + color3('000000') + \
- bord(8) + blur(8) + fad(20, 20), _txt)
- ass_main(ASS_BUF, SubL(t1, t2), \
- pos(_x, _y) + alpha1(255) + blur(2), _txt)
- ass_main(ASS_BUF, SubL(t0, t1), \
- mov(_x + 31, _y - 29, _x + 1, _y + 1) + alpha1(255) + alpha3(119) + color3('000000') + \
- bord(8) + blur(8) + fad(10 * (t1 - t0), 0) + fry(-180) + \
- animation1(0, 10 * (t1 - t0), fry(0)), _txt)
- ass_main(ASS_BUF, SubL(t1, _start + _elapk + 2), \
- pos(_x + 1, _y + 1) + alpha1(255) + alpha3(119) + color3('000000') + \
- bord(8) + blur(8) + fad(0, 20), _txt)
- for i in range(1, 5):
- ass_main(ASS_BUF, SubL(t2 + 3 * i, t3 + 3 * i), \
- mov(_x, _y, _x - 30, _y + 30) + alpha1(0) + blur(2) + \
- fad(0, 20 * (t3 - t2)) + animation1(0, 10 * (t3 - t2), fry(180)), _txt)
- ass_main(ASS_BUF, SubL(t2, t3), \
- mov(_x, _y, _x - 30, _y + 30) + alpha1(0) + blur(2) + fad(0, 10 * (t3 - t2)) + \
- animation1(0, 10 * (t3 - t2), fry(180)), _txt)
- # gradient
- seed(_j)
- ptString = '{\\p8}m 0 0 l 128 0 128 128 0 128'
- dx = _x - int(_a / 2 + 0.5) # 一个固定操作, 将an5的坐标转换为an7
- dy = _y - int(_Fs / 2 + 0.5) # ASS特效默认采用an5坐标, TCAS特效则采用an7坐标
- PIX = TextPix(Font, _txt) # get the pixel info
- PIX_t = PIX
- width = PIX[1][0]
- height = PIX[1][1]
- # get points of the text from PIX, to get the colors from points use PIX[2][...]
- text = []
- for h in range(height):
- for w in range(width):
- if PIX[2][(h * width + w) * 4 + 3] != 0:
- text.append((w, h))
- # make the boundary
- boundary = []
- for h in range(height):
- boundary.append([])
- for w in range(width):
- boundary[h].append(-1) # -1 indicates the boundary
- num = len(text) # number of points
- for i in range(num):
- w = text[i][0]
- h = text[i][1]
- boundary[h][w] = i # non-boundary area
- dx0 = (0, 1, 0, -1)
- dy0 = (1, 0, -1, 0)
- # make the index
- index = []
- for i in range(num):
- index.append(-1)
- # rearrange the index
- left = num
- while (left > 0):
- q = deque()
- for i in range(num):
- if index[i] == -1:
- q.append(i)
- index[i] = 0
- break
- while (len(q) > 0):
- left -= 1
- s = q.popleft()
- pt = text[s]
- for i in range(4):
- x1 = pt[0] + dx0[i]
- y1 = pt[1] + dy0[i]
- if x1 >= 0 and x1 < width and y1 >= 0 and y1 < height and boundary[y1][x1] >= 0:
- t = boundary[y1][x1]
- if index[t] < 0:
- index[t] = index[s] + 1
- q.append(t)
- # TCAS alternative
- #pc0 = '5955FF'
- #pc1 = '55FDFF'
- #pc2 = '9C4E4D'
- indsc = 0.5
- tp0_start = 10 * _end
- tp0_end = 0
- tp0 = []
- for i in range(num):
- t = 10 * (_start + _elapk - 10 + index[i] / indsc + 10 * RandomDouble_Gauss(-0.2, 0.2))
- tp0.append(t)
- if t < tp0_start: # what we are doing is to create a series of PIXs to conver all the possible durations
- tp0_start = t
- if t > tp0_end:
- tp0_end = t
- tp0_end += 24 * _FD
- dur = tp0_end - tp0_start
- for i in range(0, int(dur), int(_FD)): # first of all, you should know how many frames we are going to make, then with each frame, what PIX we are going to use
- PIX_li = [] # we need one PIX for each frame
- PIX_li.append(PIX_t[0])
- PIX_li.append(PIX_t[1])
- temp = list(PIX_t[2])
- for j in range(num): # make the PIX
- pt = text[j]
- off = (pt[1] * width + pt[0]) * 4
- temp[off + 0] = 0xFF
- temp[off + 1] = 0x55
- temp[off + 2] = 0x59
- if tp0_start + i < tp0[j]: # should be transparent
- temp[off + 3] = 0
- elif tp0_start + i < tp0[j] + 7 * _FD:
- temp[off + 3] *= (i + tp0_start - tp0[j] + _FD) / (8 * _FD)
- elif tp0_start + i < tp0[j] + 15 * _FD:
- temp[off + 0] = 0xFF
- temp[off + 1] = 0x55 + (0xFD - 0x55) * (i + tp0_start - tp0[j] - 7 * _FD) / (8 * _FD)
- temp[off + 2] = 0x59 + (0x55 - 0x59) * (i + tp0_start - tp0[j] - 7 * _FD) / (8 * _FD)
- elif tp0_start + i < tp0[j] + 22 * _FD:
- temp[off + 0] = 0xFF + (0x4D - 0xFF) * (i + tp0_start - tp0[j] - 14 * _FD) / (8 * _FD)
- temp[off + 1] = 0xFD + (0x4E - 0xFD) * (i + tp0_start - tp0[j] - 14 * _FD) / (8 * _FD)
- temp[off + 2] = 0x55 + (0x9C - 0x55) * (i + tp0_start - tp0[j] - 14 * _FD) / (8 * _FD)
- else:
- temp[off + 0] = 0x4D
- temp[off + 1] = 0x4E
- temp[off + 2] = 0x9C
- PIX_li.append(tuple(temp))
- PIX = tuple(PIX_li)
- tcas_main(TCAS_BUF, PIX, tp0_start + i, tp0_start + i + _FD, dx, dy, 0)
- tp0_end -= int(dur) % int(_FD)
- if tp0_end < 10 * t2:
- PIX = PixColorRGB(PIX_t, 0x9C4E4D)
- tcas_main(TCAS_BUF, PIX, tp0_end, 10 * t2, dx, dy, 0)
- ##### 将结果返回给tcax进行处理 #####
- return (ASS_BUF, TCAS_BUF)
复制代码 |
-
2
查看全部评分
-
|