Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mtoyoda/sl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: hypermkt/sl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Dec 7, 2023

  1. Ignore .idea directory

    hypermkt committed Dec 7, 2023
    Copy the full SHA
    f05fd48 View commit details
  2. Copy the full SHA
    f9d5213 View commit details

Commits on Dec 15, 2023

  1. Copy the full SHA
    bac9cfa View commit details
Showing with 194 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 Gemfile
  3. +13 −0 Gemfile.lock
  4. +27 −0 sl1.rb
  5. +43 −0 sl2.rb
  6. +106 −0 sl3.rb
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/sl
/.idea

3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem 'curses'
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
curses (1.4.4)

PLATFORMS
ruby

DEPENDENCIES
curses

BUNDLED WITH
2.1.4
27 changes: 27 additions & 0 deletions sl1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ========================================
# sl.c: SL version 5.03
# Copyright 1993,1998,2014-2015
# Toyoda Masashi
# (mtoyoda@acm.org)
# Last Modified: 2014/06/03
# ========================================
require "curses"
Curses.init_screen # Cursesの初期化
begin
Curses.curs_set(0) # カーソルを非表示
Curses.noecho # ユーザーの入力内容を画面に表示しない

0.upto(Curses.cols - 1) do |i|
Curses.clear
train = '🚃🚃🚃🚃🚃🚃🚃🚃🚃🚃🚃'
y = Curses.lines / 2 # 縦軸 中央表示
x = Curses.cols - train.length * 2 - i # 横軸 右端から表示
Curses.setpos(y, x)
Curses.addstr(train)
Curses.refresh # 画面を更新して変更を反映
sleep(0.1)
break if x <= 0 # 画面左まで到達したら終了
end
ensure
Curses.close_screen
end
43 changes: 43 additions & 0 deletions sl2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ========================================
# sl.c: SL version 5.03
# Copyright 1993,1998,2014-2015
# Toyoda Masashi
# (mtoyoda@acm.org)
# Last Modified: 2014/06/03
# ========================================
require "curses"
Curses.init_screen # Cursesの初期化
begin
Curses.curs_set(0) # カーソルを非表示
Curses.noecho # ユーザーの入力内容を画面に表示しない

0.upto(Curses.cols - 1) do |i|
Curses.clear

train = [
" ==== ________ ___________ ",
" _D _| |_______/ \\__I_I_____===__|_________| ",
" |(_)--- | H\\________/ | | =|___ ___| ",
" / | | H | | | | ||_| |_|| ",
" | | | H |__--------------------| [___] | ",
" | ________|___H__/__|_____/[][]~\\_______| | ",
" |/ | |-----------I_____I [][] [] D |=======|__ ",
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
" |/-=|___|= || || || |_____/~\\___/ ",
" \\_/ \\O=====O=====O=====O_/ \\_/ "
]

train.each_with_index do |line, index|
y = Curses.lines / 2 + index
x = Curses.cols - train[0].size - i
Curses.setpos(y, x)
Curses.addstr(line)
end

Curses.refresh # 画面を更新して変更を反映
sleep(0.1)
break if i >= Curses.cols - lines[0].size # 画面左まで到達したら終了
end
ensure
Curses.close_screen
end
106 changes: 106 additions & 0 deletions sl3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# ========================================
# sl.c: SL version 5.03
# Copyright 1993,1998,2014-2015
# Toyoda Masashi
# (mtoyoda@acm.org)
# Last Modified: 2014/06/03
# ========================================
require "curses"
Curses.init_screen # Cursesの初期化
begin
Curses.curs_set(0) # カーソルを非表示
Curses.noecho # ユーザーの入力内容を画面に表示しない

offset = 0
0.upto(Curses.cols - 1) do |i|
Curses.clear
train = []
train[0] = [
" ==== ________ ___________ ",
" _D _| |_______/ \\__I_I_____===__|_________| ",
" |(_)--- | H\\________/ | | =|___ ___| ",
" / | | H | | | | ||_| |_|| ",
" | | | H |__--------------------| [___] | ",
" | ________|___H__/__|_____/[][]~\\_______| | ",
" |/ | |-----------I_____I [][] [] D |=======|__ ",
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
" |/-=|___|= || || || |_____/~\\___/ ",
" \\_/ \\_O=====O=====O=====O/ \\_/ ",
]
train[1] = [
" ==== ________ ___________ ",
" _D _| |_______/ \\__I_I_____===__|_________| ",
" |(_)--- | H\\________/ | | =|___ ___| ",
" / | | H | | | | ||_| |_|| ",
" | | | H |__--------------------| [___] | ",
" | ________|___H__/__|_____/[][]~\\_______| | ",
" |/ | |-----------I_____I [][] [] D |=======|__ ",
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
" |/-=|___|= O=====O=====O=====O|_____/~\\___/ ",
" \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ ",
]
train[2] = [
" ==== ________ ___________ ",
" _D _| |_______/ \\__I_I_____===__|_________| ",
" |(_)--- | H\\________/ | | =|___ ___| ",
" / | | H | | | | ||_| |_|| ",
" | | | H |__--------------------| [___] | ",
" | ________|___H__/__|_____/[][]~\\_______| | ",
" |/ | |-----------I_____I [][] [] D |=======|__ ",
"__/ =| o |=-~O=====O=====O=====O\\ ____Y___________|__ ",
" |/-=|___|= || || || |_____/~\\___/ ",
" \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ ",
]
train[3] = [
" ==== ________ ___________ ",
" _D _| |_______/ \\__I_I_____===__|_________| ",
" |(_)--- | H\\________/ | | =|___ ___| ",
" / | | H | | | | ||_| |_|| ",
" | | | H |__--------------------| [___] | ",
" | ________|___H__/__|_____/[][]~\\_______| | ",
" |/ | |-----------I_____I [][] [] D |=======|__ ",
"__/ =| o |=-O=====O=====O=====O \\ ____Y___________|__ ",
" |/-=|___|= || || || |_____/~\\___/ ",
" \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ ",
]
train[4] = [
" ==== ________ ___________ ",
" _D _| |_______/ \\__I_I_____===__|_________| ",
" |(_)--- | H\\________/ | | =|___ ___| ",
" / | | H | | | | ||_| |_|| ",
" | | | H |__--------------------| [___] | ",
" | ________|___H__/__|_____/[][]~\\_______| | ",
" |/ | |-----------I_____I [][] [] D |=======|__ ",
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
" |/-=|___|=O=====O=====O=====O |_____/~\\___/ ",
" \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ ",
]
train[5] = [
" ==== ________ ___________ ",
" _D _| |_______/ \\__I_I_____===__|_________| ",
" |(_)--- | H\\________/ | | =|___ ___| ",
" / | | H | | | | ||_| |_|| ",
" | | | H |__--------------------| [___] | ",
" | ________|___H__/__|_____/[][]~\\_______| | ",
" |/ | |-----------I_____I [][] [] D |=======|__ ",
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
" |/-=|___|= || || || |_____/~\\___/ ",
" \\_/ \\O=====O=====O=====O_/ \\_/ "
]
train_length = train[0][0].size

train[offset].each_with_index do |line, index|
y = Curses.lines / 2 + index
x = Curses.cols - train_length - i
Curses.setpos(y, x)
Curses.addstr(line)
end
offset = (offset + 1) % 6 # コマ送りさせるため 0 - 5を連番で発番する

Curses.refresh # 画面を更新して変更を反映
sleep(0.1)
break if i >= Curses.cols - train_length # 画面左まで到達したら終了
end
ensure
Curses.close_screen
end