Class: Fractal::Map
- Inherits:
-
Array
- Object
- Array
- Fractal::Map
- Defined in:
- lib/fractal/map.rb
Defined Under Namespace
Classes: Line
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #[](x, y) ⇒ Object
- #[]=(x, y, value) ⇒ Object
-
#bytes ⇒ Object
Encodes the map as a grayscale bitmap, with a color depth of 8 bits per pixel.
-
#initialize(size) ⇒ Map
constructor
A new instance of Map.
- #row ⇒ Object
- #truncate(width, height) ⇒ Object
Constructor Details
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
2 3 4 |
# File 'lib/fractal/map.rb', line 2 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
2 3 4 |
# File 'lib/fractal/map.rb', line 2 def width @width end |
Instance Method Details
#[](x, y) ⇒ Object
34 35 36 37 |
# File 'lib/fractal/map.rb', line 34 def [](x, y) raise "Out of bounds: #{y} / #{@height}" if y < 0 || y >= @height super(y)[x] end |
#[]=(x, y, value) ⇒ Object
39 40 41 |
# File 'lib/fractal/map.rb', line 39 def []=(x, y, value) row(y)[x] = value end |
#bytes ⇒ Object
Encodes the map as a grayscale bitmap, with a color depth of 8 bits per pixel.
Returns the bitmap as an array of bytes.
46 47 48 |
# File 'lib/fractal/map.rb', line 46 def bytes flatten.pack("C*").bytes.to_a end |
#row ⇒ Object
3 |
# File 'lib/fractal/map.rb', line 3 alias :row :[] |
#truncate(width, height) ⇒ Object
28 29 30 31 32 |
# File 'lib/fractal/map.rb', line 28 def truncate(width, height) pop while length > height collect! { |line| line[0...width] } @width, @height = width, height end |