Hey look there's a thing on the screen!
This commit is contained in:
parent
24991c8fa3
commit
eefd9cb2c8
2 changed files with 59 additions and 26 deletions
|
@ -9,7 +9,9 @@
|
||||||
"exposed-modules": [],
|
"exposed-modules": [],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"elm-lang/core": "5.1.1 <= v < 6.0.0",
|
"elm-lang/core": "5.1.1 <= v < 6.0.0",
|
||||||
"elm-lang/html": "2.0.0 <= v < 3.0.0"
|
"elm-lang/html": "2.0.0 <= v < 3.0.0",
|
||||||
|
"elm-lang/svg": "2.0.0 <= v < 3.0.0",
|
||||||
|
"folkertdev/svg-path-dsl": "2.0.0 <= v < 3.0.0"
|
||||||
},
|
},
|
||||||
"elm-version": "0.18.0 <= v < 0.19.0"
|
"elm-version": "0.18.0 <= v < 0.19.0"
|
||||||
}
|
}
|
||||||
|
|
81
main.elm
81
main.elm
|
@ -1,50 +1,81 @@
|
||||||
import Html exposing (Html, Attribute, input, button, div, text)
|
import Html exposing (Html, h1, div, text)
|
||||||
import Html.Attributes exposing (..)
|
import Time exposing (Time, second)
|
||||||
import Html.Events exposing (onClick, onInput)
|
import Svg exposing (Svg, svg, g, path)
|
||||||
|
import Svg.Attributes exposing (stroke, fill, strokeLinejoin, strokeWidth, width, height, viewBox, d)
|
||||||
|
import Svg.Path exposing (pathToString, arcBy, subpath, closed, lineBy, startAt, antiClockwise, clockwise, largestArc)
|
||||||
|
|
||||||
|
|
||||||
|
mOVE_SPEED = 60 -- pixels per second
|
||||||
|
cHAR_RAD = 25 --half-width of character
|
||||||
|
wIDTH = "500"
|
||||||
|
hEIGHT = "900"
|
||||||
|
|
||||||
|
main : Program Never Model Msg
|
||||||
main =
|
main =
|
||||||
Html.beginnerProgram { model = model, view = view, update = update }
|
Html.beginnerProgram
|
||||||
|
{ model = model
|
||||||
|
, view = view
|
||||||
|
, update = update
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
-- MODEL
|
-- MODEL
|
||||||
|
|
||||||
type alias Model = { count : Int, content : String }
|
type alias Model =
|
||||||
|
{ time : Time}
|
||||||
|
|
||||||
model : Model
|
model : Model
|
||||||
model =
|
model = {
|
||||||
{ count = 0, content = "" }
|
time = 0
|
||||||
|
}
|
||||||
|
|
||||||
-- UPDATE
|
-- UPDATE
|
||||||
|
|
||||||
type Msg = Increment | Decrement | Reset | ChangeContent String
|
type Msg = Tick Time
|
||||||
|
|
||||||
update : Msg -> Model -> Model
|
update : Msg -> Model -> Model
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
Increment ->
|
Tick newTime ->
|
||||||
{ model | count = model.count + 1 }
|
{ model | time = newTime }
|
||||||
|
|
||||||
Decrement ->
|
|
||||||
{ model | count = model.count - 1 }
|
|
||||||
|
|
||||||
Reset ->
|
|
||||||
{ model | count = 0 }
|
|
||||||
|
|
||||||
ChangeContent newContent ->
|
|
||||||
{ model | content = newContent }
|
|
||||||
|
|
||||||
|
-- SUMSCRIPTIONS
|
||||||
|
|
||||||
-- VIEW
|
-- VIEW
|
||||||
|
|
||||||
|
type alias Point = (Float, Float)
|
||||||
|
|
||||||
|
render : String -> String -> Model -> Html msg
|
||||||
|
render w h model =
|
||||||
|
svg [ width w, height h, viewBox "0 0 500, 900"] [pacman (250, 450) (degrees 90)]
|
||||||
|
|
||||||
|
pacman : Point -> Float -> Svg msg
|
||||||
|
pacman position openness =
|
||||||
|
let
|
||||||
|
opp = cHAR_RAD * sin (openness/2)
|
||||||
|
adj = cHAR_RAD * cos (openness/2)
|
||||||
|
in
|
||||||
|
g []
|
||||||
|
[ path
|
||||||
|
[ d <|
|
||||||
|
pathToString [(subpath (startAt position) closed
|
||||||
|
[lineBy (adj, opp)
|
||||||
|
,arcBy (cHAR_RAD, cHAR_RAD) 0 (largestArc, clockwise) (0, -(opp * 2))
|
||||||
|
,lineBy (-adj, opp)
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
,fill "#ffff00"
|
||||||
|
]
|
||||||
|
[]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
div []
|
div []
|
||||||
[ button [ onClick Increment ] [ text "+" ]
|
[h1 [] [text "ElmMan!"]
|
||||||
, div [] [ text (toString model.count) ]
|
,render wIDTH hEIGHT model
|
||||||
, button [ onClick Decrement ] [ text "-" ]
|
|
||||||
, button [ onClick Reset ] [ text "Reset" ]
|
|
||||||
, input [ placeholder "Text to reverse", onInput ChangeContent ] []
|
|
||||||
, div [] [ text (String.reverse model.content )]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue