Class: ShadedAscii
- Inherits:
-
AsciiImage
- Object
- AsciiImage
- ShadedAscii
- Defined in:
- lib/honeybii/shaded_ascii.rb
Class Attribute Summary collapse
-
.gradients ⇒ Object
Returns the value of attribute gradients.
Attributes inherited from AsciiImage
Instance Method Summary collapse
- #grayscale! ⇒ Object
-
#initialize(image_filename, point_size = 12, gradient_level: 0) ⇒ ShadedAscii
constructor
A new instance of ShadedAscii.
- #pixelate! ⇒ Object
- #to_ascii! ⇒ Object
Methods inherited from AsciiImage
Constructor Details
#initialize(image_filename, point_size = 12, gradient_level: 0) ⇒ ShadedAscii
15 16 17 18 19 |
# File 'lib/honeybii/shaded_ascii.rb', line 15 def initialize(image_filename, point_size = 12, gradient_level: 0) super image_filename, point_size @gradient = ShadedAscii.gradients[gradient_level] to_ascii! end |
Class Attribute Details
.gradients ⇒ Object
Returns the value of attribute gradients.
3 4 5 |
# File 'lib/honeybii/shaded_ascii.rb', line 3 def gradients @gradients end |
Instance Method Details
#grayscale! ⇒ Object
21 22 23 |
# File 'lib/honeybii/shaded_ascii.rb', line 21 def grayscale! @raw = @raw.quantize(256, Magick::GRAYColorspace) end |
#pixelate! ⇒ Object
25 26 27 28 29 |
# File 'lib/honeybii/shaded_ascii.rb', line 25 def pixelate! columns = @raw.columns / @point_size rows = @raw.rows / (@point_size * 2) @raw.resize!(columns, rows) end |
#to_ascii! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/honeybii/shaded_ascii.rb', line 31 def to_ascii! grayscale! pixelate! ascii_array = Array.new(@raw.rows).collect do |row| Array.new(@raw.columns) end @raw.each_pixel do |pixel, col, row| index = (((@gradient.size - 1) * pixel.intensity).to_f / 65535.to_f).round ascii_array[row][col] = @gradient[index] end @ascii = ascii_array.map { |row| row.join }.join("\n") end |