diff --git a/README.md b/README.md index f4152fce597c4ca2a80ad4560c1a2079cd2ac998..927a94e687680938f0a3da9eee82c6be1a91a9c1 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,5 @@ TL;DR: paste this line in Aegisub: `Comment: 0,0:00:00.00,0:00:00.00,Default,,0, ## Organization Files are organized in subfolders by theme (e.g. jump, shape...). Each theme subfolder has a corresponding lua file in its parent folder, which imports all of the files in the theme subfolder if imported. -This file also defines a table regrouping the subfolder's contents, acting as a sort of package, to organize everything into a tree. \ No newline at end of file +This file also defines a table regrouping the subfolder's contents, acting as a sort of package, to organize everything into a tree. +The root of this tree is the `bakafx` table in the "all.lua" file. \ No newline at end of file diff --git a/all.lua b/all.lua index d799f64ff567cfb2574ffc49666c641951def2d8..fd809bd26176e97fd98c15183e8344c038d7fe64 100644 --- a/all.lua +++ b/all.lua @@ -1,2 +1,10 @@ require "baka-fx.util" -require "baka-fx.jump" \ No newline at end of file +require "baka-fx.jump" +require "baka-fx.shape" + +bakafx = +{ + util = util, + jump = jump, + shape = shape +} \ No newline at end of file diff --git a/jump/jump_frz.lua b/jump/jump_frz.lua index 5b39694874e272df83659bc87360e5791e6fc2af..03fdebebf68e896ea46480710411bf47871fca8f 100644 --- a/jump/jump_frz.lua +++ b/jump/jump_frz.lua @@ -26,11 +26,12 @@ vertical position ^ | - height - x-----x - | / \ - base_y - x x - | ' ' ' ' - +------0-t1---t2-dur---> time + base_y ++ height - x-----x + | / \ + base_y - x x + | ' ' ' ' + +-------0-t1---t2-dur---> time --]] function jump_frz(base_y, height, dur, ...) local radius = 100000 diff --git a/shape.lua b/shape.lua new file mode 100644 index 0000000000000000000000000000000000000000..13b66cd74afd81ad26408d9f14d303b9161c6d9c --- /dev/null +++ b/shape.lua @@ -0,0 +1,8 @@ +require "baka-fx.shape.potato" +require "baka-fx.shape.circle" + +shape = +{ + potato = potato, + circle = circle +} \ No newline at end of file diff --git a/shape/circle.lua b/shape/circle.lua new file mode 100644 index 0000000000000000000000000000000000000000..b323cb60e9f0f9cf1fa47c6328a7bf4a6bf86b7f --- /dev/null +++ b/shape/circle.lua @@ -0,0 +1,63 @@ +--[[ +[Description] +Draws an approximation of a circle with bezier curves. + +[Usage] +circle(radius) +circle(radius, keypoints) +circle(radius, keypoints, clockwise) + +[Arguments] +radius: radius of the circle, in pixels +keypoints: number of keypoints used (default 8) +clockwise: drawing direction, boolean (default false) + +[Notes] +This function does not include drawing tags, only vector commands. +--]] +function circle(radius, keypoints, clockwise) + keypoints = keypoints or 8 + + local halfpi = math.pi / 2 + local mult = clockwise and -1 or 1 + local ctrl = mult * 4/3 * math.tan(math.pi / (2 * keypoints)) * radius + + local points = {} + + for i = 1, keypoints do + local a = mult * i / keypoints * 2 * math.pi + local x = radius * math.cos(a) + local y = radius * math.sin(a) + + points[i] = { a = a, x = x, y = y } + end + + points[keypoints+1] = points[1] + + for i = 1, keypoints do + local p = points[i] + points[i+1].h1 = + { + x = p.x + ctrl * math.cos(p.a + halfpi), + y = p.y + ctrl * math.sin(p.a + halfpi) + } + points[i].h2 = + { + x = p.x - ctrl * math.cos(p.a + halfpi), + y = p.y - ctrl * math.sin(p.a + halfpi) + } + end + + points[1].h1 = points[keypoints+1].h1 + + local str = "m " .. points[keypoints].x .. " " .. points[keypoints].y .. " " + + for i = 1, keypoints do + local p = points[i] + str = str .. "b " .. p.h1.x .. " " .. p.h1.y .. " " + .. p.h2.x .. " " .. p.h2.y .. " " + .. p.x .. " " .. p.y .. " " + end + + return str + end \ No newline at end of file diff --git a/shape/potato.lua b/shape/potato.lua new file mode 100644 index 0000000000000000000000000000000000000000..af1b5c6fd79aadd8d37aaa88d06af0f0b4911891 --- /dev/null +++ b/shape/potato.lua @@ -0,0 +1,79 @@ +--[[ +[Description] +Draws a vector potato, based on a circle approximation with bezier curves, +with variations to the key and control points to make bumps. + +[Usage] +potato(radius) +potato(radius, rvar) +potato(radius, rvar, avar) +potato(radius, rvar, avar, hlvar) +potato(radius, rvar, avar, hlvar, havar) +potato(radius, rvar, avar, hlvar, havar, keypoints) +potato(radius, rvar, avar, hlvar, havar, keypoints, clockwise) + +[Arguments] +radius: base radius of the potato, in pixels +rvar: radius variation, between 0 and 1 (default 0) +avar: keypoint angle variation, in radians (default 0) +hlvar: control point distance variation, between 0 and 1 (default 0) +havar: control point angle variation, in radians (default 0) +keypoints: number of keypoints used (default 8) +clockwise: drawing direction, boolean (default false) + +[Notes] +(rvar, avar, hlvar, havar, keypoints) += (0.2, math.pi/18, 0.2, math.pi/12, 8) +Makes a pretty good potato. +This function does not include drawing tags, only vector commands. +--]] +function potato(radius, rvar, avar, hlvar, havar, keypoints, clockwise) + keypoints = keypoints or 8 + havar = havar or 0 + hlvar = hlvar or 0 + avar = avar or 0 + rvar = rvar or 0 + + local halfpi = math.pi / 2 + local hbase = 4/3 * math.tan(math.pi / (2 * keypoints)) + local points = {} + local mult = clockwise and -1 or 1 + + for i = 1, keypoints do + r = radius + (2 * math.random() - 1) * rvar * radius + a = i / keypoints * 2 * math.pi + (2 * math.random() - 1) * avar + local x = r * math.cos(a) + local y = r * math.sin(a) + points[i] = {r = r, a = a, x = x, y = y} + end + + points[keypoints+1] = points[1] + + for i = 1, keypoints do + local p = points[i] + + local hangle = (2 * math.random() - 1) * havar + local l = hbase * r + (2 * math.random() - 1) * hlvar * hbase * r + points[i+1].h1 = {l = l, a = hangle, + x = p.x + mult * l * math.cos(p.a + halfpi + hangle), + y = p.y + mult * l * math.sin(p.a + halfpi + hangle)} + + l = hbase * r + (2 * math.random() - 1) * hlvar * hbase * r + points[i].h2 = {l = l, a = hangle, + x = p.x - mult * l * math.cos(p.a + halfpi + hangle), + y = p.y - mult * l * math.sin(p.a + halfpi + hangle)} + end + + points[1].h1 = points[keypoints+1].h1 + + local str = "m " .. points[keypoints].x .. " " .. points[keypoints].y .. " " + + for i = 1, keypoints do + local p = points[i] + str = str .. "b " .. p.h1.x .. " " .. p.h1.y .. " " + .. p.h2.x .. " " .. p.h2.y .. " " + .. p.x .. " " .. p.y .. " " + end + + return str + end \ No newline at end of file