scala/ScalaBook/chapter-06/mkppm.scala


import java.io._
val n = 8
var colors = Array( (0,0,139),     (144,238,144), 
                    (0,191,255),   (250,250,210), 
                    (240,230,140), (205,133,63), 
                    (255,20,147),  (160,32,240))
val width = 480
val out = new FileOutputStream("board.ppm")
var m:Int = width / n 
out.write(("P6\n#Created with Scala\n480 480\n255\n").getBytes())
for ( i <- 0 to n-1 ) {
  for ( h <- 0 to m-1;
        w <- 0 to width - 1 ){
    out.write(colors(w/m)._1)  
    out.write(colors(w/m)._2)
    out.write(colors(w/m)._3)    
  }
  var t = colors(7)
  for (j <- 7 to 1 by -1) 
    colors(j) = colors(j-1) 
  colors(0) = t
}
out.close()