lue-bird/elm-xy/1.1.0

NOTE: the latest version is 1.1.3

Xy

Commonly, a tuple is used to describe 2 coordinates ( x, y ) of

  • a point
  • a dimension
  • a velocity
  • ...

examples:

This package contains simple helpers to create, transform & read 2-coordinate-tuples.

import Xy exposing (Xy)

type alias Model =
    { playerPosition : Xy Float
    , playerVelocity : Xy Float
    }

update msg model =
    case msg of
        SimulatePhysics ->
            { model
                | playerPosition =
                    model.playerPosition
                        |> Xy.map2 (+) model.playerVelocity
                , playerVelocity =
                    model.playerVelocity
                        |> Xy.map ((*) 0.98)
                        |> Xy.mapY (\y -> y - 1)
            }

view { playerPosition } =
    Collage.circle 50
        |> Collage.filled (Collage.uniform Color.red)
        |> Collage.shift playerPosition
        |> Collage.Render.svg

another example

type alias Model =
    { windowSize : Xy Float }

init =
    ( { windowSize = Xy.zero }
    , Browser.Dom.getViewport
        |> Task.perform
            (.viewport >> Xy.fromSize >> Resized)
    )

subscriptions =
    Browser.Events.onResize
        (\w h ->
            Resized (( w, h ) |> Xy.map toFloat)
        )