Last active
February 7, 2016 21:35
-
-
Save fredguth/aa87dc1cba583a78738f to your computer and use it in GitHub Desktop.
Part 2: Following Elm tutorial
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
import Graphics.Element exposing (..) | |
import Graphics.Collage exposing (..) | |
import Color exposing (..) | |
import Mouse | |
import Window | |
import Time exposing (..) | |
import Signal exposing (foldp) | |
--Model | |
type alias Vec = | |
(Float, Float) | |
type alias Pill = | |
{ pos : Vec | |
, vel : Vec | |
, rad : Float | |
, col : Color | |
} | |
vecAdd : Vec -> Vec -> Vec | |
vecAdd (ax, ay) (bx, by) = | |
(ax + bx, ay + by) | |
vecMulS : Vec -> Time -> Vec | |
vecMulS (x, y) t = | |
(x*t, y*t) | |
defaultPill = | |
{ pos = (0,0) | |
, vel = (0,-30) | |
, rad = 15 | |
, col = lightRed | |
} | |
-- Update | |
stepPill : Time -> Pill -> Pill | |
stepPill dt p = | |
{p|pos = vecAdd p.pos (vecMulS p.vel dt)} | |
-- View | |
render : (Int, Int) -> Pill -> Element | |
render (w,h) p = | |
let formPill {rad, col, pos} = circle rad | |
|> filled col | |
|> move pos | |
forms = [formPill p] | |
in | |
color lightGray <| container w h middle | |
<| color white | |
<| collage 400 400 forms | |
sig = Signal.map inSeconds (fps 30) | |
main = Signal.map2 render Window.dimensions (foldp stepPill defaultPill sig ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment