Class: Gosu::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/bestguigui_lab/image_pixels.rb

Overview

Monkey patch de Gosu::Image pour lire/ecrire un pixel individuel.

Instance Method Summary collapse

Instance Method Details

#get_pixel(x, y) ⇒ Object



6
7
8
9
10
11
# File 'lib/bestguigui_lab/image_pixels.rb', line 6

def get_pixel(x, y)
    return nil if x.negative? || x >= width || y.negative? || y >= height

    r, g, b, a = to_blob[((y * width) + x) * 4, 4].unpack('C4')
    Gosu::Color.new(a, r, g, b)
end

#set_pixel(x, y, color) ⇒ Object



13
14
15
16
17
# File 'lib/bestguigui_lab/image_pixels.rb', line 13

def set_pixel(x, y, color)
    blob = [color.red, color.green, color.blue, color.alpha].pack('C4')
    pixel = Gosu::Image.from_blob(1, 1, blob)
    insert(pixel, x, y)
end