shogi_koma 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6bd0db93a6a3bdb7dc48112a7cf5355e7a7091f9
4
+ data.tar.gz: aafc6b72752343ec90383b99fd8c1ba1dfe2fbc7
5
+ SHA512:
6
+ metadata.gz: 5dee3ba859709d9a5aa60b78f22d1b312b084c52f2ed7df8fa099debe001e5e861d47f47990f7c6a7abe961295ccbc3530fd429c1af93f002d345912344dfbbd
7
+ data.tar.gz: 5dcceba0267cb2da71c63d9829dbb37c2fa97f8c0f2a765d22b36cdc9a63cb5fa603fd9e3fd4a74245e6b844de80af72129d5618c8e24fa75a59209c94ad161f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shogi_koma.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Masafumi Yokoyama
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # ShogiKoma [![Build Status](https://secure.travis-ci.org/myokoym/shogi_koma.png?branch=master)](http://travis-ci.org/myokoym/shogi_koma)
2
+
3
+ An image generator for Shogi's pieces (it's "ko-ma" in Japanese) for Ruby by cairo.
4
+
5
+ ## Requirements
6
+
7
+ * [Ruby](https://www.ruby-lang.org/)
8
+ * [rcairo](https://github.com/rcairo/rcairo)
9
+ * [cairo](http://cairographics.org/)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem "shogi_koma"
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install shogi_koma
24
+
25
+ ## Usage
26
+
27
+ ### Write to PNG
28
+
29
+ ```ruby
30
+ require "shogi_koma"
31
+
32
+ painter = ShogiKoma::Painter.new
33
+ #painter.width = 200 # as default
34
+ #painter.height = 200 # as default
35
+ #painter.font = "IPAMincho" # as default
36
+ painter.write_to_png("歩", "fu.png")
37
+ ```
38
+
39
+ ### Draw to Cairo::Context
40
+
41
+ ```ruby
42
+ require "cairo"
43
+ require "shogi_koma"
44
+
45
+ Cairo::ImageSurface.new(:argb32, 40, 40) do |surface|
46
+ Cairo::Context.new(surface) do |context|
47
+ painter = ShogiKoma::Painter.new
48
+ #painter.font = "IPAMincho" # as default
49
+ painter.draw(context, "歩")
50
+ end
51
+ end
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run test"
4
+ task :test do
5
+ Bundler::GemHelper.install_tasks
6
+ ruby("-rubygems", "test/run-test.rb")
7
+ end
8
+
9
+ task :default => :test
data/lib/shogi_koma.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "shogi_koma/version"
2
+ require "shogi_koma/painter"
3
+
4
+ module ShogiKoma
5
+ end
@@ -0,0 +1,57 @@
1
+ require "cairo"
2
+
3
+ module ShogiKoma
4
+ class Painter
5
+ attr_accessor :width, :height, :font
6
+ def initialize
7
+ @width = 200
8
+ @height = 200
9
+ @font = "IPAMincho"
10
+ end
11
+
12
+ def write_to_png(text, output_path)
13
+ Cairo::ImageSurface.new(:argb32, @width, @height) do |surface|
14
+ Cairo::Context.new(surface) do |context|
15
+ context.scale(@width, @height)
16
+ draw(context, text)
17
+ end
18
+ surface.write_to_png(output_path)
19
+ end
20
+ end
21
+
22
+ def draw(context, text)
23
+ draw_body(context)
24
+ send("draw_text#{text.length}", context, text)
25
+ end
26
+
27
+ def draw_body(context)
28
+ context.set_line_width(0.01)
29
+ context.move_to(0.2, 0.2)
30
+ context.line_to(0.5, 0.1)
31
+ context.line_to(0.8, 0.2)
32
+ context.line_to(0.9, 0.9)
33
+ context.line_to(0.1, 0.9)
34
+ context.close_path
35
+ context.set_source_rgb(1, 0.8, 0.2)
36
+ context.fill_preserve
37
+ context.set_source_color(:black)
38
+ context.stroke
39
+ end
40
+
41
+ def draw_text1(context, text)
42
+ context.select_font_face(@font)
43
+ context.font_size = 0.6
44
+ context.move_to(0.2, 0.75)
45
+ context.show_text(text)
46
+ end
47
+
48
+ def draw_text2(context, text)
49
+ context.select_font_face(@font)
50
+ context.font_size = 0.4
51
+ context.move_to(0.3, 0.49)
52
+ context.show_text(text[0])
53
+ context.move_to(0.3, 0.85)
54
+ context.show_text(text[1])
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module ShogiKoma
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "shogi_koma"
5
+
6
+ painter = ShogiKoma::Painter.new
7
+ painter.width = 100
8
+ painter.height = 100
9
+ painter.font = "IPAMincho"
10
+ painter.write_to_png("歩", "fu.png")
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shogi_koma/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shogi_koma"
8
+ spec.version = ShogiKoma::VERSION
9
+ spec.authors = ["Masafumi Yokoyama"]
10
+ spec.email = ["myokoym@gmail.com"]
11
+ spec.description = %q{An image generator for Shogi's pieces (it's "ko-ma" in Japanese) for Ruby by cairo.}
12
+ spec.summary = %q{An image generater for Shogi's pieces}
13
+ spec.homepage = "https://github.com/myokoym/shogi_koma"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency("cairo")
22
+
23
+ spec.add_development_dependency("test-unit")
24
+ spec.add_development_dependency("test-unit-notify")
25
+ spec.add_development_dependency("test-unit-rr")
26
+ spec.add_development_dependency("bundler", "~> 1.3")
27
+ spec.add_development_dependency("rake")
28
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "test-unit"
4
+ require "test/unit/notify"
5
+ require "test/unit/rr"
6
+
7
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
8
+ $LOAD_PATH.unshift(File.join(base_dir, "lib"))
9
+ $LOAD_PATH.unshift(File.join(base_dir, "test"))
10
+
11
+ exit Test::Unit::AutoRunner.run(true)
@@ -0,0 +1,18 @@
1
+ require "shogi_koma/painter"
2
+ require "cairo"
3
+
4
+ class PainterTest < Test::Unit::TestCase
5
+ def setup
6
+ @painter = ShogiKoma::Painter.new
7
+ end
8
+
9
+ def test_draw
10
+ assert_nothing_raised do
11
+ Cairo::ImageSurface.new(:argb32, 100, 100) do |surface|
12
+ Cairo::Context.new(surface) do |context|
13
+ @painter.draw(context, "A")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shogi_koma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masafumi Yokoyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cairo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit-notify
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit-rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: An image generator for Shogi's pieces (it's "ko-ma" in Japanese) for
98
+ Ruby by cairo.
99
+ email:
100
+ - myokoym@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .travis.yml
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/shogi_koma.rb
112
+ - lib/shogi_koma/painter.rb
113
+ - lib/shogi_koma/version.rb
114
+ - sample/shogikoma.rb
115
+ - shogi_koma.gemspec
116
+ - test/run-test.rb
117
+ - test/test-painter.rb
118
+ homepage: https://github.com/myokoym/shogi_koma
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.0.3
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: An image generater for Shogi's pieces
142
+ test_files:
143
+ - test/run-test.rb
144
+ - test/test-painter.rb
145
+ has_rdoc: