Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private def init(window: Window): Grid = {
- val dx = (window.upRight._2 - window.lowLeft._2) / window.number
- val dy = (window.upRight._1 - window.lowLeft._1) / window.number
- def buildNodes(acc: Seq[Node], coor: (Int, Int)) = {
- val x = dx * coor._2 + window.lowLeft._2
- val y = dy * coor._1 + window.lowLeft._1
- coor match {
- case (r, c) if r == 0 => acc :+ Node(window.low(x, y), x, y)
- case (r, c) if c == 0 => acc :+ Node(window.left(x, y), x, y)
- case (r, c) if r == window.number - 1 => acc :+ Node(window.up(x, y), x, y)
- case (r, c) if c == window.number - 1 => acc :+ Node(window.right(x, y), x, y)
- case _ => acc :+ Node(0, x, y)
- }
- }
- val nodes = (0 until window.number) map { row => (0 until window.number) map { col => (row, col) } }
- val grid = nodes map { nodes => nodes.foldLeft(Seq[Node]())(buildNodes) }
- Grid(grid)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement