Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package o1.hiddenpics
  2.  
  3.  
  4. /** The class `Picture` represents an image that is used in the Hidden Pics application.
  5. * An image consists of pixels, represented here by `Pixel` objects. The pixels are
  6. * organized in rows and columns.
  7. *
  8. * Although individual pixels are represented as immutable objects, a `Picture` object
  9. * is mutable: any of its pixels can be changed for another. This facility is used by
  10. * the `filterReveal` methods, which, once implemented, can be used to "solve" the
  11. * garbled images provided with this application. For more information, see Chapter 5.6
  12. * in the course materials.
  13. *
  14. * @see [[Pixel]]
  15. * @param pixels a "two-dimensional" array of pixels which form this picture. The outer array
  16. * contains the "columns" of the image, each of which is an array of vertically
  17. * aligned pixels. This array must be "rectangular" and must contain at least one pixel. */
  18. class Picture(private val pixels: Array[Array[Pixel]]) {
  19.  
  20.  
  21. /** Returns the pixel at the given coordinates in this picture.
  22. * @param x an x coordinate between 0 and `width - 1`
  23. * @param y a y coordinate between 0 and `height - 1` */
  24. def apply(x: Int, y: Int) = this.pixels(x)(y)
  25.  
  26.  
  27. /** Returns the width of this picture, in pixels. */
  28. def width = this.pixels.size
  29.  
  30.  
  31. /** Returns the height of this picture, in pixels. */
  32. def height = this.pixels(0).size
  33.  
  34.  
  35. /** Runs a filter on the picture that "solves" the first hidden picture puzzle.
  36. * See Chapter 5.6 in the course materials for details. */
  37. def filterReveal1() = {
  38. for (i <- 0 until this.pixels.size) {
  39. for(j <- 0 until this.pixels(0).size)
  40. this.pixels(i)(j) = new Pixel(this.pixels(i)(j).red * 10,0,0)
  41. }
  42. }
  43.  
  44.  
  45. /** Runs a filter on the picture that "solves" the second hidden picture puzzle.
  46. * See Chapter 5.6 in the course materials for details. */
  47. def filterReveal2() = {
  48. for (i <- 0 until this.pixels.size) {
  49. for(j <- 0 until this.pixels(0).size)
  50. if (this.pixels(i)(j).blue < 16){
  51. this.pixels(i)(j) = new Pixel(this.pixels(i)(j).blue*16,this.pixels(i)(j).blue*16,this.pixels(i)(j).blue*16)
  52. }
  53. else this.pixels(i)(j) = new Pixel(0,0,0)
  54. }
  55. }
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement