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

 找回密码
 新人加入
查看: 10578|回复: 8
打印 上一主题 下一主题

[已解决] Question about effect! [复制链接]

Rank: 4

跳转到指定楼层
楼主
发表于 2013-9-6 15:40:40 |显示全部楼层 |倒序浏览
本帖最后由 Alex 于 2013-9-6 21:07 编辑

Hi,


I have question about this effect in this link

(http://www.tcax.org/forum.php?mo ... &extra=page%3D1)

I think he used curve to make this effect, so my question is how can we make this effect by using Lua ?

I'm not good in Python to understand his code and rewrite in Lua

Rank: 4

沙发
发表于 2013-9-6 23:45:22 |显示全部楼层
本帖最后由 Alex 于 2013-9-7 01:54 编辑

Thank u Bro

Rank: 4

板凳
发表于 2013-9-7 01:54:45 |显示全部楼层
I understand some things ..I will try the to do it
but If there is lua example (simple) it will be better, or if u can tell that man who wrote a LUA version

Regards

Rank: 4

地板
发表于 2013-9-7 14:34:59 |显示全部楼层
Ok
I came with question
  1. max(pt_num, maxi)
复制代码
max here it same like interpolate function in auto.4 right?
  1. function interpolate(pct, min, max)
复制代码

Rank: 4

5#
发表于 2013-9-7 16:55:29 |显示全部楼层
Yep, I had already sent your request to some members who both knew python and Lua, but I'm not sure whether they have enough interest or time to rewrite.


I really appreciate that, if they cant at less i need them help

and I really try to understand ur demo script and I'm trying to write by myself, if i have question i will ask you
question i will put here with my code

thanks

Rank: 4

6#
发表于 2013-9-7 18:13:22 |显示全部楼层
本帖最后由 Alex 于 2013-9-7 18:45 编辑

this is my  simple code, but i didn't get the right result  (NyuFx)
  1.         local l = table.copy(line)
  2.         for si,syl in pairs(line.syls) do

  3.                    for pi, pixel in ipairs(convert.text_to_pixels(syl.text, line.styleref, syl.left % 1,  y % 1)) do   

  4.                 local x, y = syl.left + pixel.x,syl.y + pixel.y

  5.                 local points = {
  6.                                 {x, y},
  7.                                 {x + rand(50,50), y+rand(-30,40)},
  8.                                 {x + rand(50,50), y+rand(30,90)},
  9.                                 {x + rand(-100,100), y + rand(-50,50)},
  10.                                 {x + rand(-50,50), y + rand(-70,70)},
  11.                                 {x + rand(-70,70), y + rand(-40,40) }
  12.                               }

  13.                 local  start_t = line.start_time + syl.start_time
  14.                 local  end_t = line.start_time + syl.start_time + 400

  15.                         local tt = Interpolate(#pixel,start_t, end_t)
  16.                         local x_cur, y_cur = bezier_curve(#pixel, points)

  17.                         l.start_time = tt
  18.                         l.end_time = tt + 300
  19.                         l.text = string.format("{\\an7\\pos("..x_cur..","..y_cur..")\\bord0\\1c&Hffffff&\\fscx150\\fscy150\\p1}").."m 0 0 l 1 0 l 1 1 l 0 1 l 0 0 "
  20.                         Output(l)

  21.                   end
  22.         end
复制代码

-

depending on your experience, what are the things missing?

Rank: 4

7#
发表于 2013-9-9 01:52:26 |显示全部楼层
本帖最后由 Alex 于 2013-9-9 01:54 编辑

thank you showjim, I appreciate that

this is the both function
  1. function bezier_curve(pct, p)

  2.         local function fac(n)
  3.                 local k = 1
  4.                 if n > 1 then
  5.                         for i=2, n do
  6.                                 k = k * i
  7.                         end
  8.                 end
  9.                 return k
  10.         end

  11.         local function bin(i, n)
  12.                 return fac(n) / (fac(i) * fac(n-i))
  13.         end

  14.         local function bernstein(pct, i, n)
  15.                 return bin(i, n) * math.pow(pct,i) * math.pow((1 - pct), n - i)
  16.         end


  17.         if pct < 0 or pct > 1 or table.maxn(p) < 2 then
  18.                 return nil
  19.         end
  20.         for i, v in ipairs(p) do
  21.                 if type(v[1]) ~= "number" or type(v[2]) ~= "number" then
  22.                         return nil
  23.                 end
  24.         end

  25.         local x, y, z = 0, 0, 0
  26.         local n = table.maxn(p) - 1
  27.         for i=0, n do
  28.                 local bern = bernstein(pct, i, n)
  29.                 x = x + p[i+1][1] * bern
  30.                 y = y + p[i+1][2] * bern
  31.                 z = z + (p[i+1][3] or 0) * bern
  32.         end
  33.         return x, y, z
  34. end
复制代码
other one
  1. function math.bezier(pct, p)
  2.         if type(pct) ~= "number" or type(p) ~= "table" then
  3.                 error("number and table expected", 2)
  4.         elseif pct < 0 or pct > 1 or #p < 2 then
  5.                 error("invalid arguments", 2)
  6.         end
  7.         for i, v in ipairs(p) do
  8.                 if type(v[1]) ~= "number" or type(v[2]) ~= "number" or (type(v[3]) ~= "number" and type(v[3]) ~= "nil") then
  9.                         error("invalid table content", 2)
  10.                 end
  11.         end
  12.         --Factorial
  13.         local function fac(n)
  14.                 local k = 1
  15.                 if n > 1 then
  16.                         for i=2, n do
  17.                                 k = k * i
  18.                         end
  19.                 end
  20.                 return k
  21.         end
  22.         --Binomial coefficient
  23.         local function bin(i, n)
  24.                 return fac(n) / (fac(i) * fac(n-i))
  25.         end
  26.         --Bernstein polynom
  27.         local function bernstein(pct, i, n)
  28.                 return bin(i, n) * pct^i * (1 - pct)^(n - i)
  29.         end
  30.         --Calculate coordinate
  31.         local point = {0, 0, 0}
  32.         local n = #p - 1
  33.         for i=0, n do
  34.                 local bern = bernstein(pct, i, n)
  35.                 point[1] = point[1] + p[i+1][1] * bern
  36.                 point[2] = point[2] + p[i+1][2] * bern
  37.                 point[3] = point[3] + (p[i+1][3] or 0) * bern
  38.         end
  39.         return point
  40. end
复制代码
Interpolate function
  1. function utils.interpolate(pct, val1, val2, calc)
  2.         if type(pct) ~= "number" or
  3.         not (
  4.                 (type(val1) == "number" and type(val2) == "number") or
  5.                 (type(val1) == "string" and type(val2) == "string")
  6.         ) or
  7.         (type(calc) ~= "string" and type(calc) ~= "number" and type(calc) ~= "nil") then
  8.                 error("number and 2 numbers or 2 strings and optional string expected", 2)
  9.         end
  10.         -- Calculate percent value depending on calculation mode
  11.         if calc ~= nil then
  12.                 if type(calc) == "number" then
  13.                         pct = pct^calc
  14.                 elseif calc == "curve_up" then
  15.                         pct = (math.sin( -math.pi/2 + pct * math.pi*2) + 1) / 2
  16.                 elseif calc == "curve_down" then
  17.                         pct = 1 - (math.sin( -math.pi/2 + pct * math.pi*2) + 1) / 2
  18.                 else
  19.                         error("valid last value expected", 2)
  20.                 end
  21.         end
  22.         -- Interpolate numbers
  23.         if type(val1) == "number" then
  24.                 return val1 + (val2 - val1) * pct
  25.         -- Interpolate strings
  26.         else
  27.                 -- RGB
  28.                 local r1, g1, b1 = convert.ass_to_rgb(val1)
  29.                 local r2, g2, b2 = convert.ass_to_rgb(val2)
  30.                 if b1 and b2 then
  31.                         return convert.rgb_to_ass((r2 - r1) * pct + r1, (g2 - g1) * pct + g1, (b2 - b1) * pct + b1)
  32.                 end
  33.                 -- Alpha
  34.                 local a1 = convert.ass_to_a(val1)
  35.                 local a2 = convert.ass_to_a(val2)
  36.                 if a1 and a2 then
  37.                         return convert.a_to_ass((a2 - a1) * pct + a1)
  38.                 end
  39.                 -- Invalid string
  40.                 error("invalid strings", 2)
  41.         end
  42. end
复制代码

Rank: 4

8#
发表于 2013-9-10 05:40:58 |显示全部楼层
No,
we can do curve effect by using pos tag, no need move tag

Rank: 4

9#
发表于 2013-9-13 23:26:08 |显示全部楼层
I used before but the result was same, i will try again soon with move tag
and I hope to get a satisfactory result
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-5-9 07:17

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH