Created
November 21, 2020 13:09
-
-
Save okabe-yuya/6aada2fe6ee33db991c056100c90a33f to your computer and use it in GitHub Desktop.
ノベル形式で標準出力のデモ
This file contains 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
# 都度都度、sleepさせてあげれば動作を再現することは可能 | |
# パフォーマンスについては未検証。他に良い方法があれば知りたい | |
defmodule GamePrintf do | |
@print_interval 100 | |
@punctuations ["。", "、", ",", "."] | |
def print(content) do | |
IO.puts("[Info] #{content}") | |
end | |
def lst_print(contents) do | |
Enum.each(contents, fn c -> | |
:timer.sleep(@print_interval) | |
IO.write(c) | |
punctuations_sleep(c) | |
end) | |
IO.write("\n") | |
end | |
defp punctuations_sleep(c) do | |
if c in @punctuations do | |
:timer.sleep(@print_interval * 2) | |
end | |
end | |
def lst_print do | |
contents() |> lst_print() | |
end | |
def single_lst_print do | |
contents() | |
|> Enum.map(fn c -> String.codepoints(c) end) | |
|> Enum.each(fn s -> lst_print(s) end) | |
end | |
defp contents do | |
[ | |
"吾輩は猫である。名前はまだ無い。", | |
"どこで生れたかとんと見当がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。", | |
"吾輩はここで始めて人間というものを見た。", | |
"しかもあとで聞くとそれは書生という人間中で一番獰悪な種族であったそうだ。", | |
"この書生というのは時々我々を捕えて煮て食うという話である。", | |
"しかしその当時は何という考もなかったから別段恐しいとも思わなかった。", | |
"ただ彼の掌に載せられてスーと持ち上げられた時何だかフワフワした感じがあったばかりである。", | |
"掌の上で少し落ちついて書生の顔を見たのがいわゆる人間というものの見始であろう。", | |
"この時妙なものだと思った感じが今でも残っている。", | |
"第一毛をもって装飾されべきはずの顔がつるつるしてまるで薬缶だ。", | |
"その後猫にもだいぶ逢ったがこんな片輪には一度も出会わした事がない。", | |
"のみならず顔の真中があまりに突起している。そうしてその穴の中から時々ぷうぷうと煙を吹く。", | |
"どうも咽せぽくて実に弱った。これが人間の飲む煙草というものである事はようやくこの頃知った。", | |
] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment