diff --git a/elm.json b/elm.json index b8ff8c9..42f0c9a 100644 --- a/elm.json +++ b/elm.json @@ -8,7 +8,8 @@ "direct": { "elm/browser": "1.0.1", "elm/core": "1.0.2", - "elm/html": "1.0.0" + "elm/html": "1.0.0", + "elm/svg": "1.0.1" }, "indirect": { "elm/json": "1.1.3", diff --git a/elm.json b/elm.json index b8ff8c9..42f0c9a 100644 --- a/elm.json +++ b/elm.json @@ -8,7 +8,8 @@ "direct": { "elm/browser": "1.0.1", "elm/core": "1.0.2", - "elm/html": "1.0.0" + "elm/html": "1.0.0", + "elm/svg": "1.0.1" }, "indirect": { "elm/json": "1.1.3", diff --git a/publish.sh b/publish.sh index eca2bd0..58abd93 100755 --- a/publish.sh +++ b/publish.sh @@ -5,6 +5,7 @@ echo "Missing config file 'publish.config.user' created." else webpack --mode production --devtool false + npm run build-elm # executes all variable definitions in the config file: . publish.config.user diff --git a/elm.json b/elm.json index b8ff8c9..42f0c9a 100644 --- a/elm.json +++ b/elm.json @@ -8,7 +8,8 @@ "direct": { "elm/browser": "1.0.1", "elm/core": "1.0.2", - "elm/html": "1.0.0" + "elm/html": "1.0.0", + "elm/svg": "1.0.1" }, "indirect": { "elm/json": "1.1.3", diff --git a/publish.sh b/publish.sh index eca2bd0..58abd93 100755 --- a/publish.sh +++ b/publish.sh @@ -5,6 +5,7 @@ echo "Missing config file 'publish.config.user' created." else webpack --mode production --devtool false + npm run build-elm # executes all variable definitions in the config file: . publish.config.user diff --git a/src/Main.elm b/src/Main.elm index 0ada492..2dd3776 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -1,7 +1,89 @@ module Main exposing (..) -import Html exposing (text) +import Html exposing (..) +import Svg exposing (..) +import Svg.Attributes exposing (..) + + +type alias Point = + { x : Float, y : Float } + + +type alias Line = + { start : Point, end : Point } + + +add a b = + Point (a.x + b.x) (a.y + b.y) + + +scale s p = + Point (s * p.x) (s * p.y) + + +diff start end = + add end (scale -1 start) + + +midpoint s line = + add line.start (scale s (diff line.start line.end)) + + +rotateMinus90Deg p = + Point p.y -p.x + + +tip line = + diff line.start line.end + |> rotateMinus90Deg + |> scale (sqrt 3 / 6) + |> add (midpoint 0.5 line) + + +kochDivide line = + [ Line line.start (midpoint (1 / 3) line) + , Line (midpoint (1 / 3) line) (tip line) + , Line (tip line) (midpoint (2 / 3) line) + , Line (midpoint (2 / 3) line) line.end + ] + + +kochIteration iterations lineList = + if iterations == 0 then + lineList + + else + List.concatMap kochDivide lineList |> kochIteration (iterations - 1) + + +lineToSvg : Line -> Svg.Svg msg +lineToSvg line = + Svg.line + [ x1 (String.fromFloat line.start.x) + , y1 (String.fromFloat line.start.y) + , x2 (String.fromFloat line.end.x) + , y2 (String.fromFloat line.end.y) + ] + [] + + +baseHeight = + 250 + + +startLine = + Line (Point 0 baseHeight) (Point 400 baseHeight) main = - text "Hello there!" + div [ class "tile" ] + [ h2 [] [ Html.text "Koch" ] + , div [] + [ svg + [ width "400px" + , height "400px" + , Svg.Attributes.style "fill: none; stroke: purple; stroke-width: 1;" + ] + ([ startLine ] |> kochIteration 5 |> List.map lineToSvg) + ] + ]