diff --git a/src/main/scala/introprog/Image.scala b/src/main/scala/introprog/Image.scala index 938f294..5c5ad9d 100644 --- a/src/main/scala/introprog/Image.scala +++ b/src/main/scala/introprog/Image.scala @@ -25,6 +25,13 @@ class Image (val underlying: java.awt.image.BufferedImage): for x <- 0 until width; y <- 0 until height do update(x, y, f(x, y)) + /** Set color of pixels by passing `f(x, y)` and return self*/ + def updated(f: (Int, Int) => Color): Image = + for x <- 0 until width; y <- 0 until height do + update(x, y, f(x, y)) + this + + /** Extract and return image pixels.*/ def toMatrix: Array[Array[Color]] = val xs: Array[Array[Color]] = Array.ofDim(width, height)