Last active
December 10, 2016 15:52
-
-
Save papiron/0d004922e5505db56b9a6dcd7e7bdc03 to your computer and use it in GitHub Desktop.
端末を指定した文字でランダムに埋め尽くす
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
元ネタはこちら。面白い! | |
http://raintrees.net/news/93 | |
https://twitter.com/kanata201612/status/806475573824360448 | |
https://twitter.com/kanata201612/status/806477105974259712 | |
https://twitter.com/kanata201612/status/806841499673444353 | |
元ネタをawkでやってみた。awkだと速すぎるのでsleepで遅く調整。終了はCtrl-cで。 | |
最初にカーソルを消しているので、終了後は tput init を実行しよう。 | |
・tput cols 端末の幅(列数) | |
・tput lines 端末の高さ(行数) | |
・tput vi カーソルを消す(MacOS, FreeBSD) | |
・tput clvis カーソルを消す(Ubuntu) | |
・awk -vchar=F 埋尽くす文字の指定(英数字1文字を想定) | |
### MacOS Sierra、FreeBSD 9.2-RELEASE | |
$ clear; tput vi; yes 'echo; sleep 0.01' | bash | awk -vcols=$(tput cols) -vlines=$(tput lines) -vchar=F 'BEGIN{srand()}{printf "\033[%d;%df%c",int(lines*rand()),int(cols*rand()),char;fflush()}' | |
### Ubuntu 16.04 | |
$ clear; tput clvis; yes 'echo; sleep 0.01' | bash | awk -vcols=$(tput cols) -vlines=$(tput lines) -vchar=F 'BEGIN{srand()}{printf "\033[%d;%df%c",int(lines*rand()),int(cols*rand()),char;fflush()}' | |
tputコマンドの方がわかりやすい気がしたので作って見た。こちらも終了後に tput init を実行してカーソルを表示させよう。 | |
しかしOS毎にtputコマンドの動きが違うのがちと残念。 | |
端末を制御するtputコマンドについてはこちら。 | |
http://news.mynavi.jp/articles/2011/01/12/tput-of-ubuntu-and-freebsd/ | |
・tput vi カーソルを消す(MacOS, FreeBSD) | |
・tput clvis カーソルを消す(Ubuntu) | |
・tput cup x y カーソルをx行y列に移動(MacOS, Ubuntu) | |
・tput cm x y カーソルをx列y行に移動(FreeBSD) | |
### MacOS Sierra 10.12.1 | |
$ clear; tput vi; yes | awk -vcols=$(tput cols) -vlines=$(tput lines) -vchar=F 'BEGIN{srand()}{printf "tput cup %d %d; echo -n %s\n",int(lines*rand()),int(cols*rand())";",char}' | bash | |
### Ubuntu 16.04 | |
$ clear; tput civis; yes | awk -vcols=$(tput cols) -vlines=$(tput lines) -vchar=F 'BEGIN{srand()}{printf "tput cup %d %d; echo -n %s\n",int(lines*rand()),int(cols*rand())";",char}' | bash | |
### FreeBSD 9.2-RELEASE | |
$ clear; tput vi; yes | awk -vcols=$(tput cols) -vlines=$(tput lines) -vchar=F 'BEGIN{srand()}{printf "tput cm %d %d; echo -n %s\n",int(cols*rand()),int(lines*rand()),char}' | bash寿司 | |
寿司の絵文字で埋め尽くす | |
### MacOS Sierra 10.12.1 | |
$ clear; tput vi; yes | awk -vcols=$(tput cols) -vlines=$(tput lines) -vchar=🍣 'BEGIN{srand()}{printf "tput cup %d %d; echo -n %s; sleep 0.001\n",int(lines*rand()),2*int((cols/2)*rand())";",char}' | bash | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment