Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Grayscale-image/Crystal/grayscale-image.crystal
Normal file
18
Task/Grayscale-image/Crystal/grayscale-image.crystal
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class RGBColour
|
||||
def to_grayscale
|
||||
luminosity = (0.2126*@red + 0.7152*@green + 0.0722*@blue).to_i
|
||||
self.class.new(luminosity, luminosity, luminosity)
|
||||
end
|
||||
end
|
||||
|
||||
class Pixmap
|
||||
def to_grayscale
|
||||
gray = self.class.new(@width, @height)
|
||||
@width.times do |x|
|
||||
@height.times do |y|
|
||||
gray[x,y] = self[x,y].to_grayscale
|
||||
end
|
||||
end
|
||||
gray
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue