Typetting with automation using lua part 2..

Continuing from my previous post, let’s dive into the main course, which is the effects

—————————— E F F E C T S ————————————————————————–

–sylables effect
l=result.add()
l.layer=11
l.text = string.format(“{\\an5\\pos(%d,%d)\\t(0,30,\\fscx140\\fscy160\\1c&HFDF0EE&\\3c&HFFFFFF&)\\t(30,%d,\\3c&H000000&\\fscx100\\fscy100\\alpha&HFF&)}%s”,x,y,syl.duration*10+200,syl.text_stripped)
l.start_time = line.start_time + syl.start_time/10
l.end_time = line.start_time + syl.start_time/10 + syl.duration + 20

–Make hearts fly about
for i=0,30 do
l = result.add()
l.layer=0
l.text = string.format(“{\\an5\\move(%d,%d,%d,%d)\\alpha&H80&\\fscx65\\fscy65\\t(\\alpha&HF7&\\fscx20\\fscy20)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”, x+math.random(-8,8)+15, y+math.random(-8,8)+10, x+math.random(-40,10)+15, y+math.random(-15,30)+10,  syl.text)
l.start_time = line.start_time + syl.start_time/10
l.end_time = line.start_time + syl.start_time/10 + syl.duration + i*4
end

Lets break it down. First up. The syllable effects

–sylables effect
l=result.add()
l.layer=11
l.text = string.format(“{\\an5\\pos(%d,%d)\\t(0,30,\\fscx140\\fscy160\\1c&HFDF0EE&\\3c&HFFFFFF&)\\t(30,%d,\\3c&H000000&\\fscx100\\fscy100\\alpha&HFF&)}%s”,x,y,syl.duration*10+200,syl.text_stripped)
l.start_time = line.start_time + syl.start_time/10
l.end_time = line.start_time + syl.start_time/10 + syl.duration + 20



\\t(0,30,\\fscx140\\fscy160\\1c&HFDF0EE&\\3c&HFFFFFF&)

It means at 0 to 0.30 second from starting time the characters will :

  • expand 140% in x axis direction and 160% in y axis direction
  • the primary color gonna change into the &HFDF0EE& (if you are wondering what is this, this is a hexagonal numeric code for colors ranging from 0-9 then continues from A to F, no need to memorize this, aegis provide you with the conversions) and the tertiary color (border color) will become &HFFFFF&
  • why 0 to 0,30 second you ask again? Well, this is something that’s empirical, meaning this numbers are based on my sole experience is the most suitable as it is not so fas not so slow to initiate an effects.

\\t(30,%d,\\3c&H000000&\\fscx100\\fscy100\\alpha&HAA&) and %d defines by syl.duration*10+200

This series of tags give us ,from 0.30 second till the syllable duration + 0,2 second the characters will :

  • The border color became &H000000 (incase you are wondering this is black)
  • The characters will shrink to normal size (100%) of x and y axis
  • The characters will hit a transparency of total about 60-70% when it gets the end of durations + 0,2 second

Next stop the heart effects, but before that I’m gonna tell you about arranging the definition, incase you haven’t noticed it the definition needs to be arranged properly to get its definite definition for example , If you have something like this :

\\pos(%d,%d)\\t(0,30,\\fsx120\\fscy150)\\t(%d,%d,\\fscx100\\fscy100)%s”,x,y,60,200,syl.text_stripped)} so the position coordinates will be x,y, the second \\t will get 60,200 and the last %s will get syl.text_stripped

Continuing.

–Make hearts fly about
for i=0,30 do
l = result.add()
l.layer=0
l.text = string.format(“{\\an5\\move(%d,%d,%d,%d)\\alpha&H80&\\fscx65\\fscy65\\t(\\alpha&HF7&\\fscx20\\fscy20)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”, x+math.random(-8,8)+15, y+math.random(-8,8)+10, x+math.random(-40,10)+15, y+math.random(-15,30)+10,  syl.text)
l.start_time = line.start_time + syl.start_time/10
l.end_time = line.start_time + syl
.start_time/10 + syl.duration + i*4
end

Let’s break it down.

The first for i=0,20 do …

… (commands)

End

That basically a loop command, it will generate a loop that will do the commands in like 21 times(from 0 to 20), i is the variables. Could be change by anything as long as it doesn’t collide with the lua commands, just put your name if you are confuse xD.

Moving onto the effecting tags.

{\\an5\\move(%d,%d,%d,%d)\\alpha&H80&\\fscx65\\fscy65\\t(\\alpha&HF7&\\fscx20\\fscy20)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”, x+math.random(-8,8)+15, y+math.random(-8,8)+10, x+math.random(-40,10)+15, y+math.random(-15,30)+10,  syl.text)

\move(a,b,c,d) is use to move the characters from point #1(a,b) to point #2(c,d) (seek aegis help for more details).

Math.random(a,b) it will generate a rondom pick of number ranging from a to b

The you should understands the rest of the tags

AEGIFACTS| Principally one line is suitable for one tags, so how do you make a line with a sentences meaning there are couple of syllable while you want each syllable of the sentences gets an effects at different time? Easy. You could write down a tag for each syllable. Pretty inconvenient huh? That’s when the k-replacer comes. The k replacer is a method that basically replace every {\k} that you have next to your syllable timing and replace it with a template tags effect that you made without separating em into different lines. But sadly tags like \move are allowed only one for each line. So what’s the solution? Yes. You separate each line into different line so you could have more freedom to animate things are more controlled environment. That’s the rule of karaskel-adv lua and other mandatory things in each script.

Let’s carry on. Outro.

–sylable outro
l=result.add()
l.text = string.format(“{\\an5\\pos(%d,%d)\\alpha&HAA&\\t(\\fry360\\alpha&HFF&)}%s”,x,y,syl.text_stripped)
l.start_time = line.start_time + syl.start_time/10 + syl.duration + 20
l.end_time = line.start_time + syl.start_time/10 + syl.duration + 40

return result
end

Let’s again break it down.

{\\an5\\pos(%d,%d)\\alpha&HAA&\\t(\\fry360\\alpha&HFF&)}%s”,x,y,syl.text_stripped)

You should have understand the first two tags, the alpha&HAA& I put there is to synchronize with the previous alpha we give to our character in the effects part. Finally the remaining tags are for spinning it 360 degrees in y axis and fading it into 100% transparency in the set of time.

There you go. You have learnt the lua. Hurray.

Feedbacks and question are welcomed. Post it here or email me. Thanks for reading

Typesetting with automation using lua part 1..

Someone request me to give some some perspective and idea about lua and using it to the max with out actually learning all of the programming language itself. Lua, if that doesn’t ring a bell to you well maybe that you are not familiar to the term aegisub. If you do know what and how to use aegisub then you might haven’t used automation scripts before. But if you do have used automation.. ah this is getting nowhere. Let’s just start. Bare in mind that this is automation 3.

Lua is a programming language that now said to be the leading in some of highly known applications and games. Why so you ask? Because is fast and simple. Not convinced yet, let’s put it this way, I’m not any familiar with programming language and i’m not majoring in computer science or somewhat related, then again able to understand lua (NOT 100% though but enough to put some creative idea and make some nice karaoke effects with it)

The lua itself not really the only fundamentals, but rather the role of the tags play mostly. So for sums up, lua is the MEDIA for you to write down, and TAGS is the things you write. More simpler, lua is the paper and tags is the ink.

I’m gonna use the muxh easier way to explain you about lua. So I’m gonna post up a example script that I always used an break it down to you. ^_^

but wait. Here’s some info about how to use automation,

automation-1

and Here’s the Script, download it at THIS LINK

— Aegisub Automation script
— Original written by Ivan Tanev aka Crafty_Shadow
— Resimplified by TheProteosAgna

name = “Basic Script #1”
description = “Simple color changing with hearts”
configuration = {}
version, kind = 3, ‘basic_ass’

–>–includes and global variables
include(“karaskel-adv.lua”)
br=0
time=1
–<–end include

function do_syllable(meta, styles, config, line, syl)

–>>FUNCTION FOR RESULT PARSING>>–
local result = {n=0}
function result.add() local l = copy_line(line); table.insert(result, l); return l end
–<<FUNCTION FOR RESULT PARSING<<–

–>–check for empty line
if syl.text == “” then
return { n=0 }
end
if syl.text == ” ” then
return { n=0 }
end
–<–end check

–>– x and y coordination definition
local x=syl.center + line.centerleft
local y=line.styleref.margin_v + 13
–<– end def

–>–check if a new line has started, and zero the counter if it has; increase the counter
if time ~= line.start_time then
time=line.start_time
br=-1
end
br=br+1
–<–end of check

————————————————————– I N T R O ———————————————————————————————————-

–Check the line for . , ” and don’t apply effect if it’s one of then
if  (syl.text_stripped == “.”) then elseif (syl.text_stripped == “,”) then elseif (syl.text_stripped == “\””) then else

–Hearts spin intro
l=result.add()
l.text = string.format(“{\\an5\\org(%d,%d)\\pos(%d,%d)\\fry90\\t(\\fry360)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”,x,y+13,x+15,y+14)
l.start_time = line.start_time -65 +br*10
l.end_time = line.start_time + br*10 -15

l=result.add()
l.text = string.format(“{\\an5\\org(%d,%d)\\pos(%d,%d)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”,x,y+13,x+15,y+14)
l.start_time = line.start_time + br*10 -15
l.end_time = line.start_time + syl.start_time/10
–finish hearts spin intro
end

–sylables spin in intro
l=result.add()
l.text = string.format(“{\\an5\\pos(%d,%d)\\fry270\\t(\\fry360)}%s”,x,y,syl.text_stripped)
l.start_time = line.start_time -28 +br*1
l.end_time = line.start_time + br*10 -15

–sylables after intro, and before effect
l=result.add()
l.layer=10
l.text = string.format(“{\\an5\\pos(%d,%d)}%s”,x,y,syl.text_stripped)
l.start_time = line.start_time +br*10 -15
l.end_time = line.start_time + syl.start_time/10

————————————————————– E F F E C T S ———————————————————————————————————-

–sylables effect
l=result.add()
l.layer=11
l.text = string.format(“{\\an5\\pos(%d,%d)\\t(0,30,\\fscx140\\fscy160\\1c&HFDF0EE&\\3c&HFFFFFF&)\\t(30,%d,\\3c&H000000&\\fscx100\\fscy100\\alpha&HFF&)}%s”,x,y,syl.duration*10+200,syl.text_stripped)
l.start_time = line.start_time + syl.start_time/10
l.end_time = line.start_time + syl.start_time/10 + syl.duration + 20

–Make hearts fly about
for i=0,30 do
l = result.add()
l.layer=0
l.text = string.format(“{\\an5\\move(%d,%d,%d,%d)\\alpha&H80&\\fscx65\\fscy65\\t(\\alpha&HF7&\\fscx20\\fscy20)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”, x+math.random(-8,8)+15, y+math.random(-8,8)+10, x+math.random(-40,10)+15, y+math.random(-15,30)+10,  syl.text)
l.start_time = line.start_time + syl.start_time/10
l.end_time = line.start_time + syl.start_time/10 + syl.duration + i*4
end

————————————————————– O U T R O ———————————————————————————————————-

–sylable outro
l=result.add()
l.text = string.format(“{\\an5\\pos(%d,%d)\\t(\\fry360\\alpha&HFF&)}%s”,x,y,syl.text_stripped)
l.start_time = line.start_time + syl.start_time/10 + syl.duration + 20
l.end_time = line.start_time + syl.start_time/10 + syl.duration + 40

return result
end

Let’s start with the mandatory parts

— Aegisub Automation script
— Original written by Ivan Tanev aka Crafty_Shadow
— Resimplified by TheProteosAgna

name = “Basic Script #1”
description = “Simple color changing with hearts”
configuration = {}
version, kind = 3, ‘basic_ass’

–>–includes and global variables
include(“karaskel-adv.lua”)
br=0
time=1
–<–end include

function do_syllable(meta, styles, config, line, syl)

–>>FUNCTION FOR RESULT PARSING>>–
local result = {n=0}
function result.add() local l = copy_line(line); table.insert(result, l); return l end
–<<FUNCTION FOR RESULT PARSING<<–

–>–check for empty line
if syl.text == “” then
return { n=0 }
end
if syl.text == ” ” then
return { n=0 }
end
–<–end check

Those part above is something that mandaotry that must have in aegis, the only modifiable is the name  and description parts. let’s skip this one and move one to something more interesting.

Next is,

–>– x and y coordination definition
local x=syl.center + line.centerleft
local y=30
–<– end def

Those line above defines the x and y coordinates.

–>–check if a new line has started, and zero the counter if it has; increase the counter
if time ~= line.start_time then
time=line.start_time
br=-1
end
br=br+1
–<–end of check

Those line above is for counting or marking the number of characters or syllables in one line, and reset the counter for each new line. ‘br ‘ is just some expression totally modifiable, you can change it with your name or something else.

For the next thing what you have to have in mind is this pattern. The command lines usualy have this elements :

l=result.add() –> something mandatory, don’t bother with it
l.text = string.format(“{you write effects here}%s”,you write the definition here )
l.start_time = it’s the line start time
l.end_time = it’s the line end time

effects usually write down with tags, you can see it in aegis help, section ASS overide tags and something like %d or %d or even %x (that a call it definition marks) , learn and memorize it. Definition usually fills with numbers or letters defining the denition marks, example if the tags has \\t(%d,%d,\\fs%d) and the definition is 0,200,50 meaning that you animate the font size larging it into 50 in 0 till 200 miliseconds time duration.

Well, I usually divide the script into 3 parts, intro effects and outro. I’ll start with Intro first. Intro is the part when the characters are comes to but just before the time it start.

–Check the line for . , ” and don’t apply effect if it’s one of them
if  (syl.text_stripped == “.”) then elseif (syl.text_stripped == “,”) then elseif (syl.text_stripped == “\””) then else

This lines of commands is for checking the line for . , ”  characters and don’t apply effect if it’s one of them

Next is the intro,

–Hearts spin intro
l=result.add()
l.text = string.format(“{\\an5\\org(%d,%d)\\pos(%d,%d)\\fry90\\t(\\fry360)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”,x,y+13,x+15,y+14)
l.start_time = line.start_time -65 +br*10
l.end_time = line.start_time + br*10 -15

–after spinning before effects
l=result.add()
l.text = string.format(“{\\an5\\org(%d,%d)\\pos(%d,%d)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”,x,y+13,x+15,y+14)
l.start_time = line.start_time + br*10 -15
l.end_time = line.start_time + syl.start_time/10
–finish hearts spin intro
end

Those line above principally to make the heart appears spinning and stays until the effects comes. Let’s break it down.

l.text = string.format(“{\\an5\\org(%d,%d)\\pos(%d,%d)\\fry90\\t(\\fry360)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”,x,y+13,x+15,y+14)

  • \\an5 –> this is the alignment
  • \\org(%d,%d) is the origin point, usually use for the center pivot for spinning, defines by x,y
  • \\pos(%d,%d) is the coordinates position, defines by x+15,y+14
  • \\fry90 is tags for rotating the character in y axis as much as 90 degrees beforehand as a starting point
  • \\t(\\fry360) is for rotating the characters to 360 degrees from its starting point (which is 90 degrees) in whole line duration from line start time till line end time
  • {\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0} is the code for a heart shape, you could preview and edit or even make your own shape  in assdraw
  • l.start_time = line.start_time -65 +br*10, means the line will start at the minus 0.65 second,  from the original start time then add by 10 times the ‘br’ or the counter of characters, example if the starting time is 05.00, the text is AGNA then the results are: for A is 05.00 – 0.65 + (1)*10 = 04.45 and for N is 05.00 – 0.65 + (3)*10 = 04.65
  • l.end_time = line.start_time + br*10 -15 same as above just with differents calculation

Next lines,  wait up, you want to make a heart appears spinning then stay put until the effects kicks in right? well if do it in one command line it is pretty hard and trickery, but if you separate it into 2 parts which are coming spinning (the previous set of line) and staying put(the next set of lines), so you’ll get it done more easy. S0 that’s what is the next set of line are about

l.text = string.format(“{\\an5\\org(%d,%d)\\pos(%d,%d)}{\\p1}m -4 -9 b -3 -9 -4 -9 -4 -9 b -4 -9 -4 -9 -4 -9 b -9 -13 -12 -11 -13 -9 b -15 -6 -11 -1 -8 2 b -8 2 -6 4 -4 6 b -2 4 0 2 0 2 b 3 -1 7 -6 5 -9 b 4 -11 1 -13 -4 -9 {\\p0}”,x,y+13,x+15,y+14)
l.start_time = line.start_time + br*10 -15
l.end_time = line.start_time + syl.start_time/10

Pay attention to the  line start time, it’s pratically collide with the previous line end time, why you ask? That’s the trick, to do the effects mentioned before, we use this set of command line as the staying put part. To trick the human eyes so the lines appears in continues set, we just have to make the staying part start’s time collide with the spinning’s end time. Easy.

It seems that I have written quite much. So I decide to break this tutorials into 2-3 parts. Wait for it.

p.s. if you edit lua just open it with notepad, and if you want to write some notes in your lua and not ruining your commands line, just use a double dash ( — ) before writting your notes.

p.p.s if you want to know more about lua here’s the link http://www.lua.org/