15
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ojichatグラフシェル芸

Last updated at Posted at 2019-12-15

ojichatグラフシェル芸とは?

o.png
こういう画像を作るシェル芸です。

コマンド

以下のコマンドで目的の画像が出力できます。

$ echo "digraph{👴[fontsize=100]👴🏻[fontsize=100]👴🏼[fontsize=100]👴->👴🏻[label=\"`ojichat|grep -Eo '.{1,14}'`\"]👴🏻->👴🏼[label=\"`ojichat|grep -Eo '.{1,14}'`\"]👴🏼->👴[label=\"`ojichat|grep -Eo '.{1,14}'`\"]}"|dot -Tpng>/images/o.png

ojichatの出力がランダムであるため、エッジのキャプションは実行するたびに変わります。

前提条件

graphvizojichatがインストールされていること。

コマンド解説

3つのノードをエッジでつないだグラフを描きます。

$ echo "digraph{A->B B->C C->A}"|dot -Tpng>/images/0.png

0.png
エッジにキャプションを添えます。

$ echo "digraph{A->B[label=\"from A to B\"] B->C[label=\"from B to C\"] C->A[label=\"from C to A\"]}"|dot -Tpng>/images/1.png

1.png

ノードに👴(OLDER MAN)を入れます。

$ echo "digraph{👴->👴🏻[label=\"from 👴 to 👴🏻\"] 👴🏻->👴 🏼[label=\"from 👴🏻 to 👴🏼\"] 👴🏼->👴[label=\"from 👴🏼 to 👴\"]}"|dot -Tpng>/images/2.png

2.png
👴🏻と👴🏼は👴に skin tone modifier を付けたものです。

エッジのキャプションをojichatの出力にします。

$ echo "digraph{👴->👴🏻[label=\"`ojichat`\"]👴🏻->👴🏼[label=\"`ojichat`\"]👴🏼->👴[label=\"`ojichat`\"]}"|dot -Tpng>/images/3.png

3.png

ojichatの出力が長すぎるので改行します。grep -Eo '.{1,14}'として、14文字で改行します。

$ echo "digraph{👴->👴🏻[label=\"`ojichat|grep -Eo '.{1,14}'`\"]👴🏻->👴🏼[label=\"`ojichat|grep -Eo '.{1,14}'`\"]👴🏼->👴[label=\"`ojichat|grep -Eo '.{1,14}'`\"]}"|dot -Tpng>/images/4.png

4.png

👴のサイズを調整します。
graphvizfontsizeを指定します。

$ echo "digraph{👴[fontsize=100]👴🏻[fontsize=100]👴🏼[fontsize=100]👴->👴🏻[label=\"`ojichat|grep -Eo '.{1,14}'`\"]👴🏻->👴🏼[label=\"`ojichat|grep -Eo '.{1,14}'`\"]👴🏼->👴[label=\"`ojichat|grep -Eo '.{1,14}'`\"]}"|dot -Tpng>/images/o.png

o.png
完成です。

所感

これをシェル芸botに投げたとき、「地獄」という反応が多かったんですけど、僕としては「優しい世界」のつもりでやっていました。
以上です。

15
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?