Commits: 1

Replace Code block with Editor in day 5

index ce02674..c073ebc 100644
--- a/content/day-5.txt
+++ b/content/day-5.txt
@@ -92,117 +92,136 @@ State is sometimes called model. There are also commands, but we will not use th
=
=First let's change the value of {Code|main} and create the {Code|view} function, like this:
=
-| Code
-    module Main exposing (main)
-
-    import Browser
-    import Dict
-    import Element
-    import Svg exposing (Svg)
-    import Svg.Attributes
-
-
-    main =
-        Browser.element
-            { init = init
-            , view = view
-            , update = update
-            , subscriptions = subscriptions
-            }
-
-
-    view age =
-        [ segment (age / 5000) { color = "brown", rotation = -90 } ]
-            |> Svg.svg
-                [ Svg.Attributes.height "100%"
-                , Svg.Attributes.width "100%"
-                , Svg.Attributes.style "background: none"
-                , Svg.Attributes.viewBox "-500 -500 1000 1000"
-                ]
-            |> Element.html
-            |> Element.layout
-                [ Element.width Element.fill
-                , Element.height Element.fill
-                ]
+| Editor
+    | Code
+        module Main exposing (main)
+
+        import Browser
+        import Dict
+        import Element
+        import Svg exposing (Svg)
+        import Svg.Attributes
+
+
+        main =
+            Browser.element
+                { init = init
+                , view = view
+                , update = update
+                , subscriptions = subscriptions
+                }
+
+
+        view age =
+            [ segment (age / 5000) { color = "brown", rotation = -90 } ]
+                |> Svg.svg
+                    [ Svg.Attributes.height "100%"
+                    , Svg.Attributes.width "100%"
+                    , Svg.Attributes.style "background: none"
+                    , Svg.Attributes.viewBox "-500 -500 1000 1000"
+                    ]
+                |> Element.html
+                |> Element.layout
+                    [ Element.width Element.fill
+                    , Element.height Element.fill
+                    ]
=
=
-    rules =
-        Dict.empty
-            |> Dict.insert "brown"
-                [ { color = "brown", rotation = 0 }
-                , { color = "green", rotation = 20 }
-                , { color = "green", rotation = -30 }
-                ]
-            |> Dict.insert "green"
-                [ { color = "red", rotation = -45 }
-                , { color = "red", rotation = -5 }
-                , { color = "red", rotation = 50 }
-                ]
+        rules =
+            Dict.empty
+                |> Dict.insert "brown"
+                    [ { color = "brown", rotation = 0 }
+                    , { color = "green", rotation = 20 }
+                    , { color = "green", rotation = -30 }
+                    ]
+                |> Dict.insert "green"
+                    [ { color = "red", rotation = -45 }
+                    , { color = "red", rotation = -5 }
+                    , { color = "red", rotation = 50 }
+                    ]
=
=
-    segment age { color, rotation } =
-        if age <= 0 then
-            Svg.g [] []
-
-        else
-            Svg.g []
-                [ rules
-                    |> Dict.get color
-                    |> Maybe.withDefault []
-                    |> List.map (segment (age - 1))
-                    |> Svg.g
-                        [ Svg.Attributes.transform
-                            (String.concat
-                                [ "rotate("
-                                , String.fromFloat rotation
-                                , ") translate("
-                                , String.fromFloat (age * 10)
-                                , ")"
-                                ]
-                            )
-                        ]
-                , dot age color rotation
-                , line age color rotation
-                ]
+        segment age { color, rotation } =
+            if age <= 0 then
+                Svg.g [] []
+
+            else
+                Svg.g []
+                    [ rules
+                        |> Dict.get color
+                        |> Maybe.withDefault []
+                        |> List.map (segment (age - 1))
+                        |> Svg.g
+                            [ Svg.Attributes.transform
+                                (String.concat
+                                    [ "rotate("
+                                    , String.fromFloat rotation
+                                    , ") translate("
+                                    , String.fromFloat (age * 10)
+                                    , ")"
+                                    ]
+                                )
+                            ]
+                    , dot age color rotation
+                    , line age color rotation
+                    ]
=
=
-    dot age color rotation =
-        Svg.circle
-            [ Svg.Attributes.r (String.fromFloat age)
-            , Svg.Attributes.cx "0"
-            , Svg.Attributes.cy "0"
-            , Svg.Attributes.fill color
-            , Svg.Attributes.transform
-                (String.concat
-                    [ "rotate("
-                    , String.fromFloat rotation
-                    , ") translate("
-                    , String.fromFloat (age * 10)
-                    , ")"
-                    ]
-                )
-            ]
-            []
-
-
-    line age color rotation =
-        Svg.line
-            [ Svg.Attributes.strokeWidth "1"
-            , Svg.Attributes.x1 "0"
-            , Svg.Attributes.y1 "0"
-            , Svg.Attributes.x1 (String.fromFloat (age * 10))
-            , Svg.Attributes.y1 "0"
-            , Svg.Attributes.stroke color
-            , Svg.Attributes.strokeWidth (String.fromFloat age)
-            , Svg.Attributes.transform
-                (String.concat
-                    [ "rotate("
-                    , String.fromFloat rotation
-                    , ")"
-                    ]
-                )
-            ]
-            []
+        dot age color rotation =
+            Svg.circle
+                [ Svg.Attributes.r (String.fromFloat age)
+                , Svg.Attributes.cx "0"
+                , Svg.Attributes.cy "0"
+                , Svg.Attributes.fill color
+                , Svg.Attributes.transform
+                    (String.concat
+                        [ "rotate("
+                        , String.fromFloat rotation
+                        , ") translate("
+                        , String.fromFloat (age * 10)
+                        , ")"
+                        ]
+                    )
+                ]
+                []
+
+
+        line age color rotation =
+            Svg.line
+                [ Svg.Attributes.strokeWidth "1"
+                , Svg.Attributes.x1 "0"
+                , Svg.Attributes.y1 "0"
+                , Svg.Attributes.x1 (String.fromFloat (age * 10))
+                , Svg.Attributes.y1 "0"
+                , Svg.Attributes.stroke color
+                , Svg.Attributes.strokeWidth (String.fromFloat age)
+                , Svg.Attributes.transform
+                    (String.concat
+                        [ "rotate("
+                        , String.fromFloat rotation
+                        , ")"
+                        ]
+                    )
+                ]
+                []
+
+    | Highlight
+        from = 11
+        to = 16
+        offset = 4
+        width = 35
+
+    | Highlight
+        from = 19
+        to = 19
+        offset = 0
+        width = 10
+
+    | Highlight
+        from = 20
+        to = 20
+        offset = 15
+        width = 10
=
=Notice that the {Code|view} takes an argument called {Code|age} and passes it to the first (brown) segment. The value of {Code|age} is our state. In some programs the type of state can be very complex, but in our program it's simply a {Code|Float} number. It will indicate how much time in milliseconds have passed from the start of the program. Because the time is counted in milliseconds, to get correct results we need to divide it by 5000 (so the tree will grows one generation of segments per five second).
=
@@ -217,9 +236,16 @@ First value is more important. This is the initial age of the tree, right after
=
=That's our init:
=
-| Code
-    init () =
-        ( 0, Cmd.none )
+| Editor
+    | Code
+        init () =
+            ( 0, Cmd.none )
+
+    | Highlight
+        from = 0
+        to = 0
+        offset = 0
+        width = 10
=
=Time for the {Code|update} function. It will get two arguments: an incoming message and the current state. Incoming message will always be a duration of time since previous frame, so let's simply call it {Code|duration}. The state is the current age of the tree, so again we can call it {Code|age}. In return we must produce a tuple with:
=
@@ -229,11 +255,18 @@ Time for the {Code|update} function. It will get two arguments: an incoming mess
=
=It looks like this:
=
-| Code
-    update duration age =
-        ( age + duration
-        , Cmd.none
-        )
+| Editor
+    | Code
+        update duration age =
+            ( age + duration
+            , Cmd.none
+            )
+
+    | Highlight
+        from = 0
+        to = 0
+        offset = 0
+        width = 10
=
=Finally let's subscribe to the events marking the passage of time. We can do it using {Code|Browser.Events.onAnimationFrameDelta}. Here is how it works. Whenever the browser is ready for the next frame it will send us a message containing the number of milliseconds that have passed since previous frame.
=
@@ -244,141 +277,156 @@ To use it we first need to import the {Code|Browser.Events} module. The {Code|Br
=
=The whole {Code|subscriptions} looks like that:
=
-| Code
-    subscriptions age =
-        Browser.Events.onAnimationFrameDelta identity
+| Editor
+    | Code
+        subscriptions age =
+            Browser.Events.onAnimationFrameDelta identity
+
+    | Highlight
+        from = 0
+        to = 0
+        offset = 0
+        width = 10
=
=And the complete code like this:
=
-| Code
-    module Main exposing (main)
+| Editor
+    | Code
+        module Main exposing (main)
=
-    import Browser
-    import Browser.Events
-    import Dict
-    import Element
-    import Svg exposing (Svg)
-    import Svg.Attributes
+        import Browser
+        import Browser.Events
+        import Dict
+        import Element
+        import Svg exposing (Svg)
+        import Svg.Attributes
=
=
-    main =
-        Browser.element
-            { init = init
-            , view = view
-            , update = update
-            , subscriptions = subscriptions
-            }
+        main =
+            Browser.element
+                { init = init
+                , view = view
+                , update = update
+                , subscriptions = subscriptions
+                }
=
=
-    init () =
-        ( 0, Cmd.none )
+        init () =
+            ( 0, Cmd.none )
=
=
-    view age =
-        [ segment (age / 5000) { color = "brown", rotation = -90 } ]
-            |> Svg.svg
-                [ Svg.Attributes.height "100%"
-                , Svg.Attributes.width "100%"
-                , Svg.Attributes.style "background: none"
-                , Svg.Attributes.viewBox "-500 -500 1000 1000"
-                ]
-            |> Element.html
-            |> Element.layout
-                [ Element.width Element.fill
-                , Element.height Element.fill
-                ]
+        view age =
+            [ segment (age / 5000) { color = "brown", rotation = -90 } ]
+                |> Svg.svg
+                    [ Svg.Attributes.height "100%"
+                    , Svg.Attributes.width "100%"
+                    , Svg.Attributes.style "background: none"
+                    , Svg.Attributes.viewBox "-500 -500 1000 1000"
+                    ]
+                |> Element.html
+                |> Element.layout
+                    [ Element.width Element.fill
+                    , Element.height Element.fill
+                    ]
=
=
-    update duration age =
-        ( duration
-            |> Debug.log "Duration"
-            |> (+) age
-            |> Debug.log "Age"
-        , Cmd.none
-        )
+        update duration age =
+            ( duration
+                |> Debug.log "Duration"
+                |> (+) age
+                |> Debug.log "Age"
+            , Cmd.none
+            )
=
=
-    subscriptions age =
-        Browser.Events.onAnimationFrameDelta identity
+        subscriptions age =
+            Browser.Events.onAnimationFrameDelta identity
=
=
-    rules =
-        Dict.empty
-            |> Dict.insert "brown"
-                [ { color = "brown", rotation = 0 }
-                , { color = "green", rotation = 20 }
-                , { color = "green", rotation = -30 }
-                ]
-            |> Dict.insert "green"
-                [ { color = "red", rotation = -45 }
-                , { color = "red", rotation = -5 }
-                , { color = "red", rotation = 50 }
-                ]
+        rules =
+            Dict.empty
+                |> Dict.insert "brown"
+                    [ { color = "brown", rotation = 0 }
+                    , { color = "green", rotation = 20 }
+                    , { color = "green", rotation = -30 }
+                    ]
+                |> Dict.insert "green"
+                    [ { color = "red", rotation = -45 }
+                    , { color = "red", rotation = -5 }
+                    , { color = "red", rotation = 50 }
+                    ]
+
+
+        segment age { color, rotation } =
+            if age <= 0 then
+                Svg.g [] []
+
+            else
+                Svg.g []
+                    [ rules
+                        |> Dict.get color
+                        |> Maybe.withDefault []
+                        |> List.map (segment (age - 1))
+                        |> Svg.g
+                            [ Svg.Attributes.transform
+                                (String.concat
+                                    [ "rotate("
+                                    , String.fromFloat rotation
+                                    , ") translate("
+                                    , String.fromFloat (age * 10)
+                                    , ")"
+                                    ]
+                                )
+                            ]
+                    , dot age color rotation
+                    , line age color rotation
+                    ]
=
=
-    segment age { color, rotation } =
-        if age <= 0 then
-            Svg.g [] []
-
-        else
-            Svg.g []
-                [ rules
-                    |> Dict.get color
-                    |> Maybe.withDefault []
-                    |> List.map (segment (age - 1))
-                    |> Svg.g
-                        [ Svg.Attributes.transform
-                            (String.concat
-                                [ "rotate("
-                                , String.fromFloat rotation
-                                , ") translate("
-                                , String.fromFloat (age * 10)
-                                , ")"
-                                ]
-                            )
+        dot age color rotation =
+            Svg.circle
+                [ Svg.Attributes.r (String.fromFloat age)
+                , Svg.Attributes.cx "0"
+                , Svg.Attributes.cy "0"
+                , Svg.Attributes.fill color
+                , Svg.Attributes.transform
+                    (String.concat
+                        [ "rotate("
+                        , String.fromFloat rotation
+                        , ") translate("
+                        , String.fromFloat (age * 10)
+                        , ")"
=                        ]
-                , dot age color rotation
-                , line age color rotation
+                    )
=                ]
+                []
+
+
+        line age color rotation =
+            Svg.line
+                [ Svg.Attributes.strokeWidth "1"
+                , Svg.Attributes.x1 "0"
+                , Svg.Attributes.y1 "0"
+                , Svg.Attributes.x1 (String.fromFloat (age * 10))
+                , Svg.Attributes.y1 "0"
+                , Svg.Attributes.stroke color
+                , Svg.Attributes.strokeWidth (String.fromFloat age)
+                , Svg.Attributes.transform
+                    (String.concat
+                        [ "rotate("
+                        , String.fromFloat rotation
+                        , ")"
+                        ]
+                    )
+                ]
+                []
=
+    | Highlight
+        from = 0
+        to = 0
+        offset = 0
+        width = 10
=
-    dot age color rotation =
-        Svg.circle
-            [ Svg.Attributes.r (String.fromFloat age)
-            , Svg.Attributes.cx "0"
-            , Svg.Attributes.cy "0"
-            , Svg.Attributes.fill color
-            , Svg.Attributes.transform
-                (String.concat
-                    [ "rotate("
-                    , String.fromFloat rotation
-                    , ") translate("
-                    , String.fromFloat (age * 10)
-                    , ")"
-                    ]
-                )
-            ]
-            []
-
-
-    line age color rotation =
-        Svg.line
-            [ Svg.Attributes.strokeWidth "1"
-            , Svg.Attributes.x1 "0"
-            , Svg.Attributes.y1 "0"
-            , Svg.Attributes.x1 (String.fromFloat (age * 10))
-            , Svg.Attributes.y1 "0"
-            , Svg.Attributes.stroke color
-            , Svg.Attributes.strokeWidth (String.fromFloat age)
-            , Svg.Attributes.transform
-                (String.concat
-                    [ "rotate("
-                    , String.fromFloat rotation
-                    , ")"
-                    ]
-                )
-            ]
-            []
=
=| Emphasize
=    That's it!