why is this rotated and why does this jumble without swapping width and height

This commit is contained in:
aliasless 2019-12-08 19:29:38 -08:00
parent 37d93081db
commit f05a91d6a9
2 changed files with 37 additions and 0 deletions

36
8.2/8.2.hs Normal file
View File

@ -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)

1
8.2/input Normal file

File diff suppressed because one or more lines are too long