From d431ca8aa645ded26833724f473577440fa73e88 Mon Sep 17 00:00:00 2001 From: Son Pham-Ba Date: Tue, 3 Dec 2024 23:51:16 +0100 Subject: [PATCH] feat: more or less lagging intermediate points --- README.md | 13 +++++++++++++ lua/smear_cursor/animation.lua | 4 ++-- lua/smear_cursor/config.lua | 6 +++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2fe713b..dc8343e 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,19 @@ As an example of further configuration, you can tune the smear dynamics to be sn }, ``` + +> [!WARNING] Fire Hazard +> Feel free to experiment with all the configuration options, but be aware that some combinations may cause your cursor to flicker or even **catch fire**. That can happen with the following settings: +> ```lua +> opts = { +> cursor_color = "#ff8800", +> stiffness = 0.6, +> trailing_stiffness = 0.1, +> trailing_exponent = 5, +> gamma = 1, +> } +> ``` + ### Transparent background Drawing the smear over a transparent background works better when using a font that supports legacy computing symbols, therefore setting the following option: diff --git a/lua/smear_cursor/animation.lua b/lua/smear_cursor/animation.lua index f91fcd5..975b8db 100644 --- a/lua/smear_cursor/animation.lua +++ b/lua/smear_cursor/animation.lua @@ -129,8 +129,8 @@ local function set_stiffnesses(head_stiffness, trailing_stiffness) end for i = 1, 4 do - local stiffness = head_stiffness - + (trailing_stiffness - head_stiffness) * (distances[i] - min_distance) / (max_distance - min_distance) + local x = (distances[i] - min_distance) / (max_distance - min_distance) + local stiffness = head_stiffness + (trailing_stiffness - head_stiffness) * x ^ config.trailing_exponent stiffnesses[i] = math.min(1, stiffness) end end diff --git a/lua/smear_cursor/config.lua b/lua/smear_cursor/config.lua index 24163ea..2ce786a 100644 --- a/lua/smear_cursor/config.lua +++ b/lua/smear_cursor/config.lua @@ -27,7 +27,11 @@ M.stiffness = 0.6 -- 0: no movement, 1: instantaneous M.trailing_stiffness = 0.25 --- How much the tail slows down when getting close to the head. +-- Controls if middle points are closer to the head or the tail. +-- < 1: closer to the tail, > 1: closer to the head +M.trailing_exponent = 2 + +-- How much the smear slows down when getting close to the target. -- 0: no slowdown, more: more slowdown M.slowdown_exponent = 0