Class: Rnes::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/rnes/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(height:, width:) ⇒ Image

Returns a new instance of Image.

Parameters:

  • height (Integer)
  • width (Integer)


11
12
13
14
15
16
17
# File 'lib/rnes/image.rb', line 11

def initialize(height:, width:)
  @bytes = Array.new(height * width) do
    [0, 0, 0]
  end
  @height = height
  @width = width
end

Instance Attribute Details

#heightInteger (readonly)

Returns:

  • (Integer)


4
5
6
# File 'lib/rnes/image.rb', line 4

def height
  @height
end

#widthInteger (readonly)

Returns:

  • (Integer)


7
8
9
# File 'lib/rnes/image.rb', line 7

def width
  @width
end

Instance Method Details

#read(x:, y:) ⇒ Object

Parameters:

  • x (Integer)
  • y (Integer)


21
22
23
# File 'lib/rnes/image.rb', line 21

def read(x:, y:)
  @bytes[@width * y + x]
end

#write(value:, x:, y:) ⇒ Object

Parameters:

  • rgb (Array<Integer>)
  • x (Integer)
  • y (Integer)


28
29
30
# File 'lib/rnes/image.rb', line 28

def write(value:, x:, y:)
  @bytes[@width * y + x] = value
end