【Aegisub】幾何變換與變形
可參考的網(wǎng)址;
https://blog.csdn.net/qq_40464371/article/details/102518672
https://blog.csdn.net/June_Xixi/article/details/102488630
https://blog.csdn.net/weixin_43943977/article/details/102511052
https://blog.csdn.net/qq_38137411/article/details/83213297
以任意點(diǎn)(a,b)進(jìn)行x方向縮放c倍、y方向縮放d倍
function transformation(x,y,a,b,c,d) ? ? return a+(x-a)*c,b+(y-b)*d end
說明:平時(shí)使用的x*2,y*2這種縮放操作當(dāng)然是以(0,0)點(diǎn)為基礎(chǔ),就像上面那樣說的,當(dāng)c、d都為0時(shí)即有x*2,y*2
θ為正即繞原點(diǎn)逆時(shí)針旋轉(zhuǎn)θ°
function rotate(x,y,θ) ? ? return x*math.cos(math.rad(θ))+y*math.sin(math.rad(θ)),-x*math.sin(math.rad(θ))+y*math.cos(math.rad(θ)) end
平面中繞任意點(diǎn)旋轉(zhuǎn)矩陣求法
θ為正即繞任意點(diǎn)(a,b)逆時(shí)針旋轉(zhuǎn)θ° ??
function rotate(x,y,a,b,θ) ? ? return (x-a)*math.cos(math.rad(θ))+(y-b)*math.sin(math.rad(θ))+a,b-(x-a)*math.sin(math.rad(θ))+(y-b)*math.cos(math.rad(θ)) end
錯(cuò)切幾何變換(形變效果樣子參考標(biāo)簽如fax)
function Shear(x,y,c,d) ? ? return x+c*y,y+d*x end
上面即在x方向錯(cuò)切c,c為x方向錯(cuò)切系數(shù)。然后d為y方向錯(cuò)切系數(shù)
更形象的寫法如下:
function Shear(x,y,c,d) ? ? return x+math.tan(math.rad(c))*y,y+math.tan(math.rad(d))*x end
說明:c、d均為你所要指定的角度,如x方向錯(cuò)切45度則c=45、d=0,其效果中可見角度"錯(cuò)開"45°
錯(cuò)切加上平移
function Shear(x,y,c,d) if c== 0 then move_x= 0 else move_x= -(by-ly)/math.tan(math.rad(c))/2 end if d == 0 then move_y =0 else move_y = -(bx-lx)/math.tan(math.rad(d))/2 end ?return x+math.tan(math.rad(c))*y+ move_x,y+math.tan(math.rad(d))*x+move_y end
扭曲
function warping1(x,y) ?r1 =math.sqrt((x-mx)^2+(by-y)^2) ? ? mr1=math.sqrt((lx-mx)^2+(by)^2) ? ?θ=math.rad(90*mr1/r1) ?return mx+(x-mx)-(y-by)*math.sin(θ*(1-((maxj-j+1)/maxj))),y end
function warping2(x,y) ?r2 =math.sqrt((x-mx)^2+(y-my)^2) ? ? mr2=math.sqrt((lx-mx)^2+(ly-my)^2) ? ?θ=math.rad(30*mr2/r2) ?return mx+(x-mx)*math.cos(θ*(1-((maxj-j)/maxj)))-(y-my)*math.sin(θ*(1-((maxj-j)/maxj))),my+(x-mx)*math.sin(θ*(1-((maxj-j)/maxj)))+(y-my)*math.cos(θ*(1-((maxj-j)/maxj))) end
function warping3(x,y) ?r3 =math.sqrt((x-mx)^2+(y-my)^2) ? ? mr3=math.sqrt((lx-mx)^2+(ly-my)^2) ? ?θ=math.rad(30*mr3/r3) ?return mx+(x-mx)*math.cos(θ*((j/maxj)-1))-(y-my)*math.sin(θ*((j/maxj)-1)),my+(x-mx)*math.sin(θ*((j/maxj)-1))+(y-my)*math.cos(θ*((j/maxj)-1)) end
function warping4(x,y) ?r4 =math.sqrt((x-mx)^2+(y-my)^2) ? ? mr4=math.sqrt((lx-mx)^2+(ly-my)^2) ? ? θ=math.rad(30*mr4/r4) ?return mx+(x-mx)*math.cos(θ*(1-(j/maxj)))-(y-my)*math.sin(θ*((1- j/maxj))),my+(x-mx)*math.sin(θ*(1-(j/maxj)))+(y-my)*math.cos(θ*((1-j/maxj))) end
function warping5(x,y) ?r5 =math.sqrt((x-mx)^2+(y-my)^2) ? ? mr5=math.sqrt((lx-mx)^2+(ly-my)^2) ? ?θ=math.rad(60*r5/mr5) ?return mx+(x-mx)*math.cos(θ*(1-(j/maxj)))-(y-my)*math.sin(θ*((1-j/maxj))),my+(x-mx)*math.sin(θ*(1-(j/maxj)))+(y-my)*math.cos(θ*((1-j/maxj))) end
function warping6(x,y) ?mod =(y-ly)/(by-ly) ?return x+20*math.sin(2*math.pi*mod)*(1-j/maxj),y end
function warping7(x,y,k) ?mod =(y-ly)/(by-ly) ?return x+k*math.sin(2*math.pi*mod)*(1-j/maxj),y end
function warping8(x,y,k,v) ?mod =(y-ly)/(by-ly) ? ?mod2 =(x-lx)/(bx-lx) ?return x+k*math.sin(2*math.pi*mod)*(1-j/maxj),y+v*math.sin(2*math.pi*mod2)*(1-j/maxj) end
關(guān)于warping8建議其中的k和v都小于字體高度除以8比較好(即小于height/8)
上面扭曲中用到的變量都先定義在前面
style=line.styleref text=_G.Yutils.decode.create_font(style.fontname, style.bold, style.italic, style.underline, style.strikeout,style.fontsize).text_to_shape(syl.text_stripped) ?text=string.gsub(text,"c","") ? lx,ly,bx,by=_G.Yutils.shape.bounding(text) ? ? ? ? ?mx=(lx+bx)/1.7 ? ? ? my=(ly+by)/2
