Jumping Blob

From Aegisub Wiki

Jump to: navigation, search

Jumping Blob v1.5 by ai-chan


--[[ Copyright (c) 2006, ai-chan. All rights reserved.]]

include("karaskel-adv.lua")

name = "Jumping blob effect v1.5"

description = "Blob jumping over syllables. Highly configurable + able to work with existing karaoke effect (as long as there is no big movement)"

configuration  = {
	[1] = {
		name = "workstyle";
		kind = "style";
		label = "Line style";
		hint = "Only apply the effect to lines with this style. Empty means apply to all lines.";
		default = ""
	},
	[2] = {
		name = "blobstyle";
		kind = "style";
		label = "Blob style";
		hint = "Style to apply to the blob. Empty means use the same style as the line.";
		default = ""
	},
	[3] = {
		name = "blob";
		kind = "text";
		label = "The Blob";
		hint = "The blob. Enter anything: a character, a drawing tag etc.\nRecommended: shape/symbol that looks the same even after being rotated 180 degrees";
		default = "{\\p2\\shad0}m 10 20 b 16 20 20 16 20 10 b 20 4 16 0 10 0 2 0 0 6 0 10 b 0 16 4 20 10 20{\\p0}"
	},
	[4] = {
		name = "dist";
		kind = "int";
		label = "Blob hover distance";
		hint = "The distance from the blob to the top of the lines";
		default = "2"
	},
	[5] = {
		name = "compensationx";
		kind = "int";
		label = "Origin adjustment X";
		hint = "Depending on what character/shape and style you use as the blob, adjust this value to get smooth and natural jumps.";
		default = "0"
	},
	[6] = {
		name = "compensationy";
		kind = "int";
		label = "Origin adjustment Y";
		hint = "Depending on what character/shape and style you use as the blob, adjust this value to get smooth and natural jumps.";
		default = "0"
	},
	[7] = {
		name = "assistmode";
		kind = "bool";
		label = "Assist mode (for the two fields above)";
		hint = "In assist mode, the blob and its 180-degrees rotated copy are displayed on screen. \nAdjust 'Origin adjustment' X & Y until the two copies perfectly overlap each other.";
		default = false
	},
	[8] = {
		name = "fadein";
		kind = "int";
		label = "Fade-in";
		hint = "Blob fade in duration in positive milliseconds";
		min = "0";
		default = "500"
	},
	[9] = {
		name = "fadeout";
		kind = "int";
		label = "Fade-out";
		hint = "Blob fade out duration in positive milliseconds";
		min = "0";
		default = "500"
	},
	[10] = {
		name = "leadin";
		kind = "int";
		label = "Lead-in";
		hint = "Blob lead in duration in positive milliseconds";
		min = "0";
		default = "250"
	},
	[11] = {
		name = "leadout";
		kind = "int";
		label = "Lead-out";
		hint = "Blob lead out duration in positive milliseconds";
		min = "0";
		default = "250"
	},
	[12] = {
		name = "use_own_center";
		kind = "bool";
		label = "Use custom line center coordinate (specify below)";
		hint = "If you use /pos to position your lines, this script needs to know the center of those lines for calculation.";
		default = false
	},
	[13] = {
		name = "center_x";
		kind = "int";
		label = "Center X";
		hint = "X coordinate of line center.";
		default = "0"
	},
	[14] = {
		name = "center_y";
		kind = "int";
		label = "Center Y";
		hint = "Y coordinate of line center.";
		default = "0"
	}
}

-- Mandatory values
version, kind= 3, 'basic_ass'

function do_syllable(meta, styles, config, line, syl)
  	local res = {n=0}
  	duration = syl.end_time - syl.start_time
  	line.history.lastsyl = 0
  	if trim(syl.text_stripped) == "" then
		line.history.dur = line.history.dur + duration
		return res
  	end
  	line.history.lastsyl = 1

  	l = copy_line(line)
	l.style = config.bstyle
  	l.end_time = line.start_time + syl.end_time/10 - duration/10
	posx = config.xaxis + syl.center
	yorg = config.yaxis - config.compensationy
  	if line.history.posx then
		xorg = (posx + line.history.posx)/2 + config.compensationx
   		lastdur = line.history.dur/10
   		l.start_time = line.start_time + syl.start_time/10 - lastdur
   		ext = do_jump(xorg, yorg, line.history.posx, config.yaxis, line.history.dur, -180)
  	else
   		xorg = posx - syl.width
   		ext = string.format("\\fad(%d,0)%s", config.fadein, do_jump(xorg, yorg, xorg, config.yaxis - syl.width, config.leadin, -90))
   		l.start_time = line.start_time + syl.start_time/10 - config.leadin/10
		if l.start_time < 0 then 
			l.start_time = 0
		end
  	end
  	l.text = string.format("{\\an5%s}%s", ext, config.blob)
	l.name = string.format("%s_blob", line.style)
  	table.insert(res, l)

  	line.history.posx = posx
  	line.history.dur = duration
  	return res 
end

function do_jump(xorg, yorg, xblob, yblob, dur, angle)
  	return string.format("\\org(%d,%d)\\pos(%d,%d)\\t(0,%d,\\frz%d)", xorg, yorg, xblob, yblob, dur, angle)
end

function do_line(meta, styles, config, line)
	if config.workstyle == "" or config.workstyle == line.style then
		an = styles[line.style].align

		if config.use_own_center then
			linecenter_y = config.center_y
			linecenter_x = config.center_x
		else
			if an < 4 then
				linecenter_y = meta.res_y - styles[line.style].margin_v - line.height/2
			elseif an < 7 then
				linecenter_y = meta.res_y/2
			else
				linecenter_y = styles[line.style].margin_v + line.height/2
			end	
			if an == 2 or an == 5 or an == 8 then
				linecenter_x = (meta.res_x - styles[line.style].margin_r + styles[line.style].margin_l)/2
			elseif an == 1 or an == 4 or an == 7 then
				linecenter_x = styles[line.style].margin_l + (line.centerright - line.centerleft)/2
			else
				linecenter_x = meta.res_x - (line.centerright - line.centerleft)/2 - styles[line.style].margin_r
			end
		end
		config.yaxis = linecenter_y - line.height*3/4 - config.dist + config.compensationy
		config.xaxis = linecenter_x - (line.centerright - line.centerleft)/2
		
		if config.blobstyle == "" then
			config.bstyle = line.style
		else
			config.bstyle = config.blobstyle			
		end

		if config.fadein < 0 then 
			config.fadein = 0
		end

		if config.fadeout < 0 then 
			config.fadeout = 0
		end

		if config.leadin < 0 then 
			config.leadin = 0
		end

		if config.leadout < 0 then 
			config.leadout = 0
		end

		local result = {n=0}
		line.history = {n=0}
		line.history.dur = 0
		lastsyl = 0
		table.insert(result,line)

		if config.assistmode then
			local l = copy_line(line)
			l.style = config.bstyle
			l.name = string.format("%s_blob_assist", line.style)
			l.text = string.format("{\\an5\\pos(%d,%d)\\bord0\\shad0\\c&H000000&\\p1}m 0 0 l %d 0 %d 1 0 1{\\p0}", config.xaxis + line.width/2, config.yaxis, line.width, line.width)
			table.insert(result,l)
			local l = copy_line(l)
			l.text = string.format("{\\an5\\pos(%d,%d)}%s", config.xaxis, config.yaxis, config.blob)
			table.insert(result,l)
			local l = copy_line(l)
			l.text = string.format("{\\an5\\pos(%d,%d)\\org(%d,%d)\\frz-180}%s", config.xaxis, config.yaxis, config.xaxis + config.compensationx, config.yaxis - config.compensationy, config.blob)
			table.insert(result,l)
			--return result
		end
		for i = 1, line.karaoke.n-1 do
			local out = do_syllable(meta, styles, config, line, line.karaoke[i])
			for j = 1, out.n do
				table.insert(result, out[j])
			end
			if line.history.lastsyl == 1 then
				lastsyl = i
			end
		end
		if line.history.posx then
			local l = copy_line(line)
			l.style = config.bstyle
			xorg = config.xaxis + line.karaoke[lastsyl].left + line.karaoke[lastsyl].width
			ext = string.format("\\fad(0,%d)%s", config.fadeout, do_jump(xorg, config.yaxis + line.karaoke[lastsyl].height/2, line.history.posx, config.yaxis, config.leadout + line.history.dur, -90))
			l.start_time = line.start_time + line.karaoke[lastsyl].start_time/10
			l.end_time = l.start_time + line.history.dur/10 + config.leadout/10
			l.text = string.format("{\\an5%s}%s", ext, config.blob)
			l.name = string.format("%s_blob", line.style)
			table.insert(result,l)
		end
		return result
	else
		return { n=1, [1]=line }
	end

end
Personal tools