diff --git a/dropdown.lua b/dropdown.lua index 4fd2e46..1c65f72 100644 --- a/dropdown.lua +++ b/dropdown.lua @@ -66,13 +66,6 @@ function self.createDropdowns() name = 'mode' }) - local param1 = {} - local param2 = {} - param1[1] = slider.kvalue('param11') - param1[2] = slider.kvalue('param12') - param2[1] = slider.kvalue('param21') - param2[2] = slider.kvalue('param22') - if d[dropdownId].selected == 1 then -- preview ease insertDropdown(d, { x = outerpadding + dropdownWidth + padding, @@ -81,12 +74,7 @@ function self.createDropdowns() options = skeys(ease.eases), name = 'ease1' }) - local _e = ease.eases[d[dropdownId].options[d[dropdownId].selected]] - param1[1] = param1[1] or (_e.params[1] and _e.params[1].default) or 1 - param1[2] = param1[2] or (_e.params[2] and _e.params[2].default) or 1 - ease.ease = function(x) - return _e.f(x, param1[1], param1[2]) - end + ease.ease = ease.eases[d[dropdownId].options[d[dropdownId].selected]].f elseif d[dropdownId].selected == 2 then -- mix eases insertDropdown(d, { x = outerpadding + dropdownWidth + padding, @@ -102,14 +90,7 @@ function self.createDropdowns() options = skeys(ease.eases), name = 'ease2' }) - - local _e1 = ease.eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]] - local _e2 = ease.eases[d[dropdownId].options[d[dropdownId].selected]] - param1[1] = param1[1] or (_e1.params[1] and _e1.params[1].default) or 1 - param1[2] = param1[2] or (_e1.params[2] and _e1.params[2].default) or 1 - param2[1] = param2[1] or (_e2.params[1] and _e2.params[1].default) or 1 - param2[2] = param2[2] or (_e2.params[2] and _e2.params[2].default) or 1 - ease.ease = ease.mixEase(_e1.f, _e2.f, slider.kvalue('mix'), param1, param2) + 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 insertDropdown(d, { x = outerpadding + dropdownWidth + padding, diff --git a/ease.lua b/ease.lua index fd5dfec..ff73894 100644 --- a/ease.lua +++ b/ease.lua @@ -2,14 +2,14 @@ local self = {} local easelib = require 'easelib' -function self.mixEase(e1, e2, point, param1, param2) +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, param1[1], param1[2]) * point + return e1(a / point) * point else - return e2((a - point) / (1 - point), param2[1], param2[2]) * (1 - point) + point + return e2((a - point) / (1 - point)) * (1 - point) + point end end end @@ -17,26 +17,18 @@ end self.eases = {} for i,v in pairs(easelib) do local min = 0 - - local params = {} - for i = 3, #v do - if v[i] then - table.insert(params, {min = v[i][1], max = v[i][2], default = v[i][3], name = v[i][4]}) - end - end - + local q = 10 for i = 0, q do - local s = v[2](i / q, (params[1] or {}).default, (params[2] or {}).default) - if s < 0 and not v.overridemin then min = -1 end + 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, - params = params + i = i } end diff --git a/easelib.lua b/easelib.lua index 706381e..8c89533 100644 --- a/easelib.lua +++ b/easelib.lua @@ -32,25 +32,6 @@ table.insert(self, {'pulse', function(t) return t < .5 and self.tap(t * 2) or -s 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, {'popElastic', function(t, damp, count) - return (1000 ^ -(t ^ damp) - 0.001) * sin(count * pi * t) -end, {1, 10, 1.4, 'damp'}, {1, 25, 6, 'count'}}) -table.insert(self, {'tapElastic', function(t, damp, count) - return (1000 ^ -((1 - t) ^ damp) - 0.001) * sin(count * pi * (1 - t)) -end, {1, 10, 1.4, 'damp'}, {1, 25, 6, 'count'}}) -table.insert(self, {'pulseElastic', function(t, damp, count) - if t < .5 then - return self.tapElastic(t * 2, damp, count) - else - return -self.popElastic(t * 2 - 1, damp, count) - end -end, {1, 10, 1.4, 'damp'}, {1, 25, 6, 'count'}}) - -table.insert(self, {'impulse', function(t, damp) - t = t ^ damp - return t * (1000 ^ -t - 0.001) * 18.6 -end, {0, 10, 0.9, 'damp'}}) - table.insert(self, {'inSine', function(x) return 1 - cos(x * (pi * 0.5)) end}) @@ -148,28 +129,4 @@ table.insert(self, {'inOutBounce', function(t) end end}) -table.insert(self, {'inElastic', function(t, a, p) - return 1 - self.outElastic(1 - t, a, p) -end, {1, 3, 1, 'a'}, {0, 2, 0.3, 'p'}, overridemin = true}) -table.insert(self, {'outElastic', function(t, a, p) - return a * pow(2, -10 * t) * sin((t - p / (2 * pi) * asin(1/a)) * 2 * pi / p) + 1 -end, {1, 3, 1, 'a'}, {0, 2, 0.3, 'p'}, overridemin = true}) -table.insert(self, {'inOutElastic', function(t, a, p) - return t < 0.5 - and 0.5 * self.inElastic(t * 2, a, p) - or 0.5 + 0.5 * self.outElastic(t * 2 - 1, a, p) -end, {1, 3, 1, 'a'}, {0, 2, 0.3, 'p'}, overridemin = true}) - -table.insert(self, {'inBack', function(t, a) - return t * t * (a * t + t - a) -end, {0, 3, 1.70158, 'a'}}) -table.insert(self, {'outBack', function(t, a) - t = t - 1 return t * t * ((a + 1) * t + a) + 1 -end, {0, 3, 1.70158, 'a'}}) -table.insert(self, {'inOutBack', function(t, a) - return t < 0.5 - and 0.5 * self.inBack(t * 2, a) - or 0.5 + 0.5 * self.outBack(t * 2 - 1, a) -end, {0, 3, 1.70158, 'a'}}) - return self diff --git a/graph.lua b/graph.lua index 30ae18f..f21efa6 100644 --- a/graph.lua +++ b/graph.lua @@ -21,9 +21,6 @@ function self.update(dt) b = b / 2 + 0.5 end graph[i] = mix(v, b, math.min(dt * 18, 1)) - if graph[i] ~= graph[i] then -- is nan - graph[i] = b - end end self.touchtimer = mix(self.touchtimer, 0, dt * 2) diff --git a/main.lua b/main.lua index cc95a1a..8fa34f8 100644 --- a/main.lua +++ b/main.lua @@ -18,10 +18,10 @@ require 'util' -- exports into global table -- rendering constants -padding = 16 +padding = 14 outerpadding = 22 margin = 6 -dropdownWidth = 128 +dropdownWidth = 106 fontHeight = love.graphics.getFont():getHeight() -- global for convinience's sake diff --git a/slider.lua b/slider.lua index 0953a0b..1d24094 100644 --- a/slider.lua +++ b/slider.lua @@ -19,7 +19,7 @@ function self.kget(key) end function self.kvalue(key) - return self.kget(key) and self.kget(key).oldvalue + return self.kget(key).oldvalue end local sliderId @@ -38,7 +38,7 @@ function self.createSliders() if mode == 2 then -- mix eases insertSlider(s, { x = outerpadding, - y = outerpadding + fontHeight * 2.5 + padding, + y = outerpadding + fontHeight + padding, width = dropdownWidth, min = 0, max = 1, @@ -48,51 +48,12 @@ function self.createSliders() }) end - local ease1 = ease.eases[dropdown.kselected('ease1')] - local ease2 = ease.eases[dropdown.kselected('ease2')] - - local param1 = ease1 and ease1.params - local param2 = ease2 and ease2.params - - if param1 then - for i,v in ipairs(param1) do - insertSlider(s, { - x = outerpadding + dropdownWidth + padding, - y = outerpadding + (fontHeight * 2.5 + padding) * i, - width = dropdownWidth, - min = v.min, - max = v.max, - default = v.default, - name = 'param1' .. i, - displayname = 'Parameter ' .. v.name - }) - end - end - if param2 then - for i,v in ipairs(param2) do - insertSlider(s, { - x = outerpadding + dropdownWidth + padding + dropdownWidth + padding, - y = outerpadding + (fontHeight * 2.5 + padding) * i, - width = dropdownWidth, - min = v.min, - max = v.max, - default = v.default, - name = 'param2' .. i, - displayname = 'Parameter ' .. v.name - }) - end - end - sliders = s end -local function normalize(a, min, max) - return (a - min) / (max - min) -end - function self.update(dt) for i, v in ipairs(sliders) do - v.spintimer = mix(v.spintimer + math.abs(normalize(v.value, v.min, v.max) - normalize(v.oldvalue, v.min, v.max)), 0, math.min(dt * 8)) + v.spintimer = mix(v.spintimer + math.abs(v.value - v.oldvalue), 0, math.min(dt * 8)) v.oldvalue = mix(v.oldvalue, v.value, math.min(dt * 20, 1)) if v.spintimer > 2 then @@ -113,20 +74,13 @@ function self.render() love.graphics.setColor(0.7, 0.7, 0.7, 0.4) love.graphics.line(x, y + h/2, x + w, y + h/2) - local normalvalue = normalize(v.value, v.min, v.max) - local normaloldvalue = normalize(v.oldvalue, v.min, v.max) - local normaldefault = normalize(v.default, v.min, v.max) - - love.graphics.setColor(0.7, 0.7, 0.7, 0.3) - love.graphics.line(x + normaldefault * w, y, x + normaldefault * w, y + h) - - local sx, sy = x + w * normaloldvalue, y + h/2 + local sx, sy = x + w * v.oldvalue, y + h/2 local ssize = h * 0.5 love.graphics.push() love.graphics.translate(sx, sy) - love.graphics.rotate((normalvalue - normaloldvalue) * 4 + v.spin * math.pi * 2) + love.graphics.rotate((v.value - v.oldvalue) * 4 + v.spin * math.pi * 2) local hovering = mx > sx - ssize/2 and mx < sx + ssize/2 and my > sy - ssize/2 and my < sy + ssize/2 and dropdown.openDropdown == 0 local dragging = mx > x and mx < x + w and my > y and my < y + h and love.mouse.isDown(1) and dropdown.openDropdown == 0 @@ -139,26 +93,18 @@ function self.render() love.graphics.setColor(1, 1, 1, 1) love.graphics.rectangle('line', -ssize/2, -ssize/2, ssize, ssize) - love.graphics.rotate((normalvalue - normaloldvalue) * -2) + love.graphics.rotate((v.value - v.oldvalue) * -2) love.graphics.setColor(1, 1, 1, 1) love.graphics.printf(math.floor(v.value * 100)/100, -ssize * 6, ssize - 2, ssize * 12, 'center') love.graphics.pop() - love.graphics.printf(v.displayname, v.x + margin * 2 - ssize * 6, v.y - 8, ssize * 12, 'center') + love.graphics.printf(v.displayname, v.x + margin * 2 - ssize * 6, v.y - 5, ssize * 12, 'center') if dragging then - v.value = ((mx - (x + 1)) / (w - 2)) * (v.max - v.min) + v.min - if v.name == 'mix' then graph.touchtimer = 1 end -- sorry !!! - createUI() - end - if mx > x and mx < x + w and my > y and my < y + h and love.mouse.isDown(2) and dropdown.openDropdown == 0 then - v.value = v.default - createUI() - end - if mx > x and mx < x + w and my > y and my < y + h and love.mouse.isDown(3) and dropdown.openDropdown == 0 then - v.value = v.min + math.random() * (v.max - v.min) + v.value = (mx - x) / w + graph.touchtimer = 1 createUI() end end