| 
UID2443积分1311帖子78主题21论坛币909 威望8 EP值449 MP值0 阅读权限100注册时间2015-3-7在线时间121 小时最后登录2018-7-21
 
  
 | 
| 模拟透镜畸变 (Lens Distortion),参考 wikipedia。 其实探索过程中发现,这个变换还有很多花样,可以多尝试改变变换。
 注意,畸变因子,尽量选得小一些,例如 0.001。
 这个是用 ASS 的,生成一行观察效果就可以了,生成多行体积会比较大。
 不足是,坐标变换后,因为是浮点,字的像素会变得不紧密,看起来是栅栏状,加上边框色会好一些,但是边界会显得模糊。
 有时间会写 TCAS,以及改善栅栏问题。
 请看工程。
 链接: http://pan.baidu.com/s/1jHXCv8E 密码: hb65
 复制代码from tcaxPy import *
def tcaxPy_Init():
    global user_font
    global font_size
    global distoration_center    # 畸变中心点,元组
    global framedur
    font_size = GetVal(val_FontSize)
    distoration_center = (640, GetVal(val_OffsetY) + font_size / 2)
    framedur = 1000 / GetVal(val_FXFPS)    # 帧时间,毫秒
    user_font = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), font_size, GetVal(val_Spacing), GetVal(val_SpaceScale), DecRGB(GetVal(val_1C)), 0, 0)
def tcaxPy_Fin():
    FinFont(user_font)
def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
    ASS_BUF  = []        # used for saving ASS FX lines
    if _i == 0:
        pix_syl = TextPix(user_font, _txt)
        # 从字的左上角开始,初始坐标
        posx_init     = _x - _a / 2        + pix_syl[0][0]
        posy_init     = _y - font_size / 2 + pix_syl[0][1]
        width, height = pix_syl[1]    # 字的宽和高
        # 逐行扫描
        for i in range(height):
            for j in range(width):
                idx = 4 * (i * width + j)
                channelR, channelG, channelB, channelA = pix_syl[2][idx : idx + 4]    # RGBA 通道值
                if channelA != 0:    # 若字不透明,则绘制粒子
                    for k in range(200):    # 200帧的变化时间长度
                        # 绝对坐标
                        posx = posx_init + j
                        posy = posy_init + i
                        # 转换为与畸变中心点的相对坐标
                        relative_posx = posx - distoration_center[0]
                        relative_posy = posy - distoration_center[1]
                        r_square = (posx - distoration_center[0]) ** 2 + (posy - distoration_center[1]) ** 2
                        # 畸变的坐标变换
                        relative_posx = relative_posx * (1 + 0.0001 * (199 - k) / 199 * r_square)
                        relative_posy = relative_posy * (1 + 0.0001 * (199 - k) / 199 * r_square)
                        # 转换为绝对坐标
                        posx += relative_posx
                        posy += relative_posy
                        ts = _start + framedur * k / 10
                        te = _start + framedur * (k + 1) / 10
                        effect = pos(posx, posy) + color1(FmtRGB(channelR, channelG, channelB)) + alpha1(255 - channelA)
                        ass_main(ASS_BUF, SubL(ts, te, 0, 'TCPS'), effect, DrawPoint())
    return (ASS_BUF, None)
 | 
 
1
查看全部评分
 |