drawille 0.2.1 → 0.3.0
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.
- checksums.yaml +8 -8
- data/README.md +38 -3
- data/drawille.gemspec +1 -0
- data/lib/drawille.rb +2 -0
- data/lib/drawille/brush.rb +2 -2
- data/lib/drawille/canvas.rb +2 -39
- data/lib/drawille/flipbook.rb +64 -0
- data/lib/drawille/frameable.rb +45 -0
- data/lib/drawille/version.rb +1 -1
- data/spec/drawille_spec.rb +245 -48
- data/spec/spec_helper.rb +2 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTlkNzYwOGIzNmE2NjEyZGE0ZWVhZjUzNGU2NmQwNjA0NDkwYTRjMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzYxODM4YjM2ZTQ1NjZlM2IxMDhlYjIwMGVlNDM3NmQ3YzQ0NWYxNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGJlODI1MzQwZWQxYTI5NDhhYzI2MGNhNDRiNThkZGMyNjczMDY0N2FkZGY1
|
10
|
+
MjE4MTZjZDFlYjE4MGZkYTI3MDhiYWZlNjI4MTZlNGM4OWI0ZGJlNzQ0ZGRh
|
11
|
+
NmI3YmU0MDNjZTVmZWVmMTNiNjc5Nzc5NGIwMWU5NTcxZDRhMmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDM2YzY4NjEwMjM5NjliYjc2MjI2ZDY0YmI0OTI2MGQ0ZTI1NzRjZGUyZDQ0
|
14
|
+
NTM4YjZiMzEyOTg3NjBlNjBkZmQ4YzZjMmU1NDNlODMxMjc1Zjg2OGVmYTQz
|
15
|
+
ZWQ0MTA0MzAwOTNlZjQ5MTNhYTE1ZGVkMWJhMDg1ZDQ4NGI1MWI=
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
Drawille for Ruby
|
2
2
|
========
|
3
|
+
[](http://badge.fury.io/rb/drawille)
|
3
4
|
|
4
5
|
Draw in your terminal with Unicode [Braille][] characters. Implementation based on [drawille][] by @asciimoo.
|
5
6
|
|
@@ -23,7 +24,7 @@ Or install it yourself as:
|
|
23
24
|
|
24
25
|
## Usage
|
25
26
|
|
26
|
-
Drawille can be used like the Python implementation due to the similar API. Here is
|
27
|
+
Drawille can be used like the Python implementation due to the similar API. Here is one of its examples:
|
27
28
|
|
28
29
|
```ruby
|
29
30
|
require 'drawille'
|
@@ -68,7 +69,7 @@ puts canvas.frame
|
|
68
69
|
|
69
70
|

|
70
71
|
|
71
|
-
This implementation also includes a Turtle graphics API for all your beloved fractals
|
72
|
+
This implementation also includes a [Turtle graphics](http://en.wikipedia.org/wiki/Turtle_graphics) API for all your beloved fractals:
|
72
73
|
|
73
74
|
```ruby
|
74
75
|
require 'drawille'
|
@@ -157,6 +158,40 @@ No point will be rendered by the ``#frame`` method.
|
|
157
158
|
|
158
159
|
Returns newline-delimited string of the given canvas state. Braille characters are used to represent points. Please note that a single character contains 2 x 4 pixels.
|
159
160
|
|
161
|
+
### Flip-book
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
c = Drawille::Canvas.new
|
165
|
+
f = Drawille::FlipBook.new
|
166
|
+
|
167
|
+
c.paint do
|
168
|
+
move 200, 100
|
169
|
+
down
|
170
|
+
|
171
|
+
36.times do
|
172
|
+
right 10
|
173
|
+
36.times do
|
174
|
+
right 10
|
175
|
+
forward 8
|
176
|
+
end
|
177
|
+
f.snapshot canvas
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
f.play repeat: true, fps: 6
|
183
|
+
```
|
184
|
+
|
185
|
+
With the flip-book it is possible to create and play animations. Just draw on the canvas as usual and create a snapshot for every frame you want to be included in the animation.
|
186
|
+
|
187
|
+
``FlipBook#snapshot canvas``
|
188
|
+
|
189
|
+
Saves a snapshot of the current state of the canvas.
|
190
|
+
|
191
|
+
``FlipBook#snapshot#play``
|
192
|
+
|
193
|
+
Will render the animation on the terminal. The method also takes an option hash with the options ``:repeat`` ``:fps``.
|
194
|
+
|
160
195
|
## License
|
161
196
|
|
162
197
|
MIT License
|
data/drawille.gemspec
CHANGED
data/lib/drawille.rb
CHANGED
data/lib/drawille/brush.rb
CHANGED
@@ -26,8 +26,8 @@ module Drawille
|
|
26
26
|
|
27
27
|
def forward length
|
28
28
|
theta = ((@state[:rotation]) / 180.0 * Math::PI)
|
29
|
-
x = @state[:x] + length * Math::cos(theta)
|
30
|
-
y = @state[:y] + length * Math::sin(theta)
|
29
|
+
x = (@state[:x] + length * Math::cos(theta)).round
|
30
|
+
y = (@state[:y] + length * Math::sin(theta)).round
|
31
31
|
|
32
32
|
move x, y
|
33
33
|
end
|
data/lib/drawille/canvas.rb
CHANGED
@@ -1,20 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
2
|
module Drawille
|
4
3
|
|
5
4
|
class Canvas
|
5
|
+
include Frameable
|
6
6
|
|
7
7
|
attr_reader :chars
|
8
8
|
|
9
|
-
PIXEL_MAP = [[0x01, 0x08],
|
10
|
-
[0x02, 0x10],
|
11
|
-
[0x04, 0x20],
|
12
|
-
[0x40, 0x80]]
|
13
|
-
|
14
|
-
BRAILLE_CHAR_OFFSET = 0x2800
|
15
|
-
|
16
9
|
def initialize
|
17
10
|
clear
|
11
|
+
@snapshots = [{}]
|
18
12
|
end
|
19
13
|
|
20
14
|
def paint &block
|
@@ -52,41 +46,10 @@ module Drawille
|
|
52
46
|
@chars[py][px] & PIXEL_MAP[y % 4][x % 2] == 0 ? set(x, y) : unset(x, y)
|
53
47
|
end
|
54
48
|
|
55
|
-
def row y, options={}
|
56
|
-
row = @chars[y]
|
57
|
-
min = options[:min_x] || row.keys.min
|
58
|
-
max = options[:max_x] || row.keys.max
|
59
|
-
return "" if min.nil? || max.nil?
|
60
|
-
(min..max).reduce("") { |memo, i| memo << to_braille(row[i] || 0) }
|
61
|
-
end
|
62
|
-
|
63
|
-
def rows options={}
|
64
|
-
min = options[:min_y] || @chars.keys.min
|
65
|
-
max = options[:max_y] || @chars.keys.max
|
66
|
-
return [] if min.nil? || max.nil?
|
67
|
-
options[:min_x] ||= @chars.reduce([]) { |m,x| m << x.last.keys }.flatten.min
|
68
|
-
options[:max_x] ||= @chars.reduce([]) { |m,x| m << x.last.keys }.flatten.max
|
69
|
-
(min..max).map { |i| row i, options }
|
70
|
-
end
|
71
|
-
|
72
|
-
def frame options={}
|
73
|
-
rows(options).join("\n")
|
74
|
-
end
|
75
|
-
|
76
|
-
def char x, y
|
77
|
-
to_braille @chars[y][x]
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
49
|
def convert x, y
|
83
50
|
x = x.round
|
84
51
|
y = y.round
|
85
52
|
[x, y, (x / 2).floor, (y / 4).floor]
|
86
53
|
end
|
87
|
-
|
88
|
-
def to_braille x
|
89
|
-
[BRAILLE_CHAR_OFFSET + x].pack("U*")
|
90
|
-
end
|
91
54
|
end
|
92
55
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'curses'
|
3
|
+
|
4
|
+
module Drawille
|
5
|
+
|
6
|
+
class FlipBook
|
7
|
+
include Frameable
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
clear
|
11
|
+
end
|
12
|
+
|
13
|
+
def clear
|
14
|
+
@snapshots = []
|
15
|
+
@chars = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def snapshot canvas
|
19
|
+
@snapshots << canvas.frame
|
20
|
+
@chars = canvas.chars
|
21
|
+
end
|
22
|
+
|
23
|
+
def each_frame options={}
|
24
|
+
return enum_for(:each_frame) unless block_given?
|
25
|
+
@snapshots.each do |frame|
|
26
|
+
yield frame
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def play options={}
|
31
|
+
options = {
|
32
|
+
repeat: false, fps: 6,
|
33
|
+
min_x: 0, min_y: 0
|
34
|
+
}.merge(options)
|
35
|
+
|
36
|
+
Curses::init_screen
|
37
|
+
begin
|
38
|
+
Curses::crmode
|
39
|
+
Curses::curs_set 0
|
40
|
+
repeat options do
|
41
|
+
each_frame options do |frame|
|
42
|
+
Curses::setpos(0, 0)
|
43
|
+
Curses::addstr(frame)
|
44
|
+
Curses::refresh
|
45
|
+
sleep(1.0/options[:fps])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
ensure
|
49
|
+
Curses::close_screen
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def repeat options
|
54
|
+
options[:repeat] ? loop { yield; clear_screen options } : yield
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def clear_screen options
|
60
|
+
Curses::clear
|
61
|
+
Curses::refresh
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Drawille
|
4
|
+
|
5
|
+
module Frameable
|
6
|
+
|
7
|
+
PIXEL_MAP = [[0x01, 0x08],
|
8
|
+
[0x02, 0x10],
|
9
|
+
[0x04, 0x20],
|
10
|
+
[0x40, 0x80]]
|
11
|
+
|
12
|
+
BRAILLE_CHAR_OFFSET = 0x2800
|
13
|
+
|
14
|
+
def row y, options={}
|
15
|
+
chars = options[:chars] || @chars
|
16
|
+
row = chars[y]
|
17
|
+
min = options[:min_x]
|
18
|
+
max = options[:max_x]
|
19
|
+
return "" if min.nil? || max.nil?
|
20
|
+
(min..max).reduce("") { |memo, i| memo << to_braille(row.nil? ? 0 : row[i] || 0) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def rows options={}
|
24
|
+
chars = options[:chars] || @chars
|
25
|
+
min = options[:min_y] || [chars.keys.min, 0].min
|
26
|
+
max = options[:max_y] || chars.keys.max
|
27
|
+
return [] if min.nil? || max.nil?
|
28
|
+
options[:min_x] ||= [chars.reduce([]) { |m,x| m << x.last.keys }.flatten.min, 0].min
|
29
|
+
options[:max_x] ||= chars.reduce([]) { |m,x| m << x.last.keys }.flatten.max
|
30
|
+
(min..max).map { |i| row i, options }
|
31
|
+
end
|
32
|
+
|
33
|
+
def frame options={}
|
34
|
+
rows(options).join("\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
def char x, y
|
38
|
+
to_braille @chars[y][x]
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_braille x
|
42
|
+
[BRAILLE_CHAR_OFFSET + x].pack("U*")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/drawille/version.rb
CHANGED
data/spec/drawille_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
include Drawille
|
5
|
+
|
6
|
+
describe Canvas do
|
7
|
+
subject(:canvas) { Canvas.new }
|
6
8
|
|
7
9
|
describe '#set' do
|
8
10
|
it 'sets pixel in the first char in the first row' do
|
@@ -20,76 +22,76 @@ describe Drawille do
|
|
20
22
|
|
21
23
|
describe "#unset" do
|
22
24
|
it 'sets and unsets a pixel' do
|
23
|
-
|
24
|
-
expect(
|
25
|
-
|
26
|
-
expect(
|
25
|
+
canvas.set(0, 0)
|
26
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[0]
|
27
|
+
canvas.unset(0, 0)
|
28
|
+
expect(canvas.char(0, 0)).to eq BRAILLE.last
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'sets four pixel but only unsets one' do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
expect(
|
35
|
-
|
36
|
-
expect(
|
32
|
+
canvas.set(0, 0)
|
33
|
+
canvas.set(0, 1)
|
34
|
+
canvas.set(1, 0)
|
35
|
+
canvas.set(1, 1)
|
36
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[3]
|
37
|
+
canvas.unset(1, 1)
|
38
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[2]
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
describe "#get" do
|
41
43
|
it 'returns the state of a pixel' do
|
42
|
-
|
43
|
-
expect(
|
44
|
-
expect(
|
44
|
+
canvas.set(1, 1)
|
45
|
+
expect(canvas.get(0, 0)).to eq false
|
46
|
+
expect(canvas.get(1, 1)).to eq true
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
50
|
describe "#toggle" do
|
49
51
|
it 'toggles a pixel' do
|
50
|
-
|
51
|
-
|
52
|
-
expect(
|
53
|
-
|
54
|
-
expect(
|
55
|
-
|
56
|
-
expect(
|
52
|
+
canvas.toggle(0, 0)
|
53
|
+
canvas.toggle(1, 0)
|
54
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[1]
|
55
|
+
canvas.toggle(1, 0)
|
56
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[0]
|
57
|
+
canvas.toggle(0, 0)
|
58
|
+
expect(canvas.char(0, 0)).to eq BRAILLE.last
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
62
|
describe "#clear" do
|
61
63
|
it 'clears the canvas' do
|
62
|
-
|
63
|
-
|
64
|
-
expect(
|
65
|
-
expect(
|
66
|
-
|
67
|
-
expect(
|
68
|
-
expect(
|
64
|
+
canvas.set(0, 0)
|
65
|
+
canvas.set(2, 0)
|
66
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[0]
|
67
|
+
expect(canvas.char(1, 0)).to eq BRAILLE[0]
|
68
|
+
canvas.clear
|
69
|
+
expect(canvas.char(0, 0)).to eq BRAILLE.last
|
70
|
+
expect(canvas.char(1, 0)).to eq BRAILLE.last
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
74
|
describe '#[]' do
|
73
75
|
it 'works with alternate syntax' do
|
74
|
-
|
75
|
-
expect(
|
76
|
-
expect(
|
77
|
-
expect(
|
78
|
-
|
79
|
-
expect(
|
80
|
-
expect(
|
76
|
+
canvas[0, 0] = true
|
77
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[0]
|
78
|
+
expect(canvas[0, 0]).to eq true
|
79
|
+
expect(canvas[1, 0]).to eq false
|
80
|
+
canvas[0, 0] = false
|
81
|
+
expect(canvas.char(0, 0)).to eq BRAILLE.last
|
82
|
+
expect(canvas[0, 0]).to eq false
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
84
86
|
describe "#rows" do
|
85
87
|
it 'has over 9 columns and 3 rows' do
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
canvas.set(0, 1)
|
89
|
+
canvas.set(4, 4)
|
90
|
+
canvas.set(8, 5)
|
91
|
+
canvas.set(16, 8)
|
90
92
|
|
91
|
-
expect(
|
92
|
-
|
93
|
+
expect(canvas.rows.size).to eq 3
|
94
|
+
canvas.rows.each do |row|
|
93
95
|
expect(row.length).to eq 9
|
94
96
|
end
|
95
97
|
end
|
@@ -98,19 +100,214 @@ describe Drawille do
|
|
98
100
|
describe "#frame" do
|
99
101
|
it 'prints a happy sinus' do
|
100
102
|
(0..1800).step(10).each do |x|
|
101
|
-
|
103
|
+
canvas.set(x/10, 10 + Math.sin(x * Math::PI / 180) * 10)
|
102
104
|
end
|
103
|
-
expect(
|
105
|
+
expect(canvas.frame).to eq IO.read("spec/sinus.dat")
|
104
106
|
end
|
105
107
|
|
106
108
|
it 'does not throw an exception on an empty canvas' do
|
107
|
-
|
109
|
+
canvas.frame
|
108
110
|
end
|
109
111
|
|
110
112
|
it 'is an empty frame for an empty canvas' do
|
111
|
-
expect(
|
112
|
-
expect(
|
113
|
+
expect(canvas.rows.size).to eq 0
|
114
|
+
expect(canvas.frame).to eq ""
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe Brush do
|
120
|
+
subject(:canvas) { Canvas.new }
|
121
|
+
subject(:brush) { Brush.new(canvas) }
|
122
|
+
|
123
|
+
describe "#up" do
|
124
|
+
it 'is up by default' do
|
125
|
+
brush.forward 40
|
126
|
+
expect(canvas.rows.size).to eq 0
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'does not draw anymore after putting brush up' do
|
130
|
+
brush.down
|
131
|
+
brush.forward 1
|
132
|
+
brush.up
|
133
|
+
brush.forward 2
|
134
|
+
expect(canvas.rows.size).to eq 1
|
135
|
+
expect(canvas.rows[0].size).to eq 1
|
136
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[1]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#down" do
|
141
|
+
it "draws if brush is put down" do
|
142
|
+
brush.down
|
143
|
+
brush.forward 1
|
144
|
+
expect(canvas.rows.size).to eq 1
|
145
|
+
expect(canvas.rows[0].size).to eq 1
|
146
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[1]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#forward" do
|
151
|
+
it 'moves to the right without changing the direction' do
|
152
|
+
brush.down
|
153
|
+
brush.forward 3
|
154
|
+
expect(canvas.rows.size).to eq 1
|
155
|
+
expect(canvas.rows[0].size).to eq 2
|
156
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[1]
|
157
|
+
expect(canvas.char(1, 0)).to eq BRAILLE[1]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "#back" do
|
162
|
+
it 'moves backward without drawing' do
|
163
|
+
brush.forward 10
|
164
|
+
brush.back 10
|
165
|
+
expect(canvas.rows.size).to eq 0
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'moves backward with drawing' do
|
169
|
+
brush.forward 9
|
170
|
+
brush.down
|
171
|
+
brush.back 9
|
172
|
+
expect(canvas.rows.size).to eq 1
|
173
|
+
expect(canvas.rows[0].size). to eq 5
|
174
|
+
5.times do |i|
|
175
|
+
expect(canvas.char(i, 0)).to eq BRAILLE[1]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "#right" do
|
181
|
+
it 'changes the direction' do
|
182
|
+
brush.down
|
183
|
+
brush.forward 1
|
184
|
+
brush.right 90
|
185
|
+
brush.forward 3
|
186
|
+
brush.right 90
|
187
|
+
brush.forward 1
|
188
|
+
brush.right 90
|
189
|
+
brush.forward 3
|
190
|
+
expect(canvas.rows.size).to eq 1
|
191
|
+
expect(canvas.rows[0].size).to eq 1
|
192
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[-2]
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "#left" do
|
197
|
+
it 'changes the direction' do
|
198
|
+
brush.move 0, 3
|
199
|
+
brush.down
|
200
|
+
brush.down
|
201
|
+
brush.forward 1
|
202
|
+
brush.left 90
|
203
|
+
brush.forward 3
|
204
|
+
brush.left 90
|
205
|
+
brush.forward 1
|
206
|
+
brush.left 90
|
207
|
+
brush.forward 3
|
208
|
+
expect(canvas.rows.size).to eq 1
|
209
|
+
expect(canvas.rows[0].size).to eq 1
|
210
|
+
expect(canvas.char(0, 0)).to eq BRAILLE[-2]
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "#move" do
|
215
|
+
it 'moves and does not draw a line' do
|
216
|
+
brush.move 200, 200
|
217
|
+
expect(canvas.rows.size).to eq 0
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'moves and does draw a line' do
|
221
|
+
brush.down
|
222
|
+
brush.move 99, 0
|
223
|
+
brush.up
|
224
|
+
brush.move 99, 4
|
225
|
+
brush.down
|
226
|
+
brush.move 0, 4
|
227
|
+
expect(canvas.rows.size).to eq 2
|
228
|
+
expect(canvas.rows[0].size).to eq 50
|
229
|
+
50.times do |i|
|
230
|
+
expect(canvas.char(i, 0)).to eq BRAILLE[1]
|
231
|
+
expect(canvas.char(i, 1)).to eq BRAILLE[1]
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "#line" do
|
237
|
+
it 'should draw a line regardless of the brush state' do
|
238
|
+
brush.line from: [2, 0], to: [5, 0]
|
239
|
+
expect(canvas.rows.size).to eq 1
|
240
|
+
expect(canvas.char(0, 0)).to eq BRAILLE.last
|
241
|
+
expect(canvas.char(1, 0)).to eq BRAILLE[1]
|
242
|
+
expect(canvas.char(2, 0)).to eq BRAILLE[1]
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should not draw with the move to the beginning of the line' do
|
246
|
+
brush.down
|
247
|
+
brush.line from: [2, 0], to: [5, 0]
|
248
|
+
expect(canvas.rows.size).to eq 1
|
249
|
+
expect(canvas.char(0, 0)).to eq BRAILLE.last
|
250
|
+
expect(canvas.char(1, 0)).to eq BRAILLE[1]
|
251
|
+
expect(canvas.char(2, 0)).to eq BRAILLE[1]
|
113
252
|
end
|
114
253
|
end
|
115
254
|
end
|
116
255
|
|
256
|
+
describe FlipBook do
|
257
|
+
subject(:canvas) { Canvas.new }
|
258
|
+
subject(:flipbook) { FlipBook.new }
|
259
|
+
|
260
|
+
describe "#each_frame" do
|
261
|
+
it 'yields four frames' do
|
262
|
+
canvas.set(0, 0)
|
263
|
+
flipbook.snapshot canvas
|
264
|
+
canvas.set(1, 0)
|
265
|
+
flipbook.snapshot canvas
|
266
|
+
canvas.set(0, 1)
|
267
|
+
flipbook.snapshot canvas
|
268
|
+
canvas.set(1, 1)
|
269
|
+
flipbook.snapshot canvas
|
270
|
+
|
271
|
+
i = 0
|
272
|
+
flipbook.each_frame do |frame|
|
273
|
+
expect(frame).to eq BRAILLE[i]
|
274
|
+
i += 1
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'yields multiline frames' do
|
279
|
+
canvas.set(0, 0)
|
280
|
+
flipbook.snapshot canvas
|
281
|
+
canvas.set(0, 4)
|
282
|
+
flipbook.snapshot canvas
|
283
|
+
|
284
|
+
expect(flipbook.rows.size).to eq 2
|
285
|
+
expect(flipbook.char(0, 0)).to eq BRAILLE[0]
|
286
|
+
expect(flipbook.char(0, 1)).to eq BRAILLE[0]
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'yields the same frame twice' do
|
290
|
+
canvas.set(0, 0)
|
291
|
+
flipbook.snapshot canvas
|
292
|
+
canvas.set(1, 0)
|
293
|
+
flipbook.snapshot canvas
|
294
|
+
2.times do
|
295
|
+
i = 0
|
296
|
+
flipbook.each_frame do |frame|
|
297
|
+
expect(frame).to eq BRAILLE[i]
|
298
|
+
i += 1
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'returns an enumerator without a block given' do
|
304
|
+
canvas.set(0, 0)
|
305
|
+
flipbook.snapshot canvas
|
306
|
+
canvas.set(1, 0)
|
307
|
+
flipbook.snapshot canvas
|
308
|
+
flipbook.each_frame.with_index do |frame, i|
|
309
|
+
expect(frame).to eq BRAILLE[i]
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,8 +7,8 @@ def set_and_check_char px_range, py_range, cx, cy
|
|
7
7
|
i = 0
|
8
8
|
py_range.each do |y|
|
9
9
|
px_range.each do |x|
|
10
|
-
|
11
|
-
expect(
|
10
|
+
canvas.set(x, y)
|
11
|
+
expect(canvas.char(cx, cy)).to eq BRAILLE[i]
|
12
12
|
i += 1
|
13
13
|
end
|
14
14
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drawille
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Skirzynski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curses
|
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'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,6 +60,8 @@ files:
|
|
46
60
|
- lib/drawille.rb
|
47
61
|
- lib/drawille/brush.rb
|
48
62
|
- lib/drawille/canvas.rb
|
63
|
+
- lib/drawille/flipbook.rb
|
64
|
+
- lib/drawille/frameable.rb
|
49
65
|
- lib/drawille/version.rb
|
50
66
|
- spec/drawille_spec.rb
|
51
67
|
- spec/sinus.dat
|