Commonly, a tuple is used to describe 2 coordinates ( x, y ) of
examples:
Playground.polygon, Playground.toXY, ...
polygon : Color -> List ( Float, Float ) -> Shape
toXY : Keyboard -> ( Float, Float )Collage.shift, Collage.polygon, ...
shift : ( Float, Float ) -> Collage msg -> Collage msg
polygon : List ( Float, Float ) -> ShapeThis 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.svganother 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)
)