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

标题: Question about effect! [打印本页]

作者: Alex    时间: 2013-9-6 15:40:40     标题: Question about effect!

本帖最后由 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


作者: milkyjing    时间: 2013-9-6 22:17:41

this demo is simpler http://www.tcax.org/forum.php?mod=viewthread&tid=382
it may help you understand the concept behind the effect.

p.s. this is a popular effect, and I think there do be some nice guy had already wrote a Lua version.
作者: Alex    时间: 2013-9-6 23:45:22

本帖最后由 Alex 于 2013-9-7 01:54 编辑

Thank u Bro

作者: Alex    时间: 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
作者: Alex    时间: 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)
复制代码

作者: milkyjing    时间: 2013-9-7 15:16:10

Alex 发表于 2013-9-7 14:34
Ok
I came with questionmax here it same like interpolate function in auto.4 right?

Nope, it means to return the larger one of pt_num and maxi
作者: milkyjing    时间: 2013-9-7 15:25:15

Alex 发表于 2013-9-7 01:54
I understand some things ..I will try the to do it
but If there is lua example (simple) it will be b ...

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 think the better way is by your side, digging into the demo, try to understand the concept, if not, come to post here with your specific question, and we will try to give an explanation. Then you're able to write your own.
作者: Alex    时间: 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
作者: Alex    时间: 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?

作者: milkyjing    时间: 2013-9-8 18:48:45

Alex 发表于 2013-9-7 18:13
this is my  simple code, but i didn't get the right result  (NyuFx)
-

Sorry, I'm not so familiar with NyuFX, I've sent your request to showjim, a nice guy who is good at NyuFX.


作者: showjim    时间: 2013-9-8 20:19:57

本帖最后由 showjim 于 2013-9-8 22:38 编辑
Alex 发表于 2013-9-7 20:13
this is my  simple code, but i didn't get the right result  (NyuFx)
-


Hi mate,

I just looked through your code roughly, the only thing I did is to check the grammar of Lua. I find there are two functions you used not properly. They are "Interpolate" and "bezier_curve". Commonly, the "pct" coefficient in these two functions should range from 0 to 1. In your code, what you used is "#pixel", this is to get the index of current pixel, the value is larger or equal to 1 in Lua. Or maybe the functions you used are not the way I said. Could you show the code of these two functions?
I do not have NyuFX on my current computer. I'll check & run your code in the next few days.

Regards,
showjim
作者: Alex    时间: 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
复制代码

作者: saiyaku    时间: 2013-9-9 07:10:06

                        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 "

I don't know lua, but maybe the 'pos' should be 'move' ,I think.
作者: Alex    时间: 2013-9-10 05:40:58

No,
we can do curve effect by using pos tag, no need move tag
作者: milkyjing    时间: 2013-9-13 23:10:53

Alex 发表于 2013-9-10 05:40
No,
we can do curve effect by using pos tag, no need move tag

but I suppose that maybe we should use move instead of pos, since in this effect the points moves from the text to the bezier.
作者: Alex    时间: 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




欢迎光临 TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua (http://tcax.org/) Powered by Discuz! X2