yhara-ruby-sl 0.1 → 0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/ChangeLog +3 -0
  2. data/Rakefile +144 -0
  3. data/lib/sl.rb +198 -0
  4. metadata +1 -1
@@ -0,0 +1,3 @@
1
+ 2008-12-18 Yutaka HARA <yhara(at)kmc.gr.jp>
2
+
3
+ * initial release.
@@ -0,0 +1,144 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'rake/contrib/sshpublisher'
10
+ require 'fileutils'
11
+ require 'lib/sl'
12
+ include FileUtils
13
+
14
+ NAME = "ruby-sl"
15
+ AUTHOR = "Yutaka HARA"
16
+ EMAIL = "yutaka.hara+github@gmail.com"
17
+ DESCRIPTION = ""
18
+ RUBYFORGE_PROJECT = "rubysl"
19
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
+ BIN_FILES = %w( )
21
+
22
+ VERS = SL::VERSION
23
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
24
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
25
+ RDOC_OPTS = [
26
+ '--title', "#{NAME} documentation",
27
+ "--charset", "utf-8",
28
+ "--opname", "index.html",
29
+ "--line-numbers",
30
+ "--main", "README",
31
+ "--inline-source",
32
+ ]
33
+
34
+ task :default => [:test]
35
+ task :package => [:clean]
36
+
37
+ Rake::TestTask.new("test") do |t|
38
+ t.libs << "test"
39
+ t.pattern = "test/**/*_test.rb"
40
+ t.verbose = true
41
+ end
42
+
43
+ spec = Gem::Specification.new do |s|
44
+ s.name = NAME
45
+ s.version = VERS
46
+ s.platform = Gem::Platform::RUBY
47
+ s.has_rdoc = true
48
+ s.extra_rdoc_files = ["README", "ChangeLog"]
49
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
50
+ s.summary = DESCRIPTION
51
+ s.description = DESCRIPTION
52
+ s.author = AUTHOR
53
+ s.email = EMAIL
54
+ s.homepage = HOMEPATH
55
+ s.executables = BIN_FILES
56
+ s.rubyforge_project = RUBYFORGE_PROJECT
57
+ s.bindir = "bin"
58
+ s.require_path = "lib"
59
+ #s.autorequire = ""
60
+ s.test_files = Dir["test/*_test.rb"]
61
+
62
+ #s.add_dependency('activesupport', '>=1.3.1')
63
+ #s.required_ruby_version = '>= 1.8.2'
64
+
65
+ s.files = %w(README ChangeLog Rakefile) +
66
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
67
+ Dir.glob("ext/**/*.{h,c,rb}") +
68
+ Dir.glob("examples/**/*.rb") +
69
+ Dir.glob("tools/*.rb") +
70
+ Dir.glob("rails/*.rb")
71
+
72
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
73
+ end
74
+
75
+ Rake::GemPackageTask.new(spec) do |p|
76
+ p.need_tar = true
77
+ p.gem_spec = spec
78
+ end
79
+
80
+ task :install do
81
+ name = "#{NAME}-#{VERS}.gem"
82
+ sh %{rake package}
83
+ sh %{sudo gem install pkg/#{name}}
84
+ end
85
+
86
+ task :uninstall => [:clean] do
87
+ sh %{sudo gem uninstall #{NAME}}
88
+ end
89
+
90
+
91
+ Rake::RDocTask.new do |rdoc|
92
+ rdoc.rdoc_dir = 'html'
93
+ rdoc.options += RDOC_OPTS
94
+ rdoc.template = "resh"
95
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
96
+ if ENV['DOC_FILES']
97
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
98
+ else
99
+ rdoc.rdoc_files.include('README', 'ChangeLog')
100
+ rdoc.rdoc_files.include('lib/**/*.rb')
101
+ rdoc.rdoc_files.include('ext/**/*.c')
102
+ end
103
+ end
104
+
105
+ desc "Publish to RubyForge"
106
+ task :rubyforge => [:rdoc, :package] do
107
+ require 'rubyforge'
108
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'yhara').upload
109
+ end
110
+
111
+ desc 'Package and upload the release to rubyforge.'
112
+ task :release => [:clean, :package] do |t|
113
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
114
+ abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
115
+ pkg = "pkg/#{NAME}-#{VERS}"
116
+
117
+ require 'rubyforge'
118
+ rf = RubyForge.new.configure
119
+ puts "Logging in"
120
+ rf.login
121
+
122
+ c = rf.userconfig
123
+ # c["release_notes"] = description if description
124
+ # c["release_changes"] = changes if changes
125
+ c["preformatted"] = true
126
+
127
+ files = [
128
+ "#{pkg}.tgz",
129
+ "#{pkg}.gem"
130
+ ].compact
131
+
132
+ puts "Releasing #{NAME} v. #{VERS}"
133
+ rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
134
+ end
135
+
136
+ desc 'Show information about the gem.'
137
+ task :debug_gem do
138
+ puts spec.to_ruby
139
+ end
140
+
141
+ desc 'Update gem spec'
142
+ task :gemspec do
143
+ open("#{NAME}.gemspec", 'w').write spec.to_ruby
144
+ end
@@ -0,0 +1,198 @@
1
+ require 'curses'
2
+
3
+ module SL
4
+
5
+ VERSION = "0.11"
6
+
7
+ def self.run!
8
+ init
9
+ run
10
+ end
11
+
12
+ def self.init
13
+ Curses.init_screen
14
+ Curses.clear
15
+ Curses.refresh
16
+ Curses.noecho
17
+ end
18
+
19
+ def self.run
20
+ h = Curses.lines
21
+ w = Curses.cols
22
+ win = Curses::Window.new(h, w, 0, 0)
23
+ D51.new(h, w).run(win)
24
+ end
25
+
26
+ class Actor
27
+
28
+ def initialize(lines, cols)
29
+ @lines, @cols = lines, cols
30
+ end
31
+
32
+ def putstr(win, y, x, str)
33
+ return if x >= @cols
34
+ if x < 0
35
+ str = str[-x-1 .. -1] or return
36
+ x = 0
37
+ end
38
+ if (x + str.size) >= @cols
39
+ str = str[0 ... (@cols - x)]
40
+ end
41
+ win.setpos(y, x)
42
+ win.addstr(str)
43
+ end
44
+
45
+ end
46
+
47
+ class Smoke < Actor
48
+ SMOKEPTNS = 16
49
+ Item = Struct.new(:y, :x, :ptrn, :kind)
50
+ Smokes = [["( )", "( )", "( )", "( )", "( )",
51
+ "( )" , "( )" , "( )" , "()" , "()" ,
52
+ "O" , "O" , "O" , "O" , "O" ,
53
+ " " ],
54
+ ["(@@@)", "(@@@@)", "(@@@@)", "(@@@)", "(@@)",
55
+ "(@@)" , "(@)" , "(@)" , "@@" , "@@" ,
56
+ "@" , "@" , "@" , "@" , "@" ,
57
+ " " ]]
58
+ Eraser = [" ", " ", " ", " ", " ",
59
+ " " , " " , " " , " " , " " ,
60
+ " " , " " , " " , " " , " " ,
61
+ " " ]
62
+
63
+ DY = [ 2, 1, 1, 1, 0, 0, 0, 0, 0, 0,
64
+ 0, 0, 0, 0, 0, 0 ]
65
+ DX = [-2, -1, 0, 1, 1, 1, 1, 1, 2, 2,
66
+ 2, 2, 2, 3, 3, 3 ]
67
+
68
+ def initialize(lines, cols)
69
+ super
70
+ @s = []
71
+ @sum = 0
72
+ end
73
+
74
+ def put(win, y, x)
75
+ if (x % 4 == 0)
76
+ @sum.times do |i|
77
+ putstr(win, @s[i].y, @s[i].x, Eraser[@s[i].ptrn]);
78
+ @s[i].y -= DY[@s[i].ptrn];
79
+ @s[i].x += DX[@s[i].ptrn];
80
+ @s[i].ptrn += (@s[i].ptrn < SMOKEPTNS - 1) ? 1 : 0;
81
+ putstr(win, @s[i].y, @s[i].x, Smokes[@s[i].kind][@s[i].ptrn]);
82
+ end
83
+ putstr(win, y, x, Smokes[@sum % 2][0]);
84
+ @s[@sum] = Item.new
85
+ @s[@sum].y = y; @s[@sum].x = x;
86
+ @s[@sum].ptrn = 0; @s[@sum].kind = @sum % 2;
87
+ @sum += 1;
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ class D51 < Actor
94
+ HEIGHT = 10
95
+ FUNNEL = 7
96
+ LENGTH = 83
97
+ PATTERNS = 6
98
+
99
+ D51_BODY = [
100
+ " ==== ________ ___________ ",
101
+ " _D _| |_______/ \\__I_I_____===__|_________| ",
102
+ " |(_)--- | H\\________/ | | =|___ ___| ",
103
+ " / | | H | | | | ||_| |_|| ",
104
+ " | | | H |__--------------------| [___] | ",
105
+ " | ________|___H__/__|_____/[][]~\\_______| | ",
106
+ " |/ | |-----------I_____I [][] [] D |=======|__ "
107
+ ]
108
+ D51_WHEEL = [
109
+ [
110
+ "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
111
+ " |/-=|___|= || || || |_____/~\\___/ ",
112
+ " \\_/ \\O=====O=====O=====O_/ \\_/ ",
113
+ ],
114
+ [
115
+ "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
116
+ " |/-=|___|=O=====O=====O=====O |_____/~\\___/ ",
117
+ " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ ",
118
+ ],
119
+ [
120
+ "__/ =| o |=-O=====O=====O=====O \\ ____Y___________|__ ",
121
+ " |/-=|___|= || || || |_____/~\\___/ ",
122
+ " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ ",
123
+ ],
124
+ [
125
+ "__/ =| o |=-~O=====O=====O=====O\\ ____Y___________|__ ",
126
+ " |/-=|___|= || || || |_____/~\\___/ ",
127
+ " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ ",
128
+ ],
129
+ [
130
+ "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
131
+ " |/-=|___|= O=====O=====O=====O|_____/~\\___/ ",
132
+ " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ ",
133
+ ],
134
+ [
135
+ "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ ",
136
+ " |/-=|___|= || || || |_____/~\\___/ ",
137
+ " \\_/ \\_O=====O=====O=====O/ \\_/ ",
138
+ ]
139
+ ]
140
+ D51_DEL = " "
141
+
142
+ COAL_BODY = [
143
+ " ",
144
+ " ",
145
+ " _________________ ",
146
+ " _| \\_____A ",
147
+ " =| | ",
148
+ " -| | ",
149
+ "__|________________________|_ ",
150
+ "|__________________________|_ ",
151
+ " |_D__D__D_| |_D__D__D_| ",
152
+ " \\_/ \\_/ \\_/ \\_/ ",
153
+ ]
154
+ COAL_DEL = " "
155
+
156
+
157
+ D51 = D51_WHEEL.map{|wheel|
158
+ D51_BODY + wheel + [D51_DEL]
159
+ }
160
+ COAL = COAL_BODY + [COAL_DEL]
161
+
162
+ def initialize(lines, cols)
163
+ super
164
+ @smoke = Smoke.new(lines, cols)
165
+ end
166
+
167
+ def run(win)
168
+ x = @cols - 1
169
+ loop do
170
+ break if put_D51(win, x).nil?
171
+ win.refresh
172
+ sleep(0.02)
173
+ x -= 1
174
+ end
175
+ end
176
+
177
+ private
178
+
179
+ def put_D51(win, x)
180
+ y = i = 0;
181
+ return nil if x < -LENGTH
182
+ y = @lines / 2 - 5
183
+
184
+ (0..HEIGHT).each do |i|
185
+ putstr(win, y + i, x, D51[(LENGTH + x) % PATTERNS][i]);
186
+ putstr(win, y + i, x + 53, COAL[i]);
187
+ end
188
+ @smoke.put(win, y - 1, x + FUNNEL);
189
+ return true
190
+ end
191
+
192
+ end
193
+
194
+ end
195
+
196
+ if $0==__FILE__
197
+ SL.run!
198
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yhara-ruby-sl
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: "0.11"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka HARA