Created
March 22, 2014 22:53
-
-
Save skybrian/9715744 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Dict | |
indexed: [a] -> Dict.Dict Int a | |
indexed list = Dict.fromList (zip [0..(length list)] list) | |
type Palette = Dict.Dict Int Color | |
makePalette: [Color] -> Palette | |
makePalette colors = indexed colors | |
palette = makePalette [red, orange, yellow, green, blue, purple] | |
colorAt: Palette -> Int -> Color | |
colorAt p i = case Dict.lookup i p of | |
Just c -> c | |
Nothing -> black | |
cellAt: Int -> Int -> Form | |
cellAt x i = moveX (toFloat (5 + x * 10)) (filled (colorAt palette i) (rect 10 10)) | |
rowAt: Int -> [Int] -> Form | |
rowAt y pixels = moveY (toFloat (-5 - y * 10)) (group (zipWith cellAt [0..(length pixels)] pixels)) | |
grid: [[Int]] -> Element | |
grid pixels = | |
let width = 10 * (length (head pixels)) | |
height = 10 * (length pixels) | |
in | |
collage width height [(move (toFloat(-width)/2,toFloat(height)/2) (group (zipWith rowAt [0..(length pixels)] pixels)))] | |
main: Element | |
main = grid [[0,1,2,3,4,5], [1,2,3,4,5,6], [2,3,4,5,6,7]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment