def floodFill(x:Int, y:Int, c:Char) = {
def fill(s:Set[(Int, Int)], c:Char, t:Char):Unit = {
val (x,y) = s.head
val current_color = colorAt(x,y)
if(current_color == t && current_color != c) {
plotPixel(x, y, c)
val left = if(x > 0) Set((x-1,y)) else Set()
val right = if(x < width-1) Set((x+1,y)) else Set()
val up = if(y > 0) Set((x,y-1)) else Set()
val down = if(y < height-1) Set((x,y+1)) else Set()
fill(s.tail ++ left ++ right ++ up ++ down, c, t)
} else if(!s.tail.isEmpty) {
fill(s.tail, c, t)
}
}
val source_color = colorAt(x,y)
val s = Set((x,y))
fill(s, c, source_color)
}