box-of-eases/main.lua

133 lines
3.3 KiB
Lua
Raw Normal View History

2021-09-17 22:25:14 +00:00
local default_G = {}
for k, v in pairs(_G) do
table.insert(default_G, k)
end
2021-09-17 22:44:26 +00:00
ease = require 'ease'
2021-09-17 19:24:26 +00:00
2021-09-17 22:34:16 +00:00
dropdown = require 'dropdown'
graph = require 'graph'
2021-09-17 19:24:26 +00:00
2021-09-17 22:44:26 +00:00
require 'util' -- exports into global table
2021-09-17 19:24:26 +00:00
-- rendering constants
2021-09-17 22:51:42 +00:00
padding = 14
outerpadding = 22
margin = 6
dropdownWidth = 106
2021-09-17 19:24:26 +00:00
2021-09-17 22:38:04 +00:00
-- slider
2021-09-17 22:34:16 +00:00
mixpoint = 0.5
oldmixpoint = 0.5
2021-09-17 19:24:26 +00:00
local mixpointtimer = 0 -- easter egg thing
local mixpointspin = 0
-- rendering
function love.load()
2021-09-17 22:25:14 +00:00
dropdown.createDropdowns()
2021-09-17 19:24:26 +00:00
end
function love.update(dt)
2021-09-17 22:34:16 +00:00
graph.update(dt)
2021-09-17 22:38:04 +00:00
2021-09-17 22:34:16 +00:00
-- slider
2021-09-17 19:24:26 +00:00
mixpointtimer = mix(mixpointtimer + math.abs(mixpoint - oldmixpoint), 0, math.min(dt * 8))
oldmixpoint = mix(oldmixpoint, mixpoint, math.min(dt * 20, 1))
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
if mixpointtimer > 2 then
mixpointtimer = mixpointtimer - 2
mixpointspin = mixpointspin + 4
end
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
mixpointspin = mix(mixpointspin, 0, dt * 3)
2021-09-17 22:38:04 +00:00
2021-09-17 22:25:14 +00:00
dropdown.update(dt)
2021-09-17 19:24:26 +00:00
end
function love.draw()
2021-09-17 22:34:16 +00:00
mode = dropdown.kget('mode').selected
2021-09-17 19:24:26 +00:00
local sw, sh = love.graphics.getDimensions()
local mx, my = love.mouse.getPosition()
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
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)
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
love.graphics.setColor(1, 1, 1, 1)
2021-09-17 22:51:42 +00:00
love.graphics.print('Box of Eases by oatmealine', outerpadding, sh - love.graphics.getFont():getHeight() - outerpadding)
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
-- sliders
-- yeah we do a lil' hardcoding
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
if mode == 2 then
2021-09-17 22:51:42 +00:00
local x, y, w, h = outerpadding, outerpadding * 2 + love.graphics.getFont():getHeight() + margin, dropdownWidth, 32
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
love.graphics.setColor(0.7, 0.7, 0.7, 0.4)
love.graphics.line(x, y + h/2, x + w, y + h/2)
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
local sx, sy = x + w * oldmixpoint, y + h/2
local ssize = h * 0.5
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
love.graphics.push()
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
love.graphics.translate(sx, sy)
love.graphics.rotate((mixpoint - oldmixpoint) * 4 + mixpointspin * math.pi * 2)
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
love.graphics.setColor(0, 0, 0, 1)
2021-09-17 22:34:16 +00:00
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
2021-09-17 19:24:26 +00:00
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)
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
love.graphics.rotate((mixpoint - oldmixpoint) * -2)
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(math.floor(mixpoint * 100)/100, -ssize * 6, ssize - 2, ssize * 12, 'center')
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
love.graphics.pop()
2021-09-17 22:38:04 +00:00
2021-09-17 22:34:16 +00:00
if mx > x and mx < x + w and my > y and my < y + h and love.mouse.isDown(1) and dropdown.openDropdown == 0 then
2021-09-17 19:24:26 +00:00
mixpoint = (mx - x) / w
2021-09-17 23:15:31 +00:00
graph.touchtimer = 1
2021-09-17 22:34:16 +00:00
dropdown.createDropdowns()
2021-09-17 19:24:26 +00:00
end
end
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
-- dropdowns
2021-09-17 22:25:14 +00:00
dropdown.render()
2021-09-17 22:38:04 +00:00
2021-09-17 19:24:26 +00:00
-- graph
2021-09-17 22:34:16 +00:00
graph.render()
2021-09-17 19:24:26 +00:00
end
function love.mousepressed(x, y, m)
2021-09-17 22:25:14 +00:00
if dropdown.mousepressed(x, y, m) then return end
2021-09-17 19:24:26 +00:00
end
function love.mousereleased(x, y, m)
2021-09-17 22:25:14 +00:00
if dropdown.mousereleased(x, y, m) then return end
2021-09-17 19:24:26 +00:00
end
function love.wheelmoved(x, y)
if y == 0 then return end
2021-09-17 22:38:04 +00:00
2021-09-17 22:25:14 +00:00
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
2021-09-17 19:24:26 +00:00
end
2021-09-17 22:25:14 +00:00
print(k, v)
::continue::
2021-09-17 19:24:26 +00:00
end
end
2021-09-17 22:25:14 +00:00
end