Skip to content

Commit 5142b90

Browse files
authored
Merge pull request #25 from theolundqvist/master
add 'updated' method to Image
2 parents 8055736 + cb53882 commit 5142b90

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/scala/introprog/Image.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ class Image (val underlying: java.awt.image.BufferedImage):
2525
for x <- 0 until width; y <- 0 until height do
2626
update(x, y, f(x, y))
2727

28+
/** Set color of pixels by passing `f(x, y)` and return self*/
29+
def updated(f: (Int, Int) => Color): Image =
30+
for x <- 0 until width; y <- 0 until height do
31+
update(x, y, f(x, y))
32+
this
33+
34+
2835
/** Extract and return image pixels.*/
2936
def toMatrix: Array[Array[Color]] =
3037
val xs: Array[Array[Color]] = Array.ofDim(width, height)

0 commit comments

Comments
 (0)