why is this rotated and why does this jumble without swapping width and height
This commit is contained in:
parent
37d93081db
commit
f05a91d6a9
|
@ -0,0 +1,36 @@
|
|||
import Data.List
|
||||
import Data.List.Split
|
||||
import Data.String.Utils
|
||||
|
||||
import Graphics.Gloss
|
||||
|
||||
type SpaceImage = [SpaceLayer]
|
||||
type SpaceLayer = [Colour]
|
||||
data Colour = Black | White | Transparent deriving Show
|
||||
|
||||
toSpaceImage:: Int -> String -> SpaceImage
|
||||
toSpaceImage dimensions input = chunksOf dimensions $ map (toColour) (strip input)
|
||||
where toColour '0' = Black
|
||||
toColour '1' = White
|
||||
toColour '2' = Transparent
|
||||
|
||||
compressSpaceImage :: SpaceImage -> SpaceLayer
|
||||
compressSpaceImage layers = map (firstColour) $ transpose layers
|
||||
where firstColour (Black:xs) = Black
|
||||
firstColour (White:xs) = White
|
||||
firstColour (Transparent:xs) = firstColour xs
|
||||
firstColour [] = Black
|
||||
|
||||
fromTuple (a, b) = (fromIntegral a, fromIntegral b)
|
||||
|
||||
renderSpaceLayer :: (Int, Int) -> SpaceLayer -> Picture
|
||||
renderSpaceLayer dims layer = pictures $ map (toPixel) (withPositions (fromTuple dims) layer)
|
||||
where withPositions (width, height) layer = zip [ (x, y) | x <- [1 .. height], y <- [1 .. width] ] layer
|
||||
toPixel ((x, y), colour) = translate x y $ color (toGlossColor colour) $ rectangleSolid 1 1
|
||||
toGlossColor Black = black
|
||||
toGlossColor White = white
|
||||
|
||||
main = do
|
||||
spaceImage <- readFile "input"
|
||||
display (InWindow "spaceimage" (200, 200) (10, 10)) black (image spaceImage)
|
||||
where image = renderSpaceLayer (25, 6) . compressSpaceImage . toSpaceImage (25 * 6)
|
Loading…
Reference in New Issue