justgook/webgl-shape/3.0.0

WebGL.Shape2d.SolidShape

Texture-less converter

{ a | width : Width, height : Height }
-> List SolidShape
-> List Entity

Converts List SolidShape to WebGL entities

main : Program () () a
main =
    Browser.sandbox
        { init = ()
        , view = view
        , update = \_ model -> model
        }


view : model -> Html msg
view _ =
    let
        screen =
            Game2d.toScreen 100 100
    in
    { entities =
        [ rectangle (rgb 239 41 41) 20 20 ]
            |> SolidShape.toEntities screen
    , screen = screen
    }
        |> Game2d.view
shape : Width -> Height -> Render -> SolidShape

Create SolidShape from Render

rectangle : Color -> Width -> Height -> SolidShape
rectangle color w h =
    Render.rect color |> SolidShape.shape w h
group : List SolidShape -> SolidShape

Put shapes together so you can move and rotate them as a group. Maybe you want to put a bunch of stars in the sky:

shapes =
    [ star
        |> move 100 100
        |> rotate 5
    , star
        |> move -120 40
        |> rotate 20
    , star
        |> move 80 -150
        |> rotate 32
    , star
        |> move -90 -30
        |> rotate -16
    ]


star =
    group
        [ triangle yellow 20
        , triangle yellow 20
            |> rotate 180
        ]
type alias SolidShape =
Shape Form
type Form
= Form (ShapeData Render)
| Group (GroupData (Shape Form))