Skip to content

Commit 747807d

Browse files
committed
feat: use octants in addition to braille to render particles
1 parent 565e8a6 commit 747807d

3 files changed

Lines changed: 59 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ return {
8484
scroll_buffer_space = true,
8585

8686
-- Set to `true` if your font supports legacy computing symbols (block unicode symbols).
87-
-- Smears will blend better on all backgrounds.
87+
-- Smears and particles will look a lot less blocky.
8888
legacy_computing_symbols_support = false,
8989

9090
-- Smear cursor in insert mode.

lua/smear_cursor/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ M.particle_random_velocity = 100 -- characters width per second
151151
M.particle_damping = 0.2
152152
M.particle_gravity = 20 -- characters width per second squared
153153
M.min_distance_emit_particles = 1.5 -- character widths
154+
M.particle_switch_octant_braille = 0.3 -- fraction of lifetime, used if `legacy_computing_symbols_support` is true
154155
M.particles_over_text = false
155156

156157
-- For debugging ---------------------------------------------------------------

lua/smear_cursor/draw.lua

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,31 @@ local RIGHT_DIAGONAL_BLOCKS = {
104104
},
105105
}
106106
M.BLOCK_ASPECT_RATIO = 2.0 -- height / width
107+
108+
local OCTANT_CHARACTERS = {
109+
"𜺨", "𜺫", "🮂", "𜴀", "", "𜴁", "𜴂", "𜴃", "𜴄", "", "𜴅", "𜴆", "𜴇", "𜴈", "",
110+
"𜴉", "𜴊", "𜴋", "𜴌", "🯦", "𜴍", "𜴎", "𜴏", "𜴐", "𜴑", "𜴒", "𜴓", "𜴔", "𜴕", "𜴖", "𜴗",
111+
"𜴘", "𜴙", "𜴚", "𜴛", "𜴜", "𜴝", "𜴞", "𜴟", "🯧", "𜴠", "𜴡", "𜴢", "𜴣", "𜴤", "𜴥", "𜴦",
112+
"𜴧", "𜴨", "𜴩", "𜴪", "𜴫", "𜴬", "𜴭", "𜴮", "𜴯", "𜴰", "𜴱", "𜴲", "𜴳", "𜴴", "𜴵", "🮅",
113+
"𜺣", "𜴶", "𜴷", "𜴸", "𜴹", "𜴺", "𜴻", "𜴼", "𜴽", "𜴾", "𜴿", "𜵀", "𜵁", "𜵂", "𜵃", "𜵄",
114+
"", "𜵅", "𜵆", "𜵇", "𜵈", "", "𜵉", "𜵊", "𜵋", "𜵌", "", "𜵍", "𜵎", "𜵏", "𜵐", "",
115+
"𜵑", "𜵒", "𜵓", "𜵔", "𜵕", "𜵖", "𜵗", "𜵘", "𜵙", "𜵚", "𜵛", "𜵜", "𜵝", "𜵞", "𜵟", "𜵠",
116+
"𜵡", "𜵢", "𜵣", "𜵤", "𜵥", "𜵦", "𜵧", "𜵨", "𜵩", "𜵪", "𜵫", "𜵬", "𜵭", "𜵮", "𜵯", "𜵰",
117+
"𜺠", "𜵱", "𜵲", "𜵳", "𜵴", "𜵵", "𜵶", "𜵷", "𜵸", "𜵹", "𜵺", "𜵻", "𜵼", "𜵽", "𜵾", "𜵿",
118+
"𜶀", "𜶁", "𜶂", "𜶃", "𜶄", "𜶅", "𜶆", "𜶇", "𜶈", "𜶉", "𜶊", "𜶋", "𜶌", "𜶍", "𜶎", "𜶏",
119+
"", "𜶐", "𜶑", "𜶒", "𜶓", "", "𜶔", "𜶕", "𜶖", "𜶗", "", "𜶘", "𜶙", "𜶚", "𜶛", "",
120+
"𜶜", "𜶝", "𜶞", "𜶟", "𜶠", "𜶡", "𜶢", "𜶣", "𜶤", "𜶥", "𜶦", "𜶧", "𜶨", "𜶩", "𜶪", "𜶫",
121+
"", "𜶬", "𜶭", "𜶮", "𜶯", "𜶰", "𜶱", "𜶲", "𜶳", "𜶴", "𜶵", "𜶶", "𜶷", "𜶸", "𜶹", "𜶺",
122+
"𜶻", "𜶼", "𜶽", "𜶾", "𜶿", "𜷀", "𜷁", "𜷂", "𜷃", "𜷄", "𜷅", "𜷆", "𜷇", "𜷈", "𜷉", "𜷊",
123+
"𜷋", "𜷌", "𜷍", "𜷎", "𜷏", "𜷐", "𜷑", "𜷒", "𜷓", "𜷔", "𜷕", "𜷖", "𜷗", "𜷘", "𜷙", "𜷚",
124+
"", "𜷛", "𜷜", "𜷝", "𜷞", "", "𜷟", "𜷠", "𜷡", "𜷢", "", "𜷣", "", "𜷤", "𜷥", "",
125+
}
107126
-- stylua: ignore end
108127

109128
local braille_characters = {}
110129
for i = 1, 255 do
111130
local code = 0x2800 + i
112-
braille_characters[i] =
113-
string.char(0xE0 + math.floor(code / 0x1000), 0x80 + (math.floor(code / 0x40) % 0x40), 0x80 + (code % 0x40))
131+
braille_characters[i] = vim.fn.nr2char(code)
114132
end
115133

116134
-- Enums for drawing quad
@@ -876,6 +894,21 @@ M.draw_quad = function(corners, target_position, vertical_bar, gradient_origin,
876894
end
877895
end
878896

897+
local function draw_octant_character(row, col, cell, hl_group, zindex)
898+
local octant_index = (cell[1][1] > 0 and 1 or 0)
899+
+ (cell[1][2] > 0 and 2 or 0)
900+
+ (cell[2][1] > 0 and 4 or 0)
901+
+ (cell[2][2] > 0 and 8 or 0)
902+
+ (cell[3][1] > 0 and 16 or 0)
903+
+ (cell[3][2] > 0 and 32 or 0)
904+
+ (cell[4][1] > 0 and 64 or 0)
905+
+ (cell[4][2] > 0 and 128 or 0)
906+
907+
if octant_index == 0 then return end
908+
909+
M.draw_character(row, col, OCTANT_CHARACTERS[octant_index], hl_group, zindex)
910+
end
911+
879912
local function draw_braille_character(row, col, cell, hl_group, zindex)
880913
local braille_index = (cell[1][1] > 0 and 1 or 0)
881914
+ (cell[2][1] > 0 and 2 or 0)
@@ -893,6 +926,9 @@ end
893926

894927
M.draw_particles = function(particles, target_position)
895928
if target_position == nil then target_position = { 0, 0 } end
929+
930+
local lifetime_switch_octant_braille = config.particle_max_lifetime
931+
* (config.legacy_computing_symbols_support and config.particle_switch_octant_braille or math.huge)
896932
local cells = {}
897933

898934
for _, particle in ipairs(particles) do
@@ -928,18 +964,29 @@ M.draw_particles = function(particles, target_position)
928964
+ cell[3][2]
929965
+ cell[4][1]
930966
+ cell[4][2]
931-
local shade = math.min(1, lifetime_sum / num_dots / config.particle_max_lifetime)
967+
968+
local lifetime_average = lifetime_sum / num_dots
969+
local draw_function
970+
local shade
971+
if lifetime_average > lifetime_switch_octant_braille then
972+
draw_function = draw_octant_character
973+
shade = math.min(
974+
1,
975+
(lifetime_average - lifetime_switch_octant_braille)
976+
/ (config.particle_max_lifetime - lifetime_switch_octant_braille)
977+
)
978+
else
979+
draw_function = draw_braille_character
980+
shade = math.min(
981+
1,
982+
lifetime_average / math.min(config.particle_max_lifetime, lifetime_switch_octant_braille)
983+
)
984+
end
932985
local hl_group_index = round(shade * config.color_levels)
933986

934987
if hl_group_index == 0 then goto continue end
935988

936-
draw_braille_character(
937-
row,
938-
col,
939-
cell,
940-
color.get_hl_group({ level = hl_group_index }),
941-
config.windows_zindex - 1
942-
)
989+
draw_function(row, col, cell, color.get_hl_group({ level = hl_group_index }), config.windows_zindex - 1)
943990

944991
::continue::
945992
end

0 commit comments

Comments
 (0)