consistent formatting

This commit is contained in:
jill 2021-09-18 01:38:04 +03:00
parent 83d23d8d72
commit 63b1a08df8
4 changed files with 102 additions and 105 deletions

View File

@ -118,54 +118,54 @@ function self.render()
local mx, my = love.mouse.getPosition() local mx, my = love.mouse.getPosition()
for i,v in ipairs(dropdowns) do for i,v in ipairs(dropdowns) do
local x, y, w, h = v.x, v.y, v.width, love.graphics.getFont():getHeight() + margin local x, y, w, h = v.x, v.y, v.width, love.graphics.getFont():getHeight() + margin
love.graphics.setColor(0, 0, 0, 0.3) love.graphics.setColor(0, 0, 0, 0.3)
if love.mouse.getX() > x and love.mouse.getX() < x + w and love.mouse.getY() > y and love.mouse.getY() < y + h then if love.mouse.getX() > x and love.mouse.getX() < x + w and love.mouse.getY() > y and love.mouse.getY() < y + h then
love.graphics.setColor(0.8, 0.8, 1, love.mouse.isDown(1) and 0.4 or 0.3) love.graphics.setColor(0.8, 0.8, 1, love.mouse.isDown(1) and 0.4 or 0.3)
end end
love.graphics.rectangle('fill', x, y, w, h) love.graphics.rectangle('fill', x, y, w, h)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.rectangle('line', x, y, w, h) love.graphics.rectangle('line', x, y, w, h)
love.graphics.print(self.selected(i), x + margin/2, y + margin/2) love.graphics.print(self.selected(i), x + margin/2, y + margin/2)
love.graphics.rectangle('line', x + w - h, y, h, h) love.graphics.rectangle('line', x + w - h, y, h, h)
love.graphics.polygon('line', x + w - h/2 + 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2 - 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2, y + h/2 + 0.3 * h) love.graphics.polygon('line', x + w - h/2 + 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2 - 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2, y + h/2 + 0.3 * h)
if self.openDropdown == i then if self.openDropdown == i then
for i,o in ipairs(v.options) do for i,o in ipairs(v.options) do
local x, y, w, h = x, y + i * h, w, h local x, y, w, h = x, y + i * h, w, h
y = y + dropdownScrollE * h y = y + dropdownScrollE * h
local gi = y / h local gi = y / h
if gi > maxDropdown or gi < 1 then if gi > maxDropdown or gi < 1 then
goto continue goto continue
end end
local a = 1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) /(#v.options - maxDropdown))), 0), 1) local a = 1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) /(#v.options - maxDropdown))), 0), 1)
love.graphics.setColor(0, 0, 0, 0.3 * a) love.graphics.setColor(0, 0, 0, 0.3 * a)
if mx > x and mx < x + w and my > y and my < y + h then if mx > x and mx < x + w and my > y and my < y + h then
love.graphics.setColor(0.8, 0.8, 1, (love.mouse.isDown(1) and 0.4 or 0.3) * a) love.graphics.setColor(0.8, 0.8, 1, (love.mouse.isDown(1) and 0.4 or 0.3) * a)
end end
love.graphics.rectangle('fill', x, y, w, h) love.graphics.rectangle('fill', x, y, w, h)
love.graphics.setColor(1, 1, 1, 0.75 * a) love.graphics.setColor(1, 1, 1, 0.75 * a)
love.graphics.rectangle('line', x, y, w, h) love.graphics.rectangle('line', x, y, w, h)
love.graphics.setColor(1, 1, 1, 1 * a) love.graphics.setColor(1, 1, 1, 1 * a)
love.graphics.print(v.options[i], x + 2, y + 2) love.graphics.print(v.options[i], x + 2, y + 2)
::continue:: ::continue::
end end
-- scrollwheel -- scrollwheel
if #v.options > maxDropdown then if #v.options > maxDropdown then
local displayed = maxDropdown / #v.options local displayed = maxDropdown / #v.options
local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown) local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown)
local size = margin local size = margin
love.graphics.setColor(1, 1, 1, 0.9) love.graphics.setColor(1, 1, 1, 0.9)
love.graphics.rectangle('fill', x + w - size, y + h + scroll * (1 - displayed) * (maxDropdown - 1) * h, size, displayed * (maxDropdown - 1) * h) love.graphics.rectangle('fill', x + w - size, y + h + scroll * (1 - displayed) * (maxDropdown - 1) * h, size, displayed * (maxDropdown - 1) * h)
end end
@ -195,7 +195,7 @@ function self.mousepressed(x, y, m)
end end
end end
end end
if not clickedDropdown and m == 1 then if not clickedDropdown and m == 1 then
self.openDropdown = 0 self.openDropdown = 0
return true return true

View File

@ -33,100 +33,100 @@ table.insert(self, {'spike', function(t) return exp(-10 * abs(2 * t - 1)) end})
table.insert(self, {'inverse', function(t) return t * t * (1 - t) * (1 - t) / (0.5 - t) end}) table.insert(self, {'inverse', function(t) return t * t * (1 - t) * (1 - t) / (0.5 - t) end})
table.insert(self, {'inSine', function(x) table.insert(self, {'inSine', function(x)
return 1 - cos(x * (pi * 0.5)) return 1 - cos(x * (pi * 0.5))
end}) end})
table.insert(self, {'outSine', function(x) table.insert(self, {'outSine', function(x)
return sin(x * (pi * 0.5)) return sin(x * (pi * 0.5))
end}) end})
table.insert(self, {'inOutSine', function(x) table.insert(self, {'inOutSine', function(x)
return 0.5 - 0.5 * cos(x * pi) return 0.5 - 0.5 * cos(x * pi)
end}) end})
table.insert(self, {'inQuad', function(t) return t * t end}) table.insert(self, {'inQuad', function(t) return t * t end})
table.insert(self, {'outQuad', function(t) return -t * (t - 2) end}) table.insert(self, {'outQuad', function(t) return -t * (t - 2) end})
table.insert(self, {'inOutQuad', function(t) table.insert(self, {'inOutQuad', function(t)
t = t * 2 t = t * 2
if t < 1 then if t < 1 then
return 0.5 * t ^ 2 return 0.5 * t ^ 2
else else
return 1 - 0.5 * (2 - t) ^ 2 return 1 - 0.5 * (2 - t) ^ 2
end end
end}) end})
table.insert(self, {'inCubic', function(t) return t * t * t end}) table.insert(self, {'inCubic', function(t) return t * t * t end})
table.insert(self, {'outCubic', function(t) return 1 - (1 - t) ^ 3 end}) table.insert(self, {'outCubic', function(t) return 1 - (1 - t) ^ 3 end})
table.insert(self, {'inOutCubic', function(t) table.insert(self, {'inOutCubic', function(t)
t = t * 2 t = t * 2
if t < 1 then if t < 1 then
return 0.5 * t ^ 3 return 0.5 * t ^ 3
else else
return 1 - 0.5 * (2 - t) ^ 3 return 1 - 0.5 * (2 - t) ^ 3
end end
end}) end})
table.insert(self, {'inQuart', function(t) return t * t * t * t end}) table.insert(self, {'inQuart', function(t) return t * t * t * t end})
table.insert(self, {'outQuart', function(t) return 1 - (1 - t) ^ 4 end}) table.insert(self, {'outQuart', function(t) return 1 - (1 - t) ^ 4 end})
table.insert(self, {'inOutQuart', function(t) table.insert(self, {'inOutQuart', function(t)
t = t * 2 t = t * 2
if t < 1 then if t < 1 then
return 0.5 * t ^ 4 return 0.5 * t ^ 4
else else
return 1 - 0.5 * (2 - t) ^ 4 return 1 - 0.5 * (2 - t) ^ 4
end end
end}) end})
table.insert(self, {'inQuint', function(t) return t ^ 5 end}) table.insert(self, {'inQuint', function(t) return t ^ 5 end})
table.insert(self, {'outQuint', function(t) return 1 - (1 - t) ^ 5 end}) table.insert(self, {'outQuint', function(t) return 1 - (1 - t) ^ 5 end})
table.insert(self, {'inOutQuint', function(t) table.insert(self, {'inOutQuint', function(t)
t = t * 2 t = t * 2
if t < 1 then if t < 1 then
return 0.5 * t ^ 5 return 0.5 * t ^ 5
else else
return 1 - 0.5 * (2 - t) ^ 5 return 1 - 0.5 * (2 - t) ^ 5
end end
end}) end})
table.insert(self, {'inExpo', function(t) return 1000 ^ (t - 1) - 0.001 end}) table.insert(self, {'inExpo', function(t) return 1000 ^ (t - 1) - 0.001 end})
table.insert(self, {'outExpo', function(t) return 1.001 - 1000 ^ -t end}) table.insert(self, {'outExpo', function(t) return 1.001 - 1000 ^ -t end})
table.insert(self, {'inOutExpo', function(t) table.insert(self, {'inOutExpo', function(t)
t = t * 2 t = t * 2
if t < 1 then if t < 1 then
return 0.5 * 1000 ^ (t - 1) - 0.0005 return 0.5 * 1000 ^ (t - 1) - 0.0005
else else
return 1.0005 - 0.5 * 1000 ^ (1 - t) return 1.0005 - 0.5 * 1000 ^ (1 - t)
end end
end}) end})
table.insert(self, {'inCirc', function(t) return 1 - sqrt(1 - t * t) end}) table.insert(self, {'inCirc', function(t) return 1 - sqrt(1 - t * t) end})
table.insert(self, {'outCirc', function(t) return sqrt(-t * t + 2 * t) end}) table.insert(self, {'outCirc', function(t) return sqrt(-t * t + 2 * t) end})
table.insert(self, {'inOutCirc', function(t) table.insert(self, {'inOutCirc', function(t)
t = t * 2 t = t * 2
if t < 1 then if t < 1 then
return 0.5 - 0.5 * sqrt(1 - t * t) return 0.5 - 0.5 * sqrt(1 - t * t)
else else
t = t - 2 t = t - 2
return 0.5 + 0.5 * sqrt(1 - t * t) return 0.5 + 0.5 * sqrt(1 - t * t)
end end
end}) end})
table.insert(self, {'outBounce', function(t) table.insert(self, {'outBounce', function(t)
if t < 1 / 2.75 then if t < 1 / 2.75 then
return 7.5625 * t * t return 7.5625 * t * t
elseif t < 2 / 2.75 then elseif t < 2 / 2.75 then
t = t - 1.5 / 2.75 t = t - 1.5 / 2.75
return 7.5625 * t * t + 0.75 return 7.5625 * t * t + 0.75
elseif t < 2.5 / 2.75 then elseif t < 2.5 / 2.75 then
t = t - 2.25 / 2.75 t = t - 2.25 / 2.75
return 7.5625 * t * t + 0.9375 return 7.5625 * t * t + 0.9375
else else
t = t - 2.625 / 2.75 t = t - 2.625 / 2.75
return 7.5625 * t * t + 0.984375 return 7.5625 * t * t + 0.984375
end end
end}) end})
table.insert(self, {'inBounce', function(t) return 1 - self.outBounce(1 - t) end}) table.insert(self, {'inBounce', function(t) return 1 - self.outBounce(1 - t) end})
table.insert(self, {'inOutBounce', function(t) table.insert(self, {'inOutBounce', function(t)
if t < 0.5 then if t < 0.5 then
return self.inBounce(t * 2) * 0.5 return self.inBounce(t * 2) * 0.5
else else
return self.outBounce(t * 2 - 1) * 0.5 + 0.5 return self.outBounce(t * 2 - 1) * 0.5 + 0.5
end end
end}) end})
return self return self

View File

@ -26,11 +26,11 @@ function self.render()
if mode == 1 or mode == 2 then if mode == 1 or mode == 2 then
local csize = 10 -- preview point size local csize = 10 -- preview point size
local size = math.min((sw - padding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + 128 + padding), sh - padding * 5 - csize) local size = math.min((sw - padding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + 128 + padding), sh - padding * 5 - csize)
local x, y, w, h = sw - padding - size, padding, size, size local x, y, w, h = sw - padding - size, padding, size, size
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.rectangle('line', x, y, w, h) love.graphics.rectangle('line', x, y, w, h)
-- grid -- grid
love.graphics.setColor(0.2, 0.2, 0.4, 0.2) love.graphics.setColor(0.2, 0.2, 0.4, 0.2)
local gridsize = 64 local gridsize = 64
@ -40,24 +40,24 @@ function self.render()
for gy = 1, gridsize - 2 do for gy = 1, gridsize - 2 do
love.graphics.line(x + margin, y + margin + gy * h/gridsize, x + w - margin, y + margin + gy * h/gridsize) love.graphics.line(x + margin, y + margin + gy * h/gridsize, x + w - margin, y + margin + gy * h/gridsize)
end end
-- mixease point -- mixease point
if mode == 2 then if mode == 2 then
love.graphics.setColor(1, 1, 1, 0.8) love.graphics.setColor(1, 1, 1, 0.8)
love.graphics.line(x + margin + mixpoint * w, y, x + margin + mixpoint * w, y + h) love.graphics.line(x + margin + mixpoint * w, y, x + margin + mixpoint * w, y + h)
end end
-- preview point -- preview point
local t = love.timer.getTime() % 1 local t = love.timer.getTime() % 1
love.graphics.setColor(0.4, 0.4, 1, 0.4) love.graphics.setColor(0.4, 0.4, 1, 0.4)
love.graphics.line(x + margin + t * w, y, x + margin + t * w, y + h) love.graphics.line(x + margin + t * w, y, x + margin + t * w, y + h)
-- y = 0 point -- y = 0 point
-- todo: this will break with eases that dont have the first point at y0 -- todo: this will break with eases that dont have the first point at y0
local py = graph[1] 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.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) love.graphics.line(x, y + h - py * h, x + w, y + py * h)
-- polygone -- polygone
-- this isnt done with a polygon because else itd waste a Bunch of ram and i kinda, dont want to do that? -- 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) love.graphics.setColor(1, 1, 1, 1)
@ -72,11 +72,11 @@ function self.render()
end end
last = b last = b
end end
-- preview -- preview
love.graphics.setColor(1, 1, 1, 0.2) 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) 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(t)
local a2 = ease(math.max(math.min(t - 0.1, 1), 0)) local a2 = ease(math.max(math.min(t - 0.1, 1), 0))
@ -87,7 +87,7 @@ function self.render()
if minEase then if minEase then
da = da / 2 + 0.5 da = da / 2 + 0.5
end end
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) 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
end end

View File

@ -54,16 +54,13 @@ minEase = false
padding = 6 padding = 6
margin = 4 margin = 4
-- slider
mixpoint = 0.5 mixpoint = 0.5
oldmixpoint = 0.5 oldmixpoint = 0.5
local mixpointtimer = 0 -- easter egg thing local mixpointtimer = 0 -- easter egg thing
local mixpointspin = 0 local mixpointspin = 0
-- graph
-- dropdown bullshit
-- rendering -- rendering
function love.load() function love.load()
@ -72,18 +69,18 @@ end
function love.update(dt) function love.update(dt)
graph.update(dt) graph.update(dt)
-- slider -- slider
mixpointtimer = mix(mixpointtimer + math.abs(mixpoint - oldmixpoint), 0, math.min(dt * 8)) mixpointtimer = mix(mixpointtimer + math.abs(mixpoint - oldmixpoint), 0, math.min(dt * 8))
oldmixpoint = mix(oldmixpoint, mixpoint, math.min(dt * 20, 1)) oldmixpoint = mix(oldmixpoint, mixpoint, math.min(dt * 20, 1))
if mixpointtimer > 2 then if mixpointtimer > 2 then
mixpointtimer = mixpointtimer - 2 mixpointtimer = mixpointtimer - 2
mixpointspin = mixpointspin + 4 mixpointspin = mixpointspin + 4
end end
mixpointspin = mix(mixpointspin, 0, dt * 3) mixpointspin = mix(mixpointspin, 0, dt * 3)
dropdown.update(dt) dropdown.update(dt)
end end
@ -91,32 +88,32 @@ function love.draw()
mode = dropdown.kget('mode').selected mode = dropdown.kget('mode').selected
local sw, sh = love.graphics.getDimensions() local sw, sh = love.graphics.getDimensions()
local mx, my = love.mouse.getPosition() local mx, my = love.mouse.getPosition()
love.graphics.setColor(0.09, 0.09, 0.12, 1) love.graphics.setColor(0.09, 0.09, 0.12, 1)
love.graphics.rectangle('fill', 0, 0, sw, sh) love.graphics.rectangle('fill', 0, 0, sw, sh)
love.graphics.setColor(0.08, 0.08, 0.1, 1) love.graphics.setColor(0.08, 0.08, 0.1, 1)
love.graphics.rectangle('line', 0, 0, sw, sh) love.graphics.rectangle('line', 0, 0, sw, sh)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.print('Box of Eases by oatmealine', padding, sh - love.graphics.getFont():getHeight() - padding) love.graphics.print('Box of Eases by oatmealine', padding, sh - love.graphics.getFont():getHeight() - padding)
-- sliders -- sliders
-- yeah we do a lil' hardcoding -- yeah we do a lil' hardcoding
if mode == 2 then if mode == 2 then
local x, y, w, h = padding, padding * 2 + love.graphics.getFont():getHeight() + margin, 128, 32 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.setColor(0.7, 0.7, 0.7, 0.4)
love.graphics.line(x, y + h/2, x + w, y + h/2) love.graphics.line(x, y + h/2, x + w, y + h/2)
local sx, sy = x + w * oldmixpoint, y + h/2 local sx, sy = x + w * oldmixpoint, y + h/2
local ssize = h * 0.5 local ssize = h * 0.5
love.graphics.push() love.graphics.push()
love.graphics.translate(sx, sy) love.graphics.translate(sx, sy)
love.graphics.rotate((mixpoint - oldmixpoint) * 4 + mixpointspin * math.pi * 2) love.graphics.rotate((mixpoint - oldmixpoint) * 4 + mixpointspin * math.pi * 2)
love.graphics.setColor(0, 0, 0, 1) 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 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) love.graphics.setColor(0.2, 0.2, 0.3, 1)
@ -124,23 +121,23 @@ function love.draw()
love.graphics.rectangle('fill', -ssize/2, -ssize/2, ssize, ssize) love.graphics.rectangle('fill', -ssize/2, -ssize/2, ssize, ssize)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.rectangle('line', -ssize/2, -ssize/2, ssize, ssize) love.graphics.rectangle('line', -ssize/2, -ssize/2, ssize, ssize)
love.graphics.rotate((mixpoint - oldmixpoint) * -2) love.graphics.rotate((mixpoint - oldmixpoint) * -2)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(math.floor(mixpoint * 100)/100, -ssize * 6, ssize - 2, ssize * 12, 'center') love.graphics.printf(math.floor(mixpoint * 100)/100, -ssize * 6, ssize - 2, ssize * 12, 'center')
love.graphics.pop() 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 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 mixpoint = (mx - x) / w
dropdown.createDropdowns() dropdown.createDropdowns()
end end
end end
-- dropdowns -- dropdowns
dropdown.render() dropdown.render()
-- graph -- graph
graph.render() graph.render()
end end
@ -155,7 +152,7 @@ end
function love.wheelmoved(x, y) function love.wheelmoved(x, y)
if y == 0 then return end if y == 0 then return end
if dropdown.wheelmoved(x, y) then return end if dropdown.wheelmoved(x, y) then return end
end end