Last active
November 30, 2015 22:10
-
-
Save stoft/b4eef971d1f6367c3909 to your computer and use it in GitHub Desktop.
Displays 10 boxes, one of them randomly switching off every cycle (200ms).
This file contains hidden or 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
module DiscoBoxen where | |
import Array exposing (fromList, get) | |
import Color exposing (Color, black, white, green, red, blue, yellow, brown, purple, orange) | |
import Graphics.Element exposing (Element, spacer, color, flow, right, show) | |
import List exposing (foldr, (::)) | |
import Random exposing (generate, initialSeed) | |
import Time exposing (every, millisecond, second) | |
drawSquare : Int -> Int -> Color -> Element | |
drawSquare x y c = | |
spacer x y |> color c | |
drawSquares : Int -> List Element | |
drawSquares r = | |
foldr | |
(\x acc -> (::) | |
(if r == x then | |
drawSquare 10 10 white | |
else | |
drawSquare 10 10 black) | |
acc) | |
[] | |
[1..10] | |
getColor n = | |
if n % 2 == 0 then | |
black | |
else | |
white | |
getRandomBoxNum n = | |
let doGenerate seed = | |
generate (Random.int 1 10) (initialSeed (round seed)) |> fst | |
in | |
Signal.map doGenerate (every (n * millisecond)) | |
{-getRandomBoxNum seed = | |
generate (Random.int 1 10) (initialSeed (round seed)) |> fst | |
main = | |
Signal.map (flow right) (Signal.map drawSquares (Signal.map getRandomBoxNum (every (200 * millisecond)))) | |
-} | |
main = | |
Signal.map (flow right) (Signal.map drawSquares (getRandomBoxNum 200)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a stylistic comment - since you set things up in the
let
for the expression in thein
, I would personally do: