create util & ease libs
This commit is contained in:
parent
63b1a08df8
commit
f73073a9c6
5 changed files with 55 additions and 53 deletions
16
dropdown.lua
16
dropdown.lua
|
@ -70,40 +70,38 @@ function self.createDropdowns()
|
||||||
x = padding + 128 + padding,
|
x = padding + 128 + padding,
|
||||||
y = padding,
|
y = padding,
|
||||||
width = 128,
|
width = 128,
|
||||||
options = skeys(eases),
|
options = skeys(ease.eases),
|
||||||
name = 'ease1'
|
name = 'ease1'
|
||||||
})
|
})
|
||||||
ease = eases[d[dropdownId].options[d[dropdownId].selected]].f
|
ease.ease = ease.eases[d[dropdownId].options[d[dropdownId].selected]].f
|
||||||
elseif d[dropdownId].selected == 2 then -- mix eases
|
elseif d[dropdownId].selected == 2 then -- mix eases
|
||||||
insertDropdown(d, {
|
insertDropdown(d, {
|
||||||
x = padding + 128 + padding,
|
x = padding + 128 + padding,
|
||||||
y = padding,
|
y = padding,
|
||||||
width = 128,
|
width = 128,
|
||||||
options = skeys(eases),
|
options = skeys(ease.eases),
|
||||||
name = 'ease1'
|
name = 'ease1'
|
||||||
})
|
})
|
||||||
insertDropdown(d, {
|
insertDropdown(d, {
|
||||||
x = padding + 128 + padding + 128 + padding,
|
x = padding + 128 + padding + 128 + padding,
|
||||||
y = padding,
|
y = padding,
|
||||||
width = 128,
|
width = 128,
|
||||||
options = skeys(eases),
|
options = skeys(ease.eases),
|
||||||
name = 'ease2'
|
name = 'ease2'
|
||||||
})
|
})
|
||||||
ease = mixEase(eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]].f, eases[d[dropdownId].options[d[dropdownId].selected]].f, mixpoint)
|
ease.ease = ease.mixEase(ease.eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]].f, ease.eases[d[dropdownId].options[d[dropdownId].selected]].f, mixpoint)
|
||||||
elseif d[dropdownId].selected == 3 then -- create eases
|
elseif d[dropdownId].selected == 3 then -- create eases
|
||||||
insertDropdown(d, {
|
insertDropdown(d, {
|
||||||
x = padding + 128 + padding,
|
x = padding + 128 + padding,
|
||||||
y = padding,
|
y = padding,
|
||||||
width = 128,
|
width = 128,
|
||||||
options = skeys(eases),
|
options = skeys(ease.eases),
|
||||||
name = 'ease1'
|
name = 'ease1'
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
dropdowns = d
|
dropdowns = d
|
||||||
minEase = (self.kselected('ease1') and eases[self.kselected('ease1')].min == -1) or (self.kselected('ease2') and eases[self.kselected('ease2')].min == -1)
|
minEase = (self.kselected('ease1') and ease.eases[self.kselected('ease1')].min == -1) or (self.kselected('ease2') and ease.eases[self.kselected('ease2')].min == -1)
|
||||||
|
|
||||||
return ease, minEase
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function self.update(dt)
|
function self.update(dt)
|
||||||
|
|
38
ease.lua
Normal file
38
ease.lua
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
local self = {}
|
||||||
|
|
||||||
|
local easelib = require 'easelib'
|
||||||
|
|
||||||
|
function self.mixEase(e1, e2, point)
|
||||||
|
if not point then point = 0.5 end
|
||||||
|
|
||||||
|
return function(a)
|
||||||
|
if a < point then
|
||||||
|
return e1(a / point) * point
|
||||||
|
else
|
||||||
|
return e2((a - point) / (1 - point)) * (1 - point) + point
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.eases = {}
|
||||||
|
for i,v in pairs(easelib) do
|
||||||
|
local min = 0
|
||||||
|
|
||||||
|
local q = 10
|
||||||
|
for i = 0, q do
|
||||||
|
local s = v[2](i / q)
|
||||||
|
if s < 0 then min = -1 end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.eases[v[1]] = {
|
||||||
|
f = v[2],
|
||||||
|
max = 1,
|
||||||
|
min = min,
|
||||||
|
i = i
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
self.ease = nil
|
||||||
|
self.minEase = false
|
||||||
|
|
||||||
|
return self
|
10
graph.lua
10
graph.lua
|
@ -7,12 +7,12 @@ function self.update(dt)
|
||||||
for i = 1, quality do
|
for i = 1, quality do
|
||||||
local a = (i - 1) / (quality - 1)
|
local a = (i - 1) / (quality - 1)
|
||||||
if not graph[i] then
|
if not graph[i] then
|
||||||
graph[i] = ease(a)
|
graph[i] = ease.ease(a)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i,v in ipairs(graph) do
|
for i,v in ipairs(graph) do
|
||||||
local a = (i - 1) / (quality - 1)
|
local a = (i - 1) / (quality - 1)
|
||||||
local b = ease(a)
|
local b = ease.ease(a)
|
||||||
if minEase then
|
if minEase then
|
||||||
b = b / 2 + 0.5
|
b = b / 2 + 0.5
|
||||||
end
|
end
|
||||||
|
@ -78,10 +78,10 @@ function self.render()
|
||||||
love.graphics.line(x + margin, y + h + padding * 2 + csize/2, x + w - margin, y + h + padding * 2 + csize/2)
|
love.graphics.line(x + margin, y + h + padding * 2 + csize/2, x + w - margin, y + h + padding * 2 + csize/2)
|
||||||
|
|
||||||
love.graphics.setColor(0.4, 0.4, 1, 1)
|
love.graphics.setColor(0.4, 0.4, 1, 1)
|
||||||
local a1 = ease(t)
|
local a1 = ease.ease(t)
|
||||||
local a2 = ease(math.max(math.min(t - 0.1, 1), 0))
|
local a2 = ease.ease(math.max(math.min(t - 0.1, 1), 0))
|
||||||
local da = a1
|
local da = a1
|
||||||
if love.timer.getTime() % 2 < 1 and math.floor(ease(0) + 0.5) ~= math.floor(ease(1) + 0.5) then
|
if love.timer.getTime() % 2 < 1 and math.floor(ease.ease(0) + 0.5) ~= math.floor(ease.ease(1) + 0.5) then
|
||||||
da = 1 - da
|
da = 1 - da
|
||||||
end
|
end
|
||||||
if minEase then
|
if minEase then
|
||||||
|
|
41
main.lua
41
main.lua
|
@ -3,52 +3,15 @@ for k, v in pairs(_G) do
|
||||||
table.insert(default_G, k)
|
table.insert(default_G, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
local easelib = require 'easelib'
|
ease = require 'ease'
|
||||||
|
|
||||||
dropdown = require 'dropdown'
|
dropdown = require 'dropdown'
|
||||||
graph = require 'graph'
|
graph = require 'graph'
|
||||||
|
|
||||||
-- utils
|
require 'util' -- exports into global table
|
||||||
|
|
||||||
function mix(x, y, a)
|
|
||||||
return x * (1 - a) + y * a
|
|
||||||
end
|
|
||||||
|
|
||||||
-- eases
|
-- eases
|
||||||
|
|
||||||
function mixEase(e1, e2, point)
|
|
||||||
if not point then point = 0.5 end
|
|
||||||
|
|
||||||
return function(a)
|
|
||||||
if a < point then
|
|
||||||
return e1(a / point) * point
|
|
||||||
else
|
|
||||||
return e2((a - point) / (1 - point)) * (1 - point) + point
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
eases = {}
|
|
||||||
for i,v in pairs(easelib) do
|
|
||||||
local min = 0
|
|
||||||
|
|
||||||
local q = 10
|
|
||||||
for i = 0, q do
|
|
||||||
local s = v[2](i / q)
|
|
||||||
if s < 0 then min = -1 end
|
|
||||||
end
|
|
||||||
|
|
||||||
eases[v[1]] = {
|
|
||||||
f = v[2],
|
|
||||||
max = 1,
|
|
||||||
min = min,
|
|
||||||
i = i
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
ease = nil
|
|
||||||
minEase = false
|
|
||||||
|
|
||||||
-- rendering constants
|
-- rendering constants
|
||||||
|
|
||||||
padding = 6
|
padding = 6
|
||||||
|
|
3
util.lua
Normal file
3
util.lua
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
function mix(x, y, a)
|
||||||
|
return x * (1 - a) + y * a
|
||||||
|
end
|
Loading…
Reference in a new issue