169 lines
No EOL
3.7 KiB
Lua
169 lines
No EOL
3.7 KiB
Lua
local default_G = {}
|
|
for k, v in pairs(_G) do
|
|
table.insert(default_G, k)
|
|
end
|
|
|
|
local easelib = require 'easelib'
|
|
|
|
dropdown = require 'dropdown'
|
|
graph = require 'graph'
|
|
|
|
-- utils
|
|
|
|
function mix(x, y, a)
|
|
return x * (1 - a) + y * a
|
|
end
|
|
|
|
-- 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
|
|
|
|
padding = 6
|
|
margin = 4
|
|
|
|
-- slider
|
|
|
|
mixpoint = 0.5
|
|
oldmixpoint = 0.5
|
|
local mixpointtimer = 0 -- easter egg thing
|
|
local mixpointspin = 0
|
|
|
|
-- rendering
|
|
|
|
function love.load()
|
|
dropdown.createDropdowns()
|
|
end
|
|
|
|
function love.update(dt)
|
|
graph.update(dt)
|
|
|
|
-- slider
|
|
mixpointtimer = mix(mixpointtimer + math.abs(mixpoint - oldmixpoint), 0, math.min(dt * 8))
|
|
oldmixpoint = mix(oldmixpoint, mixpoint, math.min(dt * 20, 1))
|
|
|
|
if mixpointtimer > 2 then
|
|
mixpointtimer = mixpointtimer - 2
|
|
mixpointspin = mixpointspin + 4
|
|
end
|
|
|
|
mixpointspin = mix(mixpointspin, 0, dt * 3)
|
|
|
|
dropdown.update(dt)
|
|
end
|
|
|
|
function love.draw()
|
|
mode = dropdown.kget('mode').selected
|
|
local sw, sh = love.graphics.getDimensions()
|
|
local mx, my = love.mouse.getPosition()
|
|
|
|
love.graphics.setColor(0.09, 0.09, 0.12, 1)
|
|
love.graphics.rectangle('fill', 0, 0, sw, sh)
|
|
love.graphics.setColor(0.08, 0.08, 0.1, 1)
|
|
love.graphics.rectangle('line', 0, 0, sw, sh)
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
love.graphics.print('Box of Eases by oatmealine', padding, sh - love.graphics.getFont():getHeight() - padding)
|
|
|
|
-- sliders
|
|
-- yeah we do a lil' hardcoding
|
|
|
|
if mode == 2 then
|
|
local x, y, w, h = padding, padding * 2 + love.graphics.getFont():getHeight() + margin, 128, 32
|
|
|
|
love.graphics.setColor(0.7, 0.7, 0.7, 0.4)
|
|
love.graphics.line(x, y + h/2, x + w, y + h/2)
|
|
|
|
local sx, sy = x + w * oldmixpoint, y + h/2
|
|
local ssize = h * 0.5
|
|
|
|
love.graphics.push()
|
|
|
|
love.graphics.translate(sx, sy)
|
|
love.graphics.rotate((mixpoint - oldmixpoint) * 4 + mixpointspin * math.pi * 2)
|
|
|
|
love.graphics.setColor(0, 0, 0, 1)
|
|
if mx > sx - ssize/2 and mx < sx + ssize/2 and my > sy - ssize/2 and my < sy + ssize/2 and dropdown.openDropdown == 0 then
|
|
love.graphics.setColor(0.2, 0.2, 0.3, 1)
|
|
end
|
|
love.graphics.rectangle('fill', -ssize/2, -ssize/2, ssize, ssize)
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
love.graphics.rectangle('line', -ssize/2, -ssize/2, ssize, ssize)
|
|
|
|
love.graphics.rotate((mixpoint - oldmixpoint) * -2)
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
love.graphics.printf(math.floor(mixpoint * 100)/100, -ssize * 6, ssize - 2, ssize * 12, 'center')
|
|
|
|
love.graphics.pop()
|
|
|
|
if mx > x and mx < x + w and my > y and my < y + h and love.mouse.isDown(1) and dropdown.openDropdown == 0 then
|
|
mixpoint = (mx - x) / w
|
|
dropdown.createDropdowns()
|
|
end
|
|
end
|
|
|
|
-- dropdowns
|
|
dropdown.render()
|
|
|
|
-- graph
|
|
graph.render()
|
|
end
|
|
|
|
function love.mousepressed(x, y, m)
|
|
if dropdown.mousepressed(x, y, m) then return end
|
|
end
|
|
|
|
function love.mousereleased(x, y, m)
|
|
if dropdown.mousereleased(x, y, m) then return end
|
|
end
|
|
|
|
function love.wheelmoved(x, y)
|
|
if y == 0 then return end
|
|
|
|
if dropdown.wheelmoved(x, y) then return end
|
|
end
|
|
|
|
function love.keypressed(key)
|
|
if key == 'f6' then -- print all globals
|
|
for k, v in pairs(_G) do
|
|
for _, g in ipairs(default_G) do
|
|
if g == k then goto continue end
|
|
end
|
|
print(k, v)
|
|
::continue::
|
|
end
|
|
end
|
|
end |