- UID
- 2
- 积分
- 8682
- 帖子
- 2905
- 主题
- 199
- 论坛币
- 11741
- 威望
- 16
- EP值
- 2349
- MP值
- 15
- 阅读权限
- 200
- 注册时间
- 2011-8-3
- 在线时间
- 2597 小时
- 最后登录
- 2024-8-28
|
说明: 代码框架类似 http://www.tcax.org/forum.php?mod=viewthread&tid=397, magnifier滤镜参考了水银灯的代码
magnifier.rar
(2.84 KB, 下载次数: 3419)
- from tcaxPy import *
- from util.cairo import *
- def tcaxPy_Init():
- global _Fs
- global _FD # 一帧的持续时间, 约40毫秒
- global _Spacing # 字体间距
- global Font # 首要字体
- _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), MakeRGB(255, 255, 255), 0, False)
- # cairo
- global ctx
- fx_width = GetVal(val_ResolutionX)
- fx_height = GetVal(val_ResolutionY)
- surface = ImageSurface(FORMAT_ARGB32, fx_width, fx_height)
- ctx = Context(surface)
- def tcaxPy_Fin():
- FinFont(Font)
- def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
- ASS_BUF = [] # 保存ASS特效
- TCAS_BUF = [] # 保存TCAS特效
- ##### 主要特效编写操作 #####
- ### begin of line scope, do not change the code ###
- lineChanged = IsLineChanged(_i)
- if lineChanged:
- _initX = _x - int((_a + _Spacing) / 2 + 0.5)
- _initY = _y - int(_Fs / 2 + 0.5)
- _length = GetVal(val_TextLength)[_i]
- tcaxPy_Line(_i, _start, _end, _initX, _initY, _length, ASS_BUF, TCAS_BUF)
- ### end of line scope, do not change the code ###
- ##### 将结果返回给tcax进行处理 #####
- return (ASS_BUF, TCAS_BUF)
- def tcaxPy_Line(_i, _start, _end, _initX, _initY, _length, ASS_BUF, TCAS_BUF):
- texts = GetVal(val_Text)[_i]
- elapk = GetVal(val_KarTimeDiff)[_i]
- kar = GetVal(val_KarTime)[_i]
- advanceDiff = GetVal(val_TextAdvanceDiff)[_i]
- advance = GetVal(val_TextAdvance)[_i]
- num = len(texts)
- assDraw = ''
- for i in range(num):
- if '' == texts[i] or ' ' == texts[i] or ' ' == texts[i]:
- continue
- assDraw += TextOutlineDraw(Font, texts[i], _initX + advanceDiff[i], _initY) + ' '
- frames = int(10 * (_end - _start) / _FD + 0.5)
- for i in range(frames):
- ts = _start + i * _FD / 10
- te = _start + (i + 1) * _FD / 10
- j = xthSyl(elapk, num, i * _FD / 10) # 根据进行的时间查找当前进行到第几个字
- pct = (ts - (_start + elapk[j])) / kar[j] # 当前文字效果进行的百分比
- big_x = _initX + advanceDiff[j] + pct * advance[j]
- big_y = _initY + _Fs / 2
- AssDraw(ctx, assDraw)
- path_trans(ctx, magnifier_filter, (big_x, big_y))
- text = ToAssDraw(ctx)
- EFT = an(7) + pos(0, 0) + color1('FFFFFF') + color3('FF0000') + p(7)
- ass_main(ASS_BUF, SubL(ts, te), EFT, text)
- def xthSyl(elapk, n, fts):
- for i in range(n - 1):
- if elapk[i] <= fts and fts < elapk[i + 1]:
- return i
- return n - 1
- def magnifier_filter(x, y, param):
- big_x, big_y = param
- D = _Fs
- d = sqrt((x - big_x * 64) * (x - big_x * 64) + (y - big_y * 64) * (y - big_y * 64)) / 64
- if d < D:
- ang = pi / 2 * sin(d / D)
- pct = D * sin(ang) / d
- new_x = int(big_x * 64 + (x - big_x * 64) * pct + 0.5)
- new_y = int(big_y * 64 + (y - big_y * 64) * pct + 0.5)
- return new_x, new_y
- else:
- return x, y
复制代码 |
-
1
查看全部评分
-
|