honeybii 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/honeybii/ascii_image.rb +2 -3
- data/lib/honeybii/shaded_ascii.rb +8 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8253805c2d75c692318f162548602dc04b51cb4
|
4
|
+
data.tar.gz: 2a911a44cb10cf5ec4bdea7838812e26cc84ae17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe123439446bdefc6d21bf076ca5df9a8ff378dcdfc3cd2d6f80c69c744d36380dfb03c5443291900752f0192b077510219c0d7ce0db0b317bb47749aeb7a59f
|
7
|
+
data.tar.gz: a7ea69fbe695a100f4a1f76a687d704db188778e6f0400588a9190c982afcf1649f1f963656e369f3079a09fb3895f48238edbbfde9632e943053a645aa7a359
|
data/lib/honeybii/ascii_image.rb
CHANGED
@@ -2,13 +2,12 @@ require 'rmagick'
|
|
2
2
|
|
3
3
|
class AsciiImage
|
4
4
|
attr_accessor :raw
|
5
|
-
attr_accessor :shades
|
6
5
|
attr_accessor :ascii
|
7
6
|
|
8
7
|
def initialize(image_filename, point_size)
|
9
|
-
@raw = Magick::ImageList.new(image_filename)
|
8
|
+
@raw = Magick::ImageList.new(image_filename).first
|
10
9
|
@point_size = point_size
|
11
|
-
@ascii =
|
10
|
+
@ascii = ''
|
12
11
|
end
|
13
12
|
|
14
13
|
def to_s
|
@@ -1,8 +1,8 @@
|
|
1
|
+
SHADES = ['@', '%', '8', '#', '$', 'V', 'Y', 'x', '*', '=', '+', ':', '~', '-', '.', ' ']
|
2
|
+
|
1
3
|
class ShadedAscii < AsciiImage
|
2
4
|
def initialize(image_filename, point_size = 12)
|
3
5
|
super image_filename, point_size
|
4
|
-
@raw = Magick::ImageList.new(image_filename).first
|
5
|
-
@shades = ['@', '%', '8', '#', '$', 'V', 'Y', 'x', '*', '=', '+', ':', '~', '-', '.', ' ']
|
6
6
|
to_ascii!
|
7
7
|
end
|
8
8
|
|
@@ -12,23 +12,23 @@ class ShadedAscii < AsciiImage
|
|
12
12
|
|
13
13
|
def pixelate!
|
14
14
|
columns = @raw.columns / @point_size
|
15
|
-
rows = @raw.rows / @point_size
|
16
|
-
@raw
|
15
|
+
rows = @raw.rows / (@point_size * 2)
|
16
|
+
@raw.resize!(columns, rows)
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_ascii!
|
20
20
|
grayscale!
|
21
21
|
pixelate!
|
22
22
|
|
23
|
-
|
23
|
+
ascii_array = Array.new(@raw.rows).collect do |row|
|
24
24
|
Array.new(@raw.columns)
|
25
25
|
end
|
26
26
|
|
27
27
|
@raw.each_pixel do |pixel, col, row|
|
28
|
-
index = (((
|
29
|
-
|
28
|
+
index = (((SHADES.size - 1) * pixel.intensity).to_f / 65535.to_f).round
|
29
|
+
ascii_array[row][col] = SHADES[index]
|
30
30
|
end
|
31
31
|
|
32
|
-
@ascii =
|
32
|
+
@ascii = ascii_array.map { |row| row.join }.join("\n")
|
33
33
|
end
|
34
34
|
end
|