Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.24 KB | None | 0 0
  1. import Html exposing (Html, text)
  2. import Svg exposing (Svg, svg, circle)
  3. import Svg.Attributes exposing (width, height, viewBox, cx, cy, r)
  4. import Time exposing (Time, every, second, inSeconds)
  5.  
  6. type alias Model =
  7.   { x : Float
  8.   , y : Float
  9.   , r : Float
  10.   }
  11.  
  12. model : Model
  13. model = Model 400 300 25
  14.  
  15. init : (Model, Cmd Msg)
  16. init = (model, Cmd.none)
  17.  
  18. type Msg = Tick Time
  19.  
  20. subscriptions : Model -> Sub Msg
  21. subscriptions model =
  22.   every (second / 60) Tick
  23.  
  24. updateBall : Model -> Time -> Model
  25. updateBall model t =
  26.   let speed = t / 2 in
  27.   let angle = turns <| inSeconds speed in
  28.   { x = (cos angle) * 200 + 400
  29.   , y = (sin angle) *  50 + 300
  30.   , r = (sin angle) *   8 +  25
  31.   }
  32.  
  33. update : Msg -> Model -> (Model, Cmd Msg)
  34. update msg model =
  35.   case msg of
  36.     Tick t -> (updateBall model t, Cmd.none)
  37.  
  38. view : Model -> Html Msg
  39. view model =
  40.   svg
  41.     [ width "800"
  42.     , height "600"
  43.     , viewBox "0 0 800 600"
  44.     ]
  45.     [ circle
  46.         [ cx <| toString model.x
  47.         , cy <| toString model.y
  48.         ,  r <| toString model.r
  49.         ] []
  50.     ]
  51.  
  52. main : Platform.Program Never Model Msg
  53. main =
  54.   Html.program
  55.     { init = init
  56.     , subscriptions = subscriptions
  57.     , update = update
  58.     , view = view
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement