Grayscale image: Difference between revisions

add Ruby
mNo edit summary
(add Ruby)
Line 526:
plot(p3 <- as(p2, "pixmapRGB"))
</lang>
 
=={{header|Ruby}}==
Extending [[Basic_bitmap_storage#Ruby]]
<lang ruby>class RGBColour
def to_grayscale
luminosity = Integer(0.2126*@red + 0.7152*@green + 0.0722*@blue)
self.class.new(luminosity, luminosity, luminosity)
end
end
 
class Bitmap
def to_grayscale
gray = Bitmap.new(@width, @height)
@width.times do |x|
@height.times do |y|
gray[x,y] = self[x,y].to_grayscale
end
end
gray
end
end</lang>
 
=={{header|Tcl}}==
Anonymous user