/
sneeuwvlokken-9.elm
67 lines (50 loc) · 1.83 KB
/
sneeuwvlokken-9.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- sneeuwvlokken-9 -- teken via mypolyline
module Main exposing(..)
import Browser
import Html exposing (div, text, input, button, Html)
import Html.Attributes exposing (placeholder, value)
import Html.Events exposing (onInput, onClick)
import String exposing (join, repeat)
import List exposing(map)
import Maybe
import Svg exposing (svg, polyline, g)
import Svg.Attributes exposing (..)
-------------- ALGEMENE DEFINITIES ------------------------
--------- TEKENEN --------
type alias Point = { x: Float, y: Float }
point2String : Point -> String
point2String p = String.fromFloat p.x ++ "," ++ String.fromFloat p.y
mypolyline kleur punten =
let puntenstring = punten |> map point2String |> String.join " "
in
polyline [ stroke kleur, points puntenstring ] [ ]
--================= SHOWTIME ==========================
main = Browser.sandbox { init = myinit, view = myview, update = myupdate }
------------------- MODEL -----------------------------
type alias Model = { naam: String, aantal: Int }
myinit : Model
myinit = { naam = "Klaas", aantal = 3 }
------------------- VIEW -----------------------------
myview: Model -> Html Msg
myview model =
let
-- plaatje = [ polyline [ stroke "blue", points "10, 10 30, 30" ] [ ] ]
plaatje = [ mypolyline "blue" [Point 10 10, Point 10 100 ] ]
in
div []
[
div [ ] [ Html.b [] [ text (repeat model.aantal "Hoi, ")], text model.naam ]
, input [ placeholder "uw naam", onInput Naam ] [ ]
, button [ onClick Meer ] [ text "MEER" ]
, svg [ viewBox "0 0 400 400", width "800px"]
[ Svg.g [ ] plaatje ]
]
------------------- UPDATE -----------------------------
type Msg
= Naam String
| Meer
myupdate: Msg -> Model -> Model
myupdate msg model =
case msg of
Naam n -> { model | naam = n }
Meer -> { model | aantal = model.aantal + 1 }