Skip to content

Instantly share code, notes, and snippets.

@koron
Created November 29, 2022 15:52
Show Gist options
  • Save koron/ea4e89de9e7fdb608fa288246a25457d to your computer and use it in GitHub Desktop.
Save koron/ea4e89de9e7fdb608fa288246a25457d to your computer and use it in GitHub Desktop.
Vimでアニメーションを再生するいにしえのスクリプト

使い方

  1. 3つの *.vim ファイルをダウンロードする(CP932で保存する)
  2. 3つのファイルを同じディレクトリに置く
  3. Vimを起動して :source gikozuza.vim もしくは :source moukoneyo.vim
  4. 鑑賞する
if !has('clientserver')
finish
endif
command! -nargs=* Animate call Animate_start(<f-args>)
function! Animate_cursor(cols, rows)
silent! execute 'normal! '.a:rows.'G'.a:cols.'|'
endfunction
function! Animate_put(data, cols, rows)
let remain = a:data
let cols = a:cols < 0 ? 1 : a:cols + 1
let rows = a:rows + 1
while remain != '' && rows <= line('$')
let str = matchstr(remain, "^[^\<NL>]*")
let len = strlen(str)
let remain = strpart(remain, len + 1)
if rows >= 1
if a:cols < 0
let str = strpart(str, - a:cols)
endif
call Animate_cursor(cols, rows)
silent! execute 'normal! gR'.str
endif
let rows = rows + 1
endwhile
endfunction
function! Animate_clear()
silent! %s/^.*$//
let @/ = ''
endfunction
function! Animate_start(wait, proc)
let rows = 20
" Delete old buffer
while 1
let nr = bufwinnr('Animate')
if nr <= 0
break
endif
silent! execute nr.' wincmd w'
bwipeout!
endwhile
" Initialize animation buffer
silent! execute rows. ' new'
setlocal nowrap buftype=nofile noswapfile
silent! file Animate
let i = rows
while i > 1
call append('$', '')
let i = i - 1
endwhile
let b:animate = 1
let b:animate_frame = 0
let b:animate_rows = rows
let b:animate_proc = a:proc
let b:animate_save_updatetime = &updatetime
let &updatetime = a:wait < 10 ? 10 : a:wait
let b:animate_save_undolevels = &undolevels
set undolevels=-1
let b:animate_save_hlsearch = &hlsearch
set nohlsearch
let b:animate_save_virtualedit = &virtualedit
set virtualedit=all
let b:animate_save_lazyredraw = &lazyredraw
set nolazyredraw
" Setup timer and procedure function
let @a = 'load'
augroup Animate
autocmd!
autocmd CursorHold Animate call s:Proc()
autocmd BufLeave Animate call Animate_stop()
augroup END
endfunction
function! Animate_stop()
augroup Animate
au!
augroup END
if exists('b:animate_save_updatetime')
let &updatetime = b:animate_save_updatetime
unlet b:animate_save_updatetime
endif
if exists('b:animate_save_undolevels')
let &undolevels = b:animate_save_undolevels
unlet b:animate_save_undolevels
endif
if exists('b:animate_save_hlsearch')
let &hlsearch = b:animate_save_hlsearch
unlet b:animate_save_hlsearch
endif
if exists('b:animate_save_virtualedit')
let &virtualedit = b:animate_save_virtualedit
unlet b:animate_save_virtualedit
endif
if exists('b:animate_save_lazyredraw')
let &lazyredraw = b:animate_save_lazyredraw
unlet b:animate_save_lazyredraw
endif
endfunction
function! s:Proc()
if b:animate_proc != ''
if {b:animate_proc}(b:animate_frame) == 0
call Animate_stop()
endif
else
call setline(1, b:animate_frame)
endif
" Count up frame number
let b:animate_frame = b:animate_frame + 1
" Update screen
normal! gg0
redraw
call remote_send(v:servername, '0')
endfunction
source animate.vim
scriptencoding cp932
let s:giko = " ∧ ∧ )\<NL>"."⊂(゚Д゚⊂⌒`つ\<NL>"."  ̄ ̄ "
let s:zuza = " ズ ザ ー ー ー ー ッ"
let s:smoke = "(´⌒;;"
let s:ballon = "逝ってよしだゴルァ\<NL>"." ̄ ̄ ̄ ̄ ̄∨ ̄ ̄ ̄"
function! Gikozuza_proc(frame)
" 終了判定
if a:frame > 110
return 0
endif
" 画面クリア & ギコ猫
call Animate_clear()
let cols = 79 - a:frame
call Animate_put(s:giko, cols, 8)
" 砂煙
let frac3 = a:frame % 4
let frac1 = a:frame % 12
let frac2 = a:frame % 20
call Animate_put(s:smoke, cols + 7 + frac1 , 10 - frac1 / 3)
call Animate_put(s:smoke, cols + 10 + (frac2/2) , 9 - frac2 / 6)
call Animate_put(s:smoke, cols + 11 + frac3 * 5 , 9 - frac3)
" 効果音と台詞
call Animate_put(s:zuza, cols, 11)
if cols <= 20
call Animate_put(s:ballon, 11, 6)
endif
return 1
endfunction
function! Gikozuza()
call Animate_start(10, 'Gikozuza_proc')
endfunction
if 1 && exists('*Animate_start')
call Gikozuza()
else
echohl Error
echo "+clientserverじゃなきゃ動かないぞゴルァ!!"
echohl None
endif
source animate.vim
scriptencoding cp932
let s:flag = "┌─┐\<NL>"."|も|\<NL>"."|う│\<NL>"."│来│\<NL>"."│ね│\<NL>"."│え│\<NL>"."│よ│\<NL>"."│!!│\<NL>"."└─┤"
let s:train = " ヽ(`Д´)ノヽ(`Д´)ノ (`Д´)ノ ( `Д)\<NL>"." | ̄ ̄ ̄|─| ̄ ̄ ̄|─| ̄ ̄ ̄|─□( ヽ┐U \<NL>"."  ̄◎ ̄  ̄◎ ̄  ̄◎ ̄ ◎─>┘◎ \<NL>"
let s:foot1 = ">"
let s:foot2 = ")"
let s:baka = "バカ"
let s:gorua = "ゴルァ"
let s:pun = "プンプン"
let s:kiko = "キコ"
function! Moukoneyo_proc(frame)
if a:frame >= 200
return 0
endif
call Animate_clear()
" 位置設定
let y = 13
if a:frame < 100
let x = -70 + a:frame * 2
if x > 14
let x = 14
endif
else
let x = (a:frame - 100) * 3 + 14
if x > 100
return 0
endif
endif
" 列車とノボリを表示
call Animate_put(s:train, x, y)
call Animate_put(s:flag, x + 24, y - 9)
" 脚コギアニメーション
let st_kiko = (a:frame / 2) % 2
call Animate_put(s:kiko, x + 42 + st_kiko * 2, y + 1 + st_kiko)
if st_kiko
call Animate_put(s:foot2, x + 38, y + 2)
endif
" プンプン
let st_pun = (a:frame / 4) % 2
call Animate_put(s:pun, x + 33 + st_pun, y - 1)
" バカゴルァ点滅
let st_bakagorua = (a:frame / 3) % 4
if st_bakagorua == 1 || st_bakagorua == 2
call Animate_put(s:baka, x + 4, y - 2)
endif
if st_bakagorua == 2 || st_bakagorua == 3
call Animate_put(s:gorua, x + 14, y - 2)
endif
return 1
endfunction
function! Moukoneyo()
call Animate_start(20, 'Moukoneyo_proc')
endfunction
if 1 && exists('*Animate_start')
call Moukoneyo()
else
echohl Error
echo "+clientserverじゃなきゃ動かないぞゴルァ!!"
echohl None
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment