Code Monkey home page Code Monkey logo

cellular-automaton.nvim's Introduction

cellular-automaton.nvim

A useless plugin that might help you cope with stubbornly broken tests or overall lack of sense in life. It lets you execute aesthetically pleasing, cellular automaton animations based on the content of neovim buffer.

make_it_rain.mov

What is cellular automata

From the Wiki:

A cellular automaton is a model used in computer science and mathematics. The idea is to model a dynamic system by using a number of cells. Each cell has one of several possible states. With each "turn" or iteration the state of the current cell is determined by two things: its current state, and the states of the neighbouring cells.

But.. why?

There is no pragmatic use case whatsoever. However, there are some pseudo-scientifically proven "use-cases":

  • Urgent deadline approaches? Don't worry. With this plugin you can procrastinate even more!
  • Are you stuck and don't know how to proceed? You can use this plugin as a visual stimulant for epic ideas!
  • Those nasty colleagues keep peeking over your shoulder and stealing your code? Now you can obfuscate your editor! Good luck stealing that.
  • Working with legacy code? Just create a <leader>fml mapping and see it melt.

Requirements

  • neovim >= 0.8
  • nvim-treesitter plugin

Installation

use 'eandrju/cellular-automaton.nvim' 

Usage

You can trigger it using simple command:

:CellularAutomaton make_it_rain

or

:CellularAutomaton game_of_life

Or just create a mapping:

vim.keymap.set("n", "<leader>fml", "<cmd>CellularAutomaton make_it_rain<CR>")

You can close animation window with one of: q/<Esc>/<CR>

Known issues

  • folding and wrapping is not supported ATM

Supported animations

Make it Rain

make_it_rain.mov

Game of Life

game_of_life.mov

Implementing your own cellular automaton logic

Using a simple interface you can implement your own cellular automaton animation. You need to provide a configuration table with an update function, which takes a 2D grid of cells and modifies it in place. Each cell by default consist of two fields:

  • char - single string character
  • hl_group - treesitter's highlight group

Example sliding animation:

local config = {
    fps = 50,
    name = 'slide',
}

-- init function is invoked only once at the start
-- config.init = function (grid)
--
-- end

-- update function
config.update = function (grid)
    for i = 1, #grid do
        local prev = grid[i][#(grid[i])]
        for j = 1, #(grid[i]) do
            grid[i][j], prev = prev, grid[i][j]
        end
    end
    return true
end

require("cellular-automaton").register_animation(config)

Result:

slide.mov

Inspiration and references

cellular-automaton.nvim's People

Contributors

eandrju avatar nooj avatar sledigabel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cellular-automaton.nvim's Issues

game_of_life has issues with code folding turned on

I use set fdm=indent in my config, which automatically folds indented lines.
When executing CellularAutomaton game_of_life some lines are folded and unfolded each frame which results in a very untidy animation.

Not sure if there is a fix for that, just want to contribute to this fun project.

Plugin erroneously reporting 'Nested animations are forbidden'

When trying to stop and restart the animation, the state machine thinks it's still running and refuses to rerun.

Usage:

  1. Run :CellularAutomaton game_of_life
  2. quit (:q)
  3. Run :CellularAutomaton game_of_life
  4. Error message prints:
    Error executing Lua callback: ...llular-automaton.nvim/lua/cellular-automaton/manager.lua:33: Nested animations are forbidden

Optionally disable warning when no parser is present

I'm using this programmatically and not calling it from a keystroke. It'd be nice if either we could set a config option to ignore missing parsers or pass an argument to the start_animation function so that it can fail silently.

E903: Process failed to start: too many open files: "/bin/zsh"

When I run it, I do see it work but then it opens this error at the bottom:

Error executing vim.schedule lua callback: ...ed/cellular-automaton.nvim/lua/cellular-automaton/ui.lua:61: Vim(le
t):E903: Process failed to start: too many open files: "/bin/zsh"
stack traceback:
        [C]: in function 'nvim_win_set_buf'
        ...ed/cellular-automaton.nvim/lua/cellular-automaton/ui.lua:61: in function 'render_frame'
        ...llular-automaton.nvim/lua/cellular-automaton/manager.lua:13: in function 'process_frame'
        ...llular-automaton.nvim/lua/cellular-automaton/manager.lua:23: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue

machine: macOS 13.1 Ventura
nvim --version:

NVIM v0.9.0-dev-3345+g922075530-dirty
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by [email protected]

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/HEAD-9220755/share/nvim"

Run :checkhealth for more info

Do you accept extra animations as PR?

great plugin, I'm having a lot of fun with it, thanks for the hard work on this :-)
I was wondering if you're accepting contributions for extra animations.

Trailing whitespace displayed during animations

When the user has set list and has a character set for trailing white space, those characters will be used to display spaces in the animation. See below.

The solution I found was simply to place vim.api.nvim_win_set_option(window_id, "list", false) in ui.open_window(). It's just one line, so idk if you want a PR for it.

Edit: the animation will also display listchars.eol at the end of the line, so it isn't only trailing spaces.

whitespace

Escape sequence in animations

I've notice the occasional escape sequence (I think that's what they are) in the animations. See below, such as <81>, <8c>, and <e2>. I personally think they're kind of fun, but I just figured I'd point it out just in case it mattered to you or someone else.

escape_chars

escape_chars__game

Error after calling `za`,`zR` to enable/disable folding.

As title.

First calling CellularAutomaton make_it_rain when some code is folded:

Error executing Lua callback: .../cellular-automaton.nvim/lua/cellular-automaton/load.lua:85: attempt to index a nil value
stack traceback:
        .../cellular-automaton.nvim/lua/cellular-automaton/load.lua:85: in function 'load_base_grid'
        ...llular-automaton.nvim/lua/cellular-automaton/manager.lua:35: in function 'execute_animation'
        .../cellular-automaton.nvim/lua/cellular-automaton/init.lua:43: in function 'start_animation'
        ...rt/cellular-automaton.nvim/plugin/cellular-automaton.lua:16: in function <...rt/cellular-automaton.nvim/plugin/cellular-automaton.lua:15>

After the first error, CellularAutomaton make_it_rain with/without code being folded will cause a different error:

Error executing Lua callback: ...llular-automaton.nvim/lua/cellular-automaton/manager.lua:30: Nested animations are forbidden
stack traceback:
        [C]: in function 'error'
        ...llular-automaton.nvim/lua/cellular-automaton/manager.lua:30: in function 'execute_animation'
        .../cellular-automaton.nvim/lua/cellular-automaton/init.lua:43: in function 'start_animation'
        ...rt/cellular-automaton.nvim/plugin/cellular-automaton.lua:16: in function <...rt/cellular-automaton.nvim/plugin/cellular-automaton.lua:15>

And sorry for being too serious about this plugin not working in a rarely happen situation.

E5108: module 'cellular-automaton' not found

After including the cellular-automaton plugin in my init.lua file, I get the "module 'cellular-automaton' not found" error when trying to use the plugin. I am using the basic neovim kickstart configuration with treesitter configured and the following lines added from a previous issue.

Help would be very appreciated!

Additional info

  • M1 max macbook pro
  • NVIM v0.8.2

My configuration file:

   63-- Cellular automata
   64use { 'eandrju/cellular-automaton.nvim', requires = 'nvim-treesitter/nvim-treesitter' }
   65local function animate(type)
   66 ┊ ┊ require('cellular-automaton').start_animation(type)
   67end
   6879vim.keymap.set('n', '<leader>fml', function() animate('make_it_rain') end)

The error log:

E5108: Error executing lua: /Users/********/.config/nvim/init.lua:66: module 'cellular-automaton' not found:
        no field package.preload['cellular-automaton']
        no file './cellular-automaton.lua'
        no file '/opt/homebrew/share/luajit-2.1.0-beta3/cellular-automaton.lua'
        no file '/usr/local/share/lua/5.1/cellular-automaton.lua'
        no file '/usr/local/share/lua/5.1/cellular-automaton/init.lua'
        no file '/opt/homebrew/share/lua/5.1/cellular-automaton.lua'
        no file '/opt/homebrew/share/lua/5.1/cellular-automaton/init.lua'
        no file '/Users/********/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/cellular-automaton.lua'
        no file '/Users/********/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/cellular-automaton/init.lua'
        no file '/Users/********/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/cellular-automaton.lua'
        no file '/Users/********/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/cellular-automaton/init.lua'
        no file './cellular-automaton.so'
        no file '/usr/local/lib/lua/5.1/cellular-automaton.so'
        no file '/opt/homebrew/lib/lua/5.1/cellular-automaton.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/Users/********/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/cellular-automaton.so'

Animation randomly stops

image

Animation seems to randomly stop until i interact with the terminal then it runs for couple seconds and stops again

When I make_it_rain lualine doesn't exist.

Hello.

Awesome plugin, thank you for creating it.
When calling on :CellularAutomaton make_it_rain, lualine doesn't exist during the animation.
Also when quiting the animation, and lualine gets back the git diffs below are not displayed anymore.

I use this plugin quite often hence why I am nitpicking.

Animation doesn’t start

This doesn’t seem to work at all on my computer:
Neovim 0.8.1, treesitter 0.1.x branch, running on Ubuntu 22.04.

Steps to reproduce

  • start nvim
  • :CellularAutomaton make_it_rain

Expected result

animation bliss

Actual result

Error executing Lua callback: .../cellular-automaton.nvim/lua/cellular-automaton/load.lua:84: attempt to index a nil value                                                                                                                     
stack traceback:                                                                                                                                                                                                                               
        .../cellular-automaton.nvim/lua/cellular-automaton/load.lua:84: in function 'load_base_grid'                                                                                                                                           
        ...llular-automaton.nvim/lua/cellular-automaton/manager.lua:38: in function 'execute_animation'                                                                                                                                        
        .../cellular-automaton.nvim/lua/cellular-automaton/init.lua:42: in function 'start_animation'                                                                                                                                          
        ...rt/cellular-automaton.nvim/plugin/cellular-automaton.lua:16: in function <...rt/cellular-automaton.nvim/plugin/cellular-automaton.lua:15>                                                                                           
Press ENTER or type command to continue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.