Skip to content

Instantly share code, notes, and snippets.

@mgwidmann
Created January 12, 2016 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgwidmann/79eb931c32be7501b491 to your computer and use it in GitHub Desktop.
Save mgwidmann/79eb931c32be7501b491 to your computer and use it in GitHub Desktop.
module ElmDemoRefactored where
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Color exposing (..)
import Time
import Text
import Window
-- MODEL
type alias Model = {count : Int, dir : Int}
-- UPDATE
update: Float -> Model -> Model
update timestamp circleSize =
let
newCount = nextCount circleSize.dir circleSize
newDir = if newCount == 0 then circleSize.dir * -1 else circleSize.dir
finalCount = if newDir /= circleSize.dir then nextCount newDir circleSize else newCount
in
{ circleSize | count = finalCount, dir = newDir}
nextCount: Int -> Model -> Int
nextCount dir circleSize =
rem (circleSize.count + dir) 500
-- VIEW
view: (Int, Int) -> Model -> Element
view (x, y) circleSize =
collage x y [
Graphics.Collage.circle (toFloat circleSize.count)
|> gradient circleGradient,
scale (toFloat circleSize.count * 0.08) (text (Text.fromString "Elm"))
]
circleGradient : Gradient
circleGradient =
radial (0,0) 0 (0,0) 500
[ (0, rgb 167 211 12)
, (1, rgb 1 159 98)
]
-- SIGNALS
signals : Signal Time.Time
signals =
Time.every Time.millisecond
-- MAIN
foldp: Signal Model
foldp =
Signal.foldp update {count = 0, dir = 1} signals
main : Signal Element
main =
Signal.map2 view Window.dimensions foldp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment