Create/play animations inside neovim's buffer.
matrix.webm
fireworks.webm
demo.webm
{
'alanfortlink/animatedbg.nvim',
config = function ()
require("animatedbg-nvim").setup({
fps = 60 -- default
})
end
}
local animatedbg = require("animatedbg-nvim")
animatedbg.play({ animation = "fireworks" }) -- fireworks | matrix | demo
-- animatedbg.play({ animation = "matrix", duration = 20 }) -- some support duration
-- animatedbg.play({ animation = "matrix", symbols = {"A", "B", "C"}}) -- replacing the symbols. remember that some symbols will not render properly :/
-- animatedbg.play({ animation = "matrix", extra_symbols = {"A", "B", "C"}}) -- extending the symbols
-- animatedbg.play({ animation = "fireworks", duration = 500, time_between_shots = 0.1 })
-- animatedbg.stop_all() -- if you don't want to wait
It's very easy to add your own animation.
You need to prove an animation builder that contains:
- A unique
id
- A
create(opts)
function that returns an animation.opts
contains information about the buffer, window, and size (opts.rows
andopts.cols
).- See some examples of how it is used in
./lua/animatedbg-nvim/animations
.
The animation table that is returned by create
must have:
init()
, called once, right before the animation startsupdate(dt) : boolean
, called before every frame is rendered.dt
is the interval since the last frame in seconds.- It should return
true
if the animation is still playing andfalse
when it's over.
- It should return
render(canvas)
, called every frame for rendering.
One could write an animation/builder like this:
--- @type AnimationBuilder
local custom_animation_builder = {
id = "unique_name",
create = function(opts)
local elapsed = 0.0
--- @type Animation
return {
init = function()
end,
update = function(dt)
elapsed = elapsed + dt
return elapsed <= 3 -- ends after 3 seconds
end,
render = function(canvas)
local center = { row = math.floor(opts.rows / 2), col = math.floor(opts.cols / 2) }
--- @type Rect
local rect = {
row = center.row - 10,
col = center.col - 10,
rows = 20,
cols = 20,
}
local decoration = { bg = "#FFFFFF", fg = "#FF0000", content = 'X' }
canvas.draw_rect(rect, decoration)
end,
}
end
}
and then set it up like this:
require("animatedbg-nvim").setup({
builders = { custom_animation_builder }
})
If you build any animations and would like to share them, there's a discussion page that you can use.
- The "canvas" will be the width of your window but the size of your buf. Make sure you have enough lines in order to see the animations :)
- So far I have figured out how to paint beyond the end of line, but I haven't figured out how to paint beyond the end of the buffer.