diff --git a/Exam2.tsl b/Exam2.tsl new file mode 100644 index 0000000000000000000000000000000000000000..b3c5d3ec5b4333133d15ecf30286ae3fc085a5e7 --- /dev/null +++ b/Exam2.tsl @@ -0,0 +1,3 @@ +t1 << tile1; +t2 << tile2; +t3 = joinV t1 t2; \ No newline at end of file diff --git a/Exam2.txt b/Exam2.txt deleted file mode 100644 index 74b0abd3e03e20df2624ef026f9b1afb5fc140b5..0000000000000000000000000000000000000000 --- a/Exam2.txt +++ /dev/null @@ -1,2 +0,0 @@ -tile1 << tile1; -print tile1; \ No newline at end of file diff --git a/TileViewer.exe b/TileViewer.exe new file mode 100644 index 0000000000000000000000000000000000000000..66f03c0f4fca26e1889c5eab330b3653a9edc9f2 Binary files /dev/null and b/TileViewer.exe differ diff --git a/TileViewer.hi b/TileViewer.hi new file mode 100644 index 0000000000000000000000000000000000000000..686a2938e2f0c20d8f344af85de8ab0eb63e2884 Binary files /dev/null and b/TileViewer.hi differ diff --git a/TileViewer.hs b/TileViewer.hs new file mode 100644 index 0000000000000000000000000000000000000000..a9d38b169e7dcebc11cb54de08adb13a36b44d9e --- /dev/null +++ b/TileViewer.hs @@ -0,0 +1,63 @@ +import Graphics.Gloss +import Data.List +import Debug.Trace +import System.IO +import System.Environment (getArgs) + +type Cell = (Int,Int) + +minViewPortSize = 100 +maxViewPortSize = 750 +defaultCellSize = 10 + +windowDisplay :: Int -> Display +windowDisplay viewPortSize = InWindow "Tile Viewer" (viewPortSize,viewPortSize) (20,20) + +background :: Color +background = white + +-- Assumes a tile is a square +drawTile :: Int -> [String] -> Picture +drawTile _ [] = Blank +drawTile viewPortSize tile = pictures $ map (\cell -> squareAt cellSize cell) cells + where cellSize = fromIntegral(viewPortSize) / fromIntegral ((length tile)) + cells = tile2cells tile + -- Drawing code for an individual square of the appropriate size at the given col/row + squareAt :: Float -> Cell -> Picture + squareAt cellSize (x,y) = polygon [ p1,p2,p3,p4 ] + where p1 = cell2Point cellSize (x,y) + p2 = ( fst p1 + cellSize , snd p1 ) + p3 = ( fst p2 , snd p2 - cellSize ) + p4 = ( fst p1 , snd p3 ) + -- Converts col/row coordinates to window coordinates offset from top-left + cell2Point :: Float -> Cell -> Point + cell2Point cellSize (x,y) = (xP,yP) + where xP = fst topLeft + (fromIntegral x) * cellSize + yP = snd topLeft - (fromIntegral y) * cellSize + --origin (0,0) is centre of the window + --this is the top-left corner + topLeft :: Point + topLeft = (negate half, half) + where half = (fromIntegral viewPortSize) / 2 + +--Finds the indexes at which the Tile value contains '1' +tile2cells :: [String] -> [Cell] +tile2cells tile = makeCells 0 idxss + where idxss = map (findIndices (\c -> c=='1')) tile + makeCells row [] = [] + makeCells row (idxs : idxss) = (map (\col -> (col,row)) idxs) ++ (makeCells (row+1) idxss) + +-- Checks that input string only contains 0s and 1s +checkInput :: Char -> Bool +checkInput '0' = True +checkInput '1' = True +checkInput _ = error "Unrecognised characted in input file" + +main :: IO () +main = do (fileName : _ ) <- getArgs + tileString <- readFile fileName + let tile = lines tileString + let _ = map (map checkInput) tile + let vPSize = max minViewPortSize ( min maxViewPortSize ( defaultCellSize * (length tile))) + display (windowDisplay vPSize) background (drawTile vPSize tile) + diff --git a/TileViewer.o b/TileViewer.o new file mode 100644 index 0000000000000000000000000000000000000000..266fc34cb97c2acbda48ead043d0a8cb8e1e5ca7 Binary files /dev/null and b/TileViewer.o differ diff --git a/Tsl.exe b/Tsl.exe index 64b8081be1730666ade1cf793d65de2826eb3bf6..1db73b7ed381b62119ff887c2a26c7ea01189072 100644 Binary files a/Tsl.exe and b/Tsl.exe differ diff --git a/Tsl.o b/Tsl.o index 72af5f1b2293e43d280ed3c6036e23177f2aa7f2..f8bb60e511e0f9f33489e946f5debfd774ee1aea 100644 Binary files a/Tsl.o and b/Tsl.o differ diff --git a/group.txt b/group.txt new file mode 100644 index 0000000000000000000000000000000000000000..16877318ab9cf2095b5de00b70576ce33618d7c7 --- /dev/null +++ b/group.txt @@ -0,0 +1,4 @@ +Mathew Zone - mhz1g21 +Paul Winpenny - plw1g21 +Thomas Holwill - th2g20 +40%-40%-20% \ No newline at end of file diff --git a/report.pdf b/report.pdf new file mode 100644 index 0000000000000000000000000000000000000000..a086fc99bbc5d5257cc5889a4586f2ffef42cc90 Binary files /dev/null and b/report.pdf differ