drawille 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/Rakefile +6 -0
- data/{ruby-drawille.gemspec → drawille.gemspec} +3 -3
- data/lib/{ruby-drawille.rb → drawille.rb} +28 -1
- data/lib/{ruby-drawille → drawille}/version.rb +1 -1
- data/spec/drawille_spec.rb +107 -0
- data/spec/sinus.dat +6 -0
- data/spec/spec_helper.rb +15 -0
- metadata +19 -17
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDIyMDkxN2Y3YmYxYWEzMDMwZDBlNGQ5MDE1MzAyZTM5MWNlZDZjMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2VmODE0YmRhMzZmNzI1NGZmOTAwNmUxODEzNDM0MTQwNDcwY2NiMQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZGYxYTk4OTQyZWIzYzRlMzBmNjhhMjdjZDc1OTdlMzZmN2IzYTNkNzE5NTI5
|
10
|
+
MGUwMjc1NjU1OGY2ZGEzNWFlNGEzNzliY2U2NjY3MmI0MDNjNWFkZGRlODg5
|
11
|
+
YzZlOTlhMzRkODZmZjY1M2VjODY1MmMzMzQ3ZTNjZDRhMDE1NWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjJhOGU4MjJkMGQ1NmMyMDkzNDViYjY1Mjc0MjlhZDc3ODk1YWVkZWIzYmNl
|
14
|
+
YWViOTc3ODZmYWIzMWZmNDliY2EwM2UzODE2YjY4MzgxMWM0ZjE1Yzk0N2Rl
|
15
|
+
MDdmYjhkY2RmYjg0ZGFkMjY1MTJkOGQxYzNjM2MzMzk1YjlhY2Q=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Drawing in terminal with Unicode [Braille][] characters. Implementation based on
|
|
11
11
|
|
12
12
|
Add this line to your application's Gemfile:
|
13
13
|
|
14
|
-
gem '
|
14
|
+
gem 'drawille'
|
15
15
|
|
16
16
|
And then execute:
|
17
17
|
|
@@ -19,7 +19,7 @@ And then execute:
|
|
19
19
|
|
20
20
|
Or install it yourself as:
|
21
21
|
|
22
|
-
$ gem install
|
22
|
+
$ gem install drawille
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
data/Rakefile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'drawille/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "drawille"
|
8
8
|
gem.version = Drawille::VERSION
|
9
9
|
gem.authors = ["Marcin Skirzynski"]
|
10
|
-
gem.
|
11
|
-
gem.description = %q{Drawing in terminal with Unicode Braille characters.}
|
10
|
+
gem.description = %q{Drawing in terminal.}
|
12
11
|
gem.summary = %q{Drawing in terminal with Unicode Braille characters.}
|
12
|
+
gem.license = "MIT"
|
13
13
|
gem.homepage = "https://github.com/maerch/ruby-drawille"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require "
|
2
|
+
require "drawille/version"
|
3
3
|
|
4
4
|
module Drawille
|
5
5
|
|
6
6
|
class Canvas
|
7
7
|
|
8
|
+
attr_reader :chars
|
9
|
+
|
8
10
|
PIXEL_MAP = [[0x01, 0x08],
|
9
11
|
[0x02, 0x10],
|
10
12
|
[0x04, 0x20],
|
@@ -25,6 +27,27 @@ module Drawille
|
|
25
27
|
@chars[py][px] |= PIXEL_MAP[y % 4][x % 2]
|
26
28
|
end
|
27
29
|
|
30
|
+
def unset x, y
|
31
|
+
x, y, px, py = convert x, y
|
32
|
+
@chars[py][px] &= ~PIXEL_MAP[y % 4][x % 2]
|
33
|
+
end
|
34
|
+
|
35
|
+
def get x, y
|
36
|
+
x, y, px, py = convert x, y
|
37
|
+
@chars[py][px] & PIXEL_MAP[y % 4][x % 2] != 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def []= x, y, bool
|
41
|
+
bool ? set(x, y) : unset(x, y)
|
42
|
+
end
|
43
|
+
|
44
|
+
alias_method :[], :get
|
45
|
+
|
46
|
+
def toggle x, y
|
47
|
+
x, y, px, py = convert x, y
|
48
|
+
@chars[py][px] & PIXEL_MAP[y % 4][x % 2] == 0 ? set(x, y) : unset(x, y)
|
49
|
+
end
|
50
|
+
|
28
51
|
def row y, options={}
|
29
52
|
row = @chars[y]
|
30
53
|
min = options[:min_x] || row.keys.min
|
@@ -45,6 +68,10 @@ module Drawille
|
|
45
68
|
rows(options).join("\n")
|
46
69
|
end
|
47
70
|
|
71
|
+
def char x, y
|
72
|
+
to_braille @chars[y][x]
|
73
|
+
end
|
74
|
+
|
48
75
|
private
|
49
76
|
|
50
77
|
def convert x, y
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Drawille do
|
5
|
+
subject { Drawille::Canvas.new }
|
6
|
+
|
7
|
+
describe '#set' do
|
8
|
+
it 'sets pixel in the first char in the first row' do
|
9
|
+
set_and_check_char (0..1), (0..3), 0, 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'sets pixel in the third char in the first row' do
|
13
|
+
set_and_check_char (4..5), (0..3), 2, 0
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets pixel in the second char in the second row' do
|
17
|
+
set_and_check_char (2..3), (4..7), 1, 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#unset" do
|
22
|
+
it 'sets and unsets a pixel' do
|
23
|
+
subject.set(0, 0)
|
24
|
+
expect(subject.char(0, 0)).to eq BRAILLE[0]
|
25
|
+
subject.unset(0, 0)
|
26
|
+
expect(subject.char(0, 0)).to eq BRAILLE.last
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets four pixel but only unsets one' do
|
30
|
+
subject.set(0, 0)
|
31
|
+
subject.set(0, 1)
|
32
|
+
subject.set(1, 0)
|
33
|
+
subject.set(1, 1)
|
34
|
+
expect(subject.char(0, 0)).to eq BRAILLE[3]
|
35
|
+
subject.unset(1, 1)
|
36
|
+
expect(subject.char(0, 0)).to eq BRAILLE[2]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#get" do
|
41
|
+
it 'returns the state of a pixel' do
|
42
|
+
subject.set(1, 1)
|
43
|
+
expect(subject.get(0, 0)).to eq false
|
44
|
+
expect(subject.get(1, 1)).to eq true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#toggle" do
|
49
|
+
it 'toggles a pixel' do
|
50
|
+
subject.toggle(0, 0)
|
51
|
+
subject.toggle(1, 0)
|
52
|
+
expect(subject.char(0, 0)).to eq BRAILLE[1]
|
53
|
+
subject.toggle(1, 0)
|
54
|
+
expect(subject.char(0, 0)).to eq BRAILLE[0]
|
55
|
+
subject.toggle(0, 0)
|
56
|
+
expect(subject.char(0, 0)).to eq BRAILLE.last
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#clear" do
|
61
|
+
it 'clears the canvas' do
|
62
|
+
subject.set(0, 0)
|
63
|
+
subject.set(2, 0)
|
64
|
+
expect(subject.char(0, 0)).to eq BRAILLE[0]
|
65
|
+
expect(subject.char(1, 0)).to eq BRAILLE[0]
|
66
|
+
subject.clear
|
67
|
+
expect(subject.char(0, 0)).to eq BRAILLE.last
|
68
|
+
expect(subject.char(1, 0)).to eq BRAILLE.last
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#[]' do
|
73
|
+
it 'works with alternate syntax' do
|
74
|
+
subject[0, 0] = true
|
75
|
+
expect(subject.char(0, 0)).to eq BRAILLE[0]
|
76
|
+
expect(subject[0, 0]).to eq true
|
77
|
+
expect(subject[1, 0]).to eq false
|
78
|
+
subject[0, 0] = false
|
79
|
+
expect(subject.char(0, 0)).to eq BRAILLE.last
|
80
|
+
expect(subject[0, 0]).to eq false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#rows" do
|
85
|
+
it 'has over 9 columns and 3 rows' do
|
86
|
+
subject.set(0, 1)
|
87
|
+
subject.set(4, 4)
|
88
|
+
subject.set(8, 5)
|
89
|
+
subject.set(16, 8)
|
90
|
+
|
91
|
+
expect(subject.rows.size).to eq 3
|
92
|
+
subject.rows.each do |row|
|
93
|
+
expect(row.length).to eq 9
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#frame" do
|
99
|
+
it 'prints a happy sinus' do
|
100
|
+
(0..1800).step(10).each do |x|
|
101
|
+
subject.set(x/10, 10 + Math.sin(x * Math::PI / 180) * 10)
|
102
|
+
end
|
103
|
+
expect(subject.frame).to eq IO.read("spec/sinus.dat")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
data/spec/sinus.dat
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠒⠉⠑⠢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠒⠉⠑⠢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠒⠉⠑⠢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠒⠉⠑⠢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠒⠉⠑⠢⠀⠀⠀
|
2
|
+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡐⠁⠀⠀⠀⠀⠑⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡐⠁⠀⠀⠀⠀⠑⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡐⠁⠀⠀⠀⠀⠑⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡐⠁⠀⠀⠀⠀⠑⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡐⠁⠀⠀⠀⠀⠑⡀⠀
|
3
|
+
⠄⠀⠀⠀⠀⠀⠀⠀⠀⠌⠀⠀⠀⠀⠀⠀⠀⠈⠄⠀⠀⠀⠀⠀⠀⠀⠀⠌⠀⠀⠀⠀⠀⠀⠀⠈⠄⠀⠀⠀⠀⠀⠀⠀⠀⠌⠀⠀⠀⠀⠀⠀⠀⠈⠄⠀⠀⠀⠀⠀⠀⠀⠀⠌⠀⠀⠀⠀⠀⠀⠀⠈⠄⠀⠀⠀⠀⠀⠀⠀⠀⠌⠀⠀⠀⠀⠀⠀⠀⠈⠄
|
4
|
+
⠈⢂⠀⠀⠀⠀⠀⢀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢂⠀⠀⠀⠀⠀⢀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢂⠀⠀⠀⠀⠀⢀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢂⠀⠀⠀⠀⠀⢀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢂⠀⠀⠀⠀⠀⢀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
5
|
+
⠀⠀⠡⣀⠀⢀⡠⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠡⣀⠀⢀⡠⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠡⣀⠀⢀⡠⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠡⣀⠀⢀⡠⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠡⣀⠀⢀⡠⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
6
|
+
⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'drawille'
|
3
|
+
|
4
|
+
BRAILLE = %w[⠁ ⠉ ⠋ ⠛ ⠟ ⠿ ⡿ ⣿ ⠀]
|
5
|
+
|
6
|
+
def set_and_check_char px_range, py_range, cx, cy
|
7
|
+
i = 0
|
8
|
+
py_range.each do |y|
|
9
|
+
px_range.each do |x|
|
10
|
+
subject.set(x, y)
|
11
|
+
expect(subject.char(cx, cy)).to eq BRAILLE[i]
|
12
|
+
i += 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drawille
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Marcin Skirzynski
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,14 +20,12 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
|
-
description: Drawing in terminal
|
31
|
-
email:
|
32
|
-
- marcin.skirzynski@gmail.com
|
27
|
+
description: Drawing in terminal.
|
28
|
+
email:
|
33
29
|
executables: []
|
34
30
|
extensions: []
|
35
31
|
extra_rdoc_files: []
|
@@ -39,31 +35,37 @@ files:
|
|
39
35
|
- LICENSE.txt
|
40
36
|
- README.md
|
41
37
|
- Rakefile
|
42
|
-
-
|
43
|
-
- lib/
|
44
|
-
-
|
38
|
+
- drawille.gemspec
|
39
|
+
- lib/drawille.rb
|
40
|
+
- lib/drawille/version.rb
|
41
|
+
- spec/drawille_spec.rb
|
42
|
+
- spec/sinus.dat
|
43
|
+
- spec/spec_helper.rb
|
45
44
|
homepage: https://github.com/maerch/ruby-drawille
|
46
|
-
licenses:
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
47
48
|
post_install_message:
|
48
49
|
rdoc_options: []
|
49
50
|
require_paths:
|
50
51
|
- lib
|
51
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
53
|
requirements:
|
54
54
|
- - ! '>='
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
58
|
requirements:
|
60
59
|
- - ! '>='
|
61
60
|
- !ruby/object:Gem::Version
|
62
61
|
version: '0'
|
63
62
|
requirements: []
|
64
63
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
64
|
+
rubygems_version: 2.2.2
|
66
65
|
signing_key:
|
67
|
-
specification_version:
|
66
|
+
specification_version: 4
|
68
67
|
summary: Drawing in terminal with Unicode Braille characters.
|
69
|
-
test_files:
|
68
|
+
test_files:
|
69
|
+
- spec/drawille_spec.rb
|
70
|
+
- spec/sinus.dat
|
71
|
+
- spec/spec_helper.rb
|