2021-09-17 22:34:16 +00:00
|
|
|
local self = {}
|
|
|
|
|
|
|
|
local quality = 256
|
|
|
|
local graph = {}
|
|
|
|
|
2021-09-17 23:15:31 +00:00
|
|
|
self.touchtimer = 0
|
|
|
|
|
2021-09-17 23:31:20 +00:00
|
|
|
local timer = 0
|
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
function self.update(dt)
|
|
|
|
for i = 1, quality do
|
|
|
|
local a = (i - 1) / (quality - 1)
|
|
|
|
if not graph[i] then
|
2021-09-17 22:44:26 +00:00
|
|
|
graph[i] = ease.ease(a)
|
2021-09-17 22:34:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
for i,v in ipairs(graph) do
|
|
|
|
local a = (i - 1) / (quality - 1)
|
2021-09-17 22:44:26 +00:00
|
|
|
local b = ease.ease(a)
|
2021-09-17 22:34:16 +00:00
|
|
|
if minEase then
|
|
|
|
b = b / 2 + 0.5
|
|
|
|
end
|
|
|
|
graph[i] = mix(v, b, math.min(dt * 18, 1))
|
2021-09-18 00:48:03 +00:00
|
|
|
if graph[i] ~= graph[i] then -- is nan
|
|
|
|
graph[i] = b
|
|
|
|
end
|
2021-09-17 22:34:16 +00:00
|
|
|
end
|
2021-09-17 23:15:31 +00:00
|
|
|
self.touchtimer = mix(self.touchtimer, 0, dt * 2)
|
2021-09-17 23:31:20 +00:00
|
|
|
|
|
|
|
-- lots of math just for the timer
|
|
|
|
-- may need to abstract this out, somehow
|
|
|
|
-- todo
|
|
|
|
local sw, sh = love.graphics.getDimensions()
|
|
|
|
local csize = 10 -- preview point size
|
|
|
|
local size = math.min((sw - outerpadding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + dropdownWidth + padding), sh - outerpadding * 2 - padding * 3 - csize)
|
|
|
|
local x, y, w, h = sw - outerpadding - size, outerpadding, size, size
|
|
|
|
local mx, my = love.mouse.getPosition()
|
|
|
|
|
|
|
|
if not (love.mouse.isDown(1) and mx > x and mx < x + w and my > y and my < y + h) then
|
2021-09-18 10:53:57 +00:00
|
|
|
timer = (timer + dt * (slider.kvalue('bpm')/120)) % 2
|
2021-09-17 23:31:20 +00:00
|
|
|
else
|
|
|
|
timer = mix(timer, (mx - x) / w, dt * 14)
|
|
|
|
end
|
2021-09-17 22:34:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function self.render()
|
|
|
|
local sw, sh = love.graphics.getDimensions()
|
|
|
|
|
|
|
|
if mode == 1 or mode == 2 then
|
|
|
|
local csize = 10 -- preview point size
|
2021-09-17 22:51:42 +00:00
|
|
|
local size = math.min((sw - outerpadding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + dropdownWidth + padding), sh - outerpadding * 2 - padding * 3 - csize)
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:51:42 +00:00
|
|
|
local x, y, w, h = sw - outerpadding - size, outerpadding, size, size
|
2021-09-17 22:34:16 +00:00
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.rectangle('line', x, y, w, h)
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
-- grid
|
|
|
|
love.graphics.setColor(0.2, 0.2, 0.4, 0.2)
|
|
|
|
local gridsize = 64
|
|
|
|
for gx = 1, gridsize - 2 do
|
|
|
|
love.graphics.line(x + margin + gx * w/gridsize, y + margin, x + margin + gx * w/gridsize, y + h - margin)
|
|
|
|
end
|
|
|
|
for gy = 1, gridsize - 2 do
|
|
|
|
love.graphics.line(x + margin, y + margin + gy * h/gridsize, x + w - margin, y + margin + gy * h/gridsize)
|
|
|
|
end
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
-- mixease point
|
2021-09-18 00:05:13 +00:00
|
|
|
if mode == 2 and slider.kget('mix') then
|
2021-09-17 23:15:31 +00:00
|
|
|
love.graphics.setColor(1, 1, 1, 0.2 + self.touchtimer * 0.6)
|
2021-09-18 00:05:13 +00:00
|
|
|
love.graphics.line(x + margin + slider.kvalue('mix') * w, y, x + margin + slider.kvalue('mix') * w, y + h)
|
2021-09-17 22:34:16 +00:00
|
|
|
end
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
-- preview point
|
2021-09-17 23:31:20 +00:00
|
|
|
local t = timer % 1
|
2021-09-17 22:34:16 +00:00
|
|
|
love.graphics.setColor(0.4, 0.4, 1, 0.4)
|
|
|
|
love.graphics.line(x + margin + t * w, y, x + margin + t * w, y + h)
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
-- y = 0 point
|
|
|
|
-- todo: this will break with eases that dont have the first point at y0
|
|
|
|
local py = graph[1]
|
|
|
|
love.graphics.setColor(0.7, 0.7, 0.7, 0.4 * (1 - math.abs(py - 0.5) / 0.5))
|
|
|
|
love.graphics.line(x, y + h - py * h, x + w, y + py * h)
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
-- polygone
|
|
|
|
-- this isnt done with a polygon because else itd waste a Bunch of ram and i kinda, dont want to do that?
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
local last = graph[1] or 0
|
|
|
|
for gx = 1, quality - 1 do
|
|
|
|
local a = gx/quality
|
|
|
|
local b = graph[gx + 1] or 0
|
|
|
|
local px, py = x + margin + gx * ((w - margin)/quality), y + h - margin - b * (h - margin * 2)
|
|
|
|
local ox, oy = x + margin + (gx - 1) * ((w - margin)/quality), y + h - margin - last * (h - margin * 2)
|
|
|
|
if math.abs(b - last) < 1 then
|
|
|
|
love.graphics.line(ox, oy, px, py)
|
|
|
|
end
|
|
|
|
last = b
|
|
|
|
end
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
-- preview
|
|
|
|
love.graphics.setColor(1, 1, 1, 0.2)
|
|
|
|
love.graphics.line(x + margin, y + h + padding * 2 + csize/2, x + w - margin, y + h + padding * 2 + csize/2)
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
love.graphics.setColor(0.4, 0.4, 1, 1)
|
2021-09-17 22:44:26 +00:00
|
|
|
local a1 = ease.ease(t)
|
|
|
|
local a2 = ease.ease(math.max(math.min(t - 0.1, 1), 0))
|
2021-09-17 22:34:16 +00:00
|
|
|
local da = a1
|
2021-09-17 23:31:20 +00:00
|
|
|
if timer % 2 > 1 and math.floor(ease.ease(0) + 0.5) ~= math.floor(ease.ease(1) + 0.5) then
|
2021-09-17 22:34:16 +00:00
|
|
|
da = 1 - da
|
|
|
|
end
|
|
|
|
if minEase then
|
|
|
|
da = da / 2 + 0.5
|
|
|
|
end
|
2021-09-17 22:38:04 +00:00
|
|
|
|
2021-09-17 22:34:16 +00:00
|
|
|
love.graphics.ellipse('fill', x + margin + (w - margin * 2) * da, y + h + padding * 2 + csize/2, csize * (1 + math.min(math.abs(a1 - a2), 3) * 1.2), csize)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return self
|