Skip to content

Commit

Permalink
Merge pull request #25 from theolundqvist/master
Browse files Browse the repository at this point in the history
add 'updated' method to Image
  • Loading branch information
bjornregnell authored Sep 22, 2021
2 parents 8055736 + cb53882 commit 5142b90
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/scala/introprog/Image.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5142b90

Please sign in to comment.