Untitled


SUBMITTED BY: Guest

DATE: Nov. 11, 2013, 9:31 p.m.

FORMAT: Text only

SIZE: 1.2 kB

HITS: 2330

  1. def floodFill(x:Int, y:Int, c:Char) = {
  2. def fill(s:Set[(Int, Int)], c:Char, t:Char):Unit = {
  3. val (x,y) = s.head
  4. val current_color = colorAt(x,y)
  5. if(current_color == t && current_color != c) {
  6. plotPixel(x, y, c)
  7. val left = if(x > 0) Set((x-1,y)) else Set()
  8. val right = if(x < width-1) Set((x+1,y)) else Set()
  9. val up = if(y > 0) Set((x,y-1)) else Set()
  10. val down = if(y < height-1) Set((x,y+1)) else Set()
  11. fill(s.tail ++ left ++ right ++ up ++ down, c, t)
  12. } else if(!s.tail.isEmpty) {
  13. fill(s.tail, c, t)
  14. }
  15. }
  16. val source_color = colorAt(x,y)
  17. val s = Set((x,y))
  18. fill(s, c, source_color)
  19. }

comments powered by Disqus