Class: OfIf::Image
- Inherits:
-
Object
- Object
- OfIf::Image
- Defined in:
- lib/of_if/image.rb
Overview
Image renders a source file only by its indentation and obfuscates the code by displaying only color blocks.
Constant Summary collapse
- DEFAULTS =
{ margin: 100, char_width: 10, line_height: 20, minimal_width: 480 }.freeze
Instance Attribute Summary collapse
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(line) ⇒ Object
- #height ⇒ Object
-
#initialize ⇒ Image
constructor
A new instance of Image.
- #write(filename) ⇒ Object
Constructor Details
#initialize ⇒ Image
Returns a new instance of Image.
18 19 20 21 22 |
# File 'lib/of_if/image.rb', line 18 def initialize @width = minimal_width @image_operations = [] @current_line_index = 0 end |
Instance Attribute Details
#width ⇒ Object (readonly)
Returns the value of attribute width.
16 17 18 |
# File 'lib/of_if/image.rb', line 16 def width @width end |
Class Method Details
Instance Method Details
#<<(line) ⇒ Object
32 33 34 35 36 |
# File 'lib/of_if/image.rb', line 32 def <<(line) @image_operations << create_image_operation(line, @current_line_index) update_width line.length @current_line_index += 1 end |
#height ⇒ Object
38 |
# File 'lib/of_if/image.rb', line 38 def height = offset + (@current_line_index * line_height) |
#write(filename) ⇒ Object
40 41 42 43 44 |
# File 'lib/of_if/image.rb', line 40 def write(filename) png = ChunkyPNG::Image.new width, height, ChunkyPNG::Color::WHITE @image_operations.each { |op| op.call png } png.save filename end |