Skip to content

Instantly share code, notes, and snippets.

@fffej
Created May 5, 2010 06:08
Show Gist options
  • Save fffej/390442 to your computer and use it in GitHub Desktop.
Save fffej/390442 to your computer and use it in GitHub Desktop.
-- |A simple loop over each pixel
forEachPixel :: Grid -> ((Int,Int) -> IO()) -> IO()
forEachPixel (Grid n _) = forM_ [(u,v) | u<-[1..n], v <- [1..n]]
-- |For simplicity, just consider up,down,left,right to be the neighbours
neighbours :: Grid -> (Int,Int) -> IO (Double,Double,Double,Double)
neighbours g (x,y) = do
up <- readVal g (x-1,y)
down <- readVal g (x+1,y)
left <- readVal g (x,y-1)
right <- readVal g (x,y+1)
return (up,down,left,right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment