drawille 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yjk3ZmI2NzE4YzNjYzM0ZWEyYjJjNDU2OWY0NDhmY2VjNzRlMGVlNQ==
4
+ OWEzYWU1YjkwZTI1ODNiYjI1NzI4ZmZhZDRhZmE0Yjc5YmNiMmEzYQ==
5
5
  data.tar.gz: !binary |-
6
- NDVmZWMzYzY1MjA5YWE1ZjlkZWY1YzM1ODhiMzljMWI4NzhiNWQzOA==
6
+ YjNiYWIzN2U3OWJiNmY4OTYzMjFjMmQ4YzdlMzkwNjYwZWQwN2Q5OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjJkZTdjM2I1MTZlYTZlYWI1ZTM5Zjk0Zjc1YTkzZmExODEwZTUyZWU5N2Jm
10
- MjYxYTAyNmFlOWY3YTVmMTIyN2NlMDFlNzhiMjEyODczZjEyOTRmY2JjYjI5
11
- M2YxOWZkYmNjNmM3MmRlMjU3MDAwMTJkNWY4ZTdiZWJlY2I1NzM=
9
+ MGY4YWRiMzRmNjc2YjUzMTUzNmM4MzYyNTdiOTdhOTYyMzM2MjhlZDlkMzc5
10
+ NjIzZDEyMzVjYjVmNjkwN2RhNjQ5NTRiMjJkMzUwZTBmZWFmYzg0N2FlYTA4
11
+ ZjhjZmYzYjVlZGM2YmNiYjdkZjljN2JkZjAyN2NkMmVhMmMzMGI=
12
12
  data.tar.gz: !binary |-
13
- MDg3NjU4OTNmOTdkNzdlNmU4ODY5ODQwNWE1OTYyZWEzNzE4NTkzZmRmNTIy
14
- NGFiODE4OTkxN2YyZTNmMjc0MjdkZDdiNDY3ZWYxMTc3MzhjMzFlN2YyYjc1
15
- OWEwZWM5ZTg0MTM5ZTgwMDA3ODcyMDJjOGJkYWFmYzNkZWQ2Yjg=
13
+ YTNjMjM1ZjExY2Y1ODQ3NDVmNDRlZDBlNDMzMGVjNjdiZTUzMGQ2YWU3ZmE0
14
+ NDFiMGNkYzdkOWRhZThlN2JmN2MxNjhhYjIyNjA4MjFmMTZmZTMzM2M1MTU5
15
+ YWVhN2ExZTI5Yjc5NzhmYzhlYmViZjQxMjIwYzk0MGM0ZTJkNjU=
data/README.md CHANGED
@@ -26,17 +26,48 @@ Or install it yourself as:
26
26
  Drawille can be used like the Python implementation due to the similar API. Here is on of its examples:
27
27
 
28
28
  ```ruby
29
- c = Drawille::Canvas.new
29
+ require 'drawille'
30
+
31
+ canvas = Drawille::Canvas.new
30
32
 
31
33
  (0..1800).step(10).each do |x|
32
- c.set(x/10, 10 + Math.sin(x * Math::PI / 180) * 10)
34
+ canvas.set(x/10, 10 + Math.sin(x * Math::PI / 180) * 10)
33
35
  end
34
36
 
35
- puts c.frame
37
+ puts canvas.frame
36
38
  ```
37
39
 
38
40
  ![Sinus](docs/images/sinus.gif)
39
41
 
42
+ But in the end you can use it in every possible situation where you have only two colors. This means it is perfect for some stencil graffitis.
43
+
44
+ ```ruby
45
+ require 'drawille'
46
+ require 'chunky_png'
47
+
48
+ include ChunkyPNG
49
+
50
+ canvas = Drawille::Canvas.new
51
+
52
+ def draw canvas, img, xoffset=0
53
+ (0..img.dimension.width-1).each do |x|
54
+ (0..img.dimension.height-1).each do |y|
55
+ r = Color.r(img[x,y])
56
+ g = Color.g(img[x,y])
57
+ b = Color.b(img[x,y])
58
+ canvas.set(x+xoffset, y) if (r + b + g) > 100
59
+ end
60
+ end
61
+ end
62
+
63
+ draw canvas, Image.from_file('examples/stencil-1.png')
64
+ draw canvas, Image.from_file('examples/stencil-2.jpg'), 141
65
+
66
+ puts canvas.frame
67
+ ```
68
+
69
+ ![Stencil](docs/images/stencil.gif)
70
+
40
71
  This implementation also includes a Turtle graphics API for all your beloved fractals. See this simple example:
41
72
 
42
73
  ```ruby
Binary file
Binary file
Binary file
@@ -0,0 +1,22 @@
1
+ require 'drawille'
2
+ require 'chunky_png'
3
+
4
+ include ChunkyPNG
5
+
6
+ canvas = Drawille::Canvas.new
7
+
8
+ def draw canvas, img, xoffset=0
9
+ (0..img.dimension.width-1).each do |x|
10
+ (0..img.dimension.height-1).each do |y|
11
+ r = Color.r(img[x,y])
12
+ g = Color.g(img[x,y])
13
+ b = Color.b(img[x,y])
14
+ canvas.set(x+xoffset, y) if (r + b + g) > 100
15
+ end
16
+ end
17
+ end
18
+
19
+ draw canvas, Image.from_file('examples/stencil-1.png')
20
+ draw canvas, Image.from_file('examples/stencil-2.jpg'), 141
21
+
22
+ puts canvas.frame
@@ -56,13 +56,14 @@ module Drawille
56
56
  row = @chars[y]
57
57
  min = options[:min_x] || row.keys.min
58
58
  max = options[:max_x] || row.keys.max
59
-
59
+ return "" if min.nil? || max.nil?
60
60
  (min..max).reduce("") { |memo, i| memo << to_braille(row[i] || 0) }
61
61
  end
62
62
 
63
63
  def rows options={}
64
64
  min = options[:min_y] || @chars.keys.min
65
65
  max = options[:max_y] || @chars.keys.max
66
+ return [] if min.nil? || max.nil?
66
67
  options[:min_x] ||= @chars.reduce([]) { |m,x| m << x.last.keys }.flatten.min
67
68
  options[:max_x] ||= @chars.reduce([]) { |m,x| m << x.last.keys }.flatten.max
68
69
  (min..max).map { |i| row i, options }
@@ -1,3 +1,3 @@
1
1
  module Drawille
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -102,6 +102,15 @@ describe Drawille do
102
102
  end
103
103
  expect(subject.frame).to eq IO.read("spec/sinus.dat")
104
104
  end
105
+
106
+ it 'does not throw an exception on an empty canvas' do
107
+ subject.frame
108
+ end
109
+
110
+ it 'is an empty frame for an empty canvas' do
111
+ expect(subject.rows.size).to eq 0
112
+ expect(subject.frame).to eq ""
113
+ end
105
114
  end
106
115
  end
107
116
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drawille
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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-05-22 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -37,8 +37,12 @@ files:
37
37
  - Rakefile
38
38
  - docs/images/mn-gon.gif
39
39
  - docs/images/sinus.gif
40
+ - docs/images/stencil.gif
40
41
  - drawille.gemspec
41
42
  - examples/mn-gon.rb
43
+ - examples/stencil-1.png
44
+ - examples/stencil-2.jpg
45
+ - examples/stencil.rb
42
46
  - lib/drawille.rb
43
47
  - lib/drawille/brush.rb
44
48
  - lib/drawille/canvas.rb