Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Html exposing (Html, text)
- import Svg exposing (Svg, svg, circle)
- import Svg.Attributes exposing (width, height, viewBox, cx, cy, r)
- import Time exposing (Time, every, second, inSeconds)
- type alias Model =
- { x : Float
- , y : Float
- , r : Float
- }
- model : Model
- model = Model 400 300 25
- init : (Model, Cmd Msg)
- init = (model, Cmd.none)
- type Msg = Tick Time
- subscriptions : Model -> Sub Msg
- subscriptions model =
- every (second / 60) Tick
- updateBall : Model -> Time -> Model
- updateBall model t =
- let speed = t / 2 in
- let angle = turns <| inSeconds speed in
- { x = (cos angle) * 200 + 400
- , y = (sin angle) * 50 + 300
- , r = (sin angle) * 8 + 25
- }
- update : Msg -> Model -> (Model, Cmd Msg)
- update msg model =
- case msg of
- Tick t -> (updateBall model t, Cmd.none)
- view : Model -> Html Msg
- view model =
- svg
- [ width "800"
- , height "600"
- , viewBox "0 0 800 600"
- ]
- [ circle
- [ cx <| toString model.x
- , cy <| toString model.y
- , r <| toString model.r
- ] []
- ]
- main : Platform.Program Never Model Msg
- main =
- Html.program
- { init = init
- , subscriptions = subscriptions
- , update = update
- , view = view
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement