Skip to content

Instantly share code, notes, and snippets.

@kureikei
Created March 26, 2015 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kureikei/e0e158cf3ec40fdf3722 to your computer and use it in GitHub Desktop.
Save kureikei/e0e158cf3ec40fdf3722 to your computer and use it in GitHub Desktop.
on displayHaiku(haiku)
set haiku_lines to paragraphs of haiku -- 各行 (linesは予約後(の複数形)なので使えない!)
set max_length to 0 -- 一番長い行の文字数
repeat with ln in haiku_lines -- line、lengthは予約後なので使えない!
set len to length of ln
if max_length < len then set max_length to len
end repeat
set line_count to count haiku_lines -- 行数
set tategaki to ""
repeat with i from 1 to max_length
repeat with j from 1 to line_count
set ln to item (line_count + 1 - j) of haiku_lines -- 下の行から上の行へ
if length of ln ≥ i then -- 文字がなかった場合にエラーが出るからifで分けなきゃいけない
set chr to character i of ln -- 一文字ずつ取り出す
else
set chr to " " -- 文字数が足りない場合は空白で埋める
end if
set tategaki to tategaki & chr -- 文字を追加
end repeat
set tategaki to tategaki & "\n"
end repeat
-- 表示
-- say haiku -- せっかくだから喋らせたかったけど「いにしえいけや」って喋るからやめた
display alert tategaki buttons "よい"
end displayHaiku
displayHaiku("古池や\n蛙飛びこむ\n水の音")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment