Created
July 7, 2015 15:50
-
-
Save paulsmith/a4b02662ab31c7491c0c 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 Text exposing (..) | |
import Color exposing (..) | |
import Graphics.Element exposing (..) | |
import Graphics.Collage exposing (..) | |
import List | |
import Time exposing (Time, fps, timestamp) | |
import Signal exposing ((<~)) | |
main = | |
let | |
delta = fps 60 | |
sizes' = sizes (List.length colors) 100 | |
angles = (\(t, _) -> angle t) <~ timestamp delta | |
anglesSignal = Signal.sampleOn delta angles | |
in | |
(\a -> collage 200 200 (diamonds sizes' a)) <~ anglesSignal | |
diamonds : List Float -> Float -> List Form | |
diamonds sizes angle = | |
List.map2 (,) colors sizes | |
|> List.map (\(color, size) -> diamond color size angle) | |
angle timestamp = | |
toFloat ((round (timestamp / 10)) % 360) | |
sizes : Int -> Int -> List Float | |
sizes n max = | |
let | |
step = 20 | |
start = max // step | |
stop = (max - n*step) // step | |
in | |
downTo start stop | |
|> List.map (\n -> n * step) | |
|> List.map toFloat | |
downTo : Int -> Int -> List Int | |
downTo start stop = | |
let n = (start - stop) + 1 | |
in | |
List.reverse [1..n] | |
colors : List Color | |
colors = | |
[red, orange, yellow, green, blue, purple] | |
diamond : Color -> Float -> Float -> Form | |
diamond color size angle = | |
square size | |
|> filled color | |
|> rotate (degrees angle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment