Skip to content
Extraits de code Groupes Projets
Valider 057ba5b0 rédigé par ultrakatiz's avatar ultrakatiz
Parcourir les fichiers

added shape folder, circle and potato, and bakafx table in all.lua

parent a8e93126
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -17,3 +17,4 @@ 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.
The root of this tree is the `bakafx` table in the "all.lua" file.
\ No newline at end of file
require "baka-fx.util"
require "baka-fx.jump"
require "baka-fx.shape"
bakafx =
{
util = util,
jump = jump,
shape = shape
}
\ No newline at end of file
......@@ -26,11 +26,12 @@ vertical
position
^
|
height - x-----x
base_y
+ height - x-----x
| / \
base_y - x x
| ' ' ' '
+------0-t1---t2-dur---> time
+-------0-t1---t2-dur---> time
--]]
function jump_frz(base_y, height, dur, ...)
local radius = 100000
......
require "baka-fx.shape.potato"
require "baka-fx.shape.circle"
shape =
{
potato = potato,
circle = circle
}
\ No newline at end of file
--[[
[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
--[[
[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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter