Advertisement
Guest User

Untitled

a guest
Sep 21st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.91 KB | None | 0 0
  1.   private def init(window: Window): Grid = {
  2.     val dx = (window.upRight._2 - window.lowLeft._2) / window.number
  3.     val dy = (window.upRight._1 - window.lowLeft._1) / window.number
  4.     def buildNodes(acc: Seq[Node], coor: (Int, Int)) = {
  5.       val x = dx * coor._2 + window.lowLeft._2
  6.       val y = dy * coor._1 + window.lowLeft._1
  7.       coor match {
  8.         case (r, c) if r == 0 => acc :+ Node(window.low(x, y), x, y)
  9.         case (r, c) if c == 0 => acc :+ Node(window.left(x, y), x, y)
  10.         case (r, c) if r == window.number - 1 => acc :+ Node(window.up(x, y), x, y)
  11.         case (r, c) if c == window.number - 1 => acc :+ Node(window.right(x, y), x, y)
  12.         case _ => acc :+ Node(0, x, y)
  13.       }
  14.     }
  15.     val nodes = (0 until window.number) map { row => (0 until window.number) map { col => (row, col) } }
  16.     val grid = nodes map { nodes => nodes.foldLeft(Seq[Node]())(buildNodes) }
  17.     Grid(grid)
  18.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement