Last active
May 31, 2016 01:15
-
-
Save JoshCheek/6dda9c54e6ebf2080c4cc8af7be32bf9 to your computer and use it in GitHub Desktop.
Squares rotating in Elm (old-style w/ Signal)
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
-- http://ec2-52-202-34-228.compute-1.amazonaws.com:8000/examples/shapes | |
import Color exposing (..) | |
import Graphics.Collage exposing (..) | |
import Graphics.Element exposing (..) | |
import Time exposing (..) | |
radius = 150 | |
clearGrey = rgba 111 111 111 0.6 | |
blueish = hsl (degrees (180+35)) 0.5 0.4 | |
greenish = hsl (degrees (180-35)) 0.5 0.4 | |
main = | |
Signal.map squares (every millisecond) | |
squares t = | |
let | |
style color = | |
traced | |
{ width = 20 | |
, color = color | |
, cap = Round | |
, join = Smooth | |
, dashing = [] | |
, dashOffset = 0 | |
} | |
outerSquares = | |
List.map outerSquare (cornersFor radius) | |
outerSquare center = | |
square (radius-40) center | |
|> style blueish | |
|> rotate (degrees -t/10) | |
innerSquare = | |
square radius (0, 0) | |
|> (style greenish) | |
|> rotate (pi/4) | |
|> rotate (degrees t/10) | |
in | |
collage 700 700 ([innerSquare] ++ outerSquares) | |
square radius center = | |
let | |
corners = cornersFor radius | |
addVec (x1, y1) (x2, y2) = (x1+x2, y1+y2) | |
squarePoints = | |
case List.head corners of | |
Just first -> corners ++ [first] | |
Nothing -> corners | |
squarePath = | |
List.map (addVec center) squarePoints | |
in | |
path squarePath | |
cornersFor r = | |
[ ( r, 0) | |
, ( 0, r) | |
, (-r, 0) | |
, ( 0, -r) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment