From 844ecd1f26a5e7c5a41ff5a17f4d0e54c219083a Mon Sep 17 00:00:00 2001 From: liquidev Date: Wed, 10 Mar 2021 16:35:37 +0100 Subject: [PATCH] Make animation speed independent of config.fps, add config.animation_rate to fine-tune animation speed (#93) * animation rate config field * @franko's math magic to make it look more correct --- data/core/config.lua | 1 + data/core/view.lua | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/data/core/config.lua b/data/core/config.lua index bfe4fb76..8cc7d556 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -19,6 +19,7 @@ config.line_limit = 80 config.max_symbols = 4000 config.max_project_files = 2000 config.transitions = true +config.animation_rate = 1.0 config.blink_period = 0.8 -- Disable plugin loading setting to false the config entry diff --git a/data/core/view.lua b/data/core/view.lua index 4d499594..9a58cc41 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -24,7 +24,10 @@ function View:move_towards(t, k, dest, rate) if not config.transitions or math.abs(val - dest) < 0.5 then t[k] = dest else - t[k] = common.lerp(val, dest, rate or 0.5) + rate = common.clamp(rate or 0.5, 1e-8, 1 - 1e-8) + local alpha = math.log(1 - rate) * config.animation_rate + local dt = 60 / config.fps + t[k] = common.lerp(val, dest, 1 - math.exp(alpha * dt)) end if val ~= dest then core.redraw = true