Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New styles: raw code: add Fall, burn #13

Open
daUnknownCoder opened this issue May 9, 2024 · 0 comments
Open

New styles: raw code: add Fall, burn #13

daUnknownCoder opened this issue May 9, 2024 · 0 comments

Comments

@daUnknownCoder
Copy link

idk how to add a pull request, ik how to but i am not able to change the code, here are the code for the two...

`Fall` nicknamed as `Make_It_Rain` (Click me bro)

from Eandrju/cellular-automaton.nvim

local M = {
  fps = 50,
  side_noise = true,
  disperse_rate = 3,
}

local frame

local cell_empty = function(grid, x, y)
  if x > 0 and x <= #grid and y > 0 and y <= #grid[x] and grid[x][y].char == " " then
    return true
  end
  return false
end

local swap_cells = function(grid, x1, y1, x2, y2)
  grid[x1][y1], grid[x2][y2] = grid[x2][y2], grid[x1][y1]
end

M.init = function(grid)
  frame = 1
end

M.update = function(grid)
  frame = frame + 1
  -- reset 'processed' flag
  for i = 1, #grid, 1 do
    for j = 1, #grid[i] do
      grid[i][j].processed = false
    end
  end
  local was_state_updated = false
  for x0 = #grid - 1, 1, -1 do
    for i = 1, #grid[x0] do
      -- iterate through grid from bottom to top using snake move
      -- >>>>>>>>>>>>
      -- ^<<<<<<<<<<<
      -- >>>>>>>>>>>^
      local y0
      if (frame + x0) % 2 == 0 then
        y0 = i
      else
        y0 = #grid[x0] + 1 - i
      end
      local cell = grid[x0][y0]

      -- skip spaces and comments or already proccessed cells
      if cell.char == " " or string.find(cell.hl_group or "", "comment") or cell.processed == true then
        goto continue
      end

      cell.processed = true

      -- to introduce some randomness sometimes step aside
      if M.side_noise then
        local random = math.random()
        local side_step_probability = 0.05
        if random < side_step_probability then
          was_state_updated = true
          if cell_empty(grid, x0, y0 + 1) then
            swap_cells(grid, x0, y0, x0, y0 + 1)
          end
        elseif random < 2 * side_step_probability then
          was_state_updated = true
          if cell_empty(grid, x0, y0 - 1) then
            swap_cells(grid, x0, y0, x0, y0 - 1)
          end
        end
      end

      -- either go one down
      if cell_empty(grid, x0 + 1, y0) then
        swap_cells(grid, x0, y0, x0 + 1, y0)
        was_state_updated = true
      else
        -- or to the side
        local disperse_direction = cell.disperse_direction or ({ -1, 1 })[math.random(1, 2)]
        local last_pos = { x0, y0 }
        for d = 1, M.disperse_rate do
          local y = y0 + disperse_direction * d
          -- prevent teleportation
          if not cell_empty(grid, x0, y) then
            cell.disperse_direction = disperse_direction * -1
            break
          elseif last_pos[1] == x0 then
            swap_cells(grid, last_pos[1], last_pos[2], x0, y)
            was_state_updated = true
            last_pos = { x0, y }
          end
          if cell_empty(grid, x0 + 1, y) then
            swap_cells(grid, last_pos[1], last_pos[2], x0 + 1, y)
            was_state_updated = true
            last_pos = { x0 + 1, y }
          end
        end
      end
      ::continue::
    end
  end
  return was_state_updated
end

return M
make_it_rain.mov
`Burn` nicknamed as `random_case` (Click me bro)

from fazibear/screen_saviour.nvim

local utils = require("screen_saviour.utils")

local M = {
  name = "random_case",
  fps = 10,
}

local change_char_case = function(char)
  local new_char = char
  if char.char >= "A" and char.char <= "Z" then
    new_char.char = string.lower(char.char)
  else
    new_char.char = string.upper(char.char)
  end
  return new_char
end

local change_word_case = function(word)
  local chars = {}
  local random = math.random(0, #word)
  for i = 1, #word do
    if i == random then
      table.insert(chars, word[i])
    else
      table.insert(chars, change_char_case(word[i]))
    end
  end
  return chars
end

M.update = function(grid)
  return utils.update_each(utils.is_letter, grid, change_word_case)
end

return M

asciicast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant