Skip to content

Commit

Permalink
add toggle for entropy display
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Jan 10, 2020
1 parent 0b68f93 commit 633c5c1
Showing 1 changed file with 71 additions and 112 deletions.
183 changes: 71 additions & 112 deletions src/Main.elm
Expand Up @@ -33,6 +33,7 @@ type alias Model =
, indexes : Dict Int Image
, weights : Dict Int Int
, rules : Adjacency.Rules Int
, showEntropy : Bool
}


Expand All @@ -41,6 +42,7 @@ type Msg
| Start
| Stop
| Step
| ToggleEntropy


init : () -> ( Model, Cmd Msg )
Expand Down Expand Up @@ -119,6 +121,7 @@ init _ =
, indexes = indexes
, weights = weights
, rules = rules
, showEntropy = False
}
, Cmd.none
)
Expand Down Expand Up @@ -154,6 +157,9 @@ update msg model =
Stop ->
( { model | running = False }, Cmd.none )

ToggleEntropy ->
( { model | showEntropy = not model.showEntropy }, Cmd.none )


main : Program () Model Msg
main =
Expand Down Expand Up @@ -209,6 +215,7 @@ view model =
, Html.button [ Events.onClick (Reset { width = 10, height = 10 }) ] [ Html.text "Reset (10x10)" ]
, Html.button [ Events.onClick (Reset { width = 20, height = 20 }) ] [ Html.text "Reset (20x20)" ]
, Html.button [ Events.onClick (Reset { width = 50, height = 50 }) ] [ Html.text "Reset (50x50)" ]
, Html.button [ Events.onClick ToggleEntropy ] [ Html.text "Toggle Entropy (debug)" ]
, Wave.view
(\indexes ->
let
Expand Down Expand Up @@ -257,119 +264,71 @@ view model =
)
)
model.wave
, if model.showEntropy then
let
entropies =
Wave.getEntropy model.wave
in
Html.div []
[ Html.text "Entropy Info"
, Html.p []
[ Html.text "Next: "
, case Heap.peek entropies of
Nothing ->
Html.text "Nothing"

Just { coords, entropy } ->
Html.span []
[ Html.text (String.fromInt entropy)
, Html.text " @ "
, Html.text (String.fromInt coords.row)
, Html.text ","
, Html.text (String.fromInt coords.column)
]
]
, Html.p []
[ Html.text "Total: "
, Html.text (String.fromInt (Heap.size entropies))
]
, entropies
|> Heap.toList
|> List.foldl
(\new grid ->
Grid.update
(\maybeExisting ->
case maybeExisting of
Nothing ->
Just new

Just existing ->
if existing.entropy < new.entropy then
Just existing

else
Just new
)
{ row = new.coords.row, column = new.coords.column }
grid
)
(Grid.initialize
{ rows = model.waveSize.height
, columns = model.waveSize.width
}
(always Nothing)
)
|> Grid.view
(\value ->
Html.td [ css [ Css.padding (Css.px 2) ] ]
[ value
|> Maybe.map (String.fromInt << .entropy)
|> Maybe.withDefault "-"
|> Html.text
]
)
]

-- , Html.div [ css [ Css.displayFlex, Css.justifyContent Css.spaceAround ] ]
-- [ let
-- entropies =
-- Wave.getEntropy model.wave
-- in
-- Html.div []
-- [ Html.text "Entropy Info"
-- , Html.p []
-- [ Html.text "Next: "
-- , case Heap.peek entropies of
-- Nothing ->
-- Html.text "Nothing"
-- Just { coords, entropy } ->
-- Html.span []
-- [ Html.text (String.fromInt entropy)
-- , Html.text " @ "
-- , Html.text (String.fromInt coords.row)
-- , Html.text ","
-- , Html.text (String.fromInt coords.column)
-- ]
-- ]
-- , Html.p []
-- [ Html.text "Total: "
-- , Html.text (String.fromInt (Heap.size entropies))
-- ]
-- , entropies
-- |> Heap.toList
-- |> List.foldl
-- (\new grid ->
-- Grid.update
-- (\maybeExisting ->
-- case maybeExisting of
-- Nothing ->
-- Just new
-- Just existing ->
-- if existing.entropy < new.entropy then
-- Just existing
-- else
-- Just new
-- )
-- { row = new.coords.row, column = new.coords.column }
-- grid
-- )
-- (Grid.initialize
-- { rows = model.waveSize.height
-- , columns = model.waveSize.width
-- }
-- (always Nothing)
-- )
-- |> Grid.view
-- (\value ->
-- Html.td [ css [ Css.padding (Css.px 2) ] ]
-- [ value
-- |> Maybe.map (String.fromInt << .entropy)
-- |> Maybe.withDefault "-"
-- |> Html.text
-- ]
-- )
-- ]
-- , Html.div []
-- [ Html.text "Rules"
-- , Wave.getRules model.wave
-- |> Adjacency.toList
-- |> List.sortBy
-- (\{ from, offsetRows, offsetColumns } ->
-- ( Color.toRGBAString from
-- , offsetRows
-- , offsetColumns
-- )
-- )
-- |> List.map
-- (\{ from, to, offsetRows, offsetColumns } ->
-- let
-- viewColor color =
-- Html.div
-- [ style "background-color" (Color.toRGBAString color)
-- , css [ Css.width (Css.px 10), Css.height (Css.px 10) ]
-- ]
-- []
-- in
-- Html.tr []
-- [ Html.td
-- [ css [ Css.float Css.right ] ]
-- [ viewColor from ]
-- , Html.td
-- [ css [ Css.textAlign Css.right ] ]
-- [ Html.text (String.fromInt offsetRows) ]
-- , Html.td
-- [ css [ Css.textAlign Css.right ] ]
-- [ Html.text (String.fromInt offsetColumns) ]
-- , Html.td [ css [ Css.displayFlex ] ]
-- (Set.toList to
-- |> List.map viewColor
-- )
-- ]
-- )
-- |> (::)
-- (Html.tr []
-- [ Html.th [] [ Html.text "From" ]
-- , Html.th [] [ Html.text "↓" ]
-- , Html.th [] [ Html.text "→" ]
-- , Html.th [] [ Html.text "Allow" ]
-- ]
-- )
-- |> Html.table
-- [ css
-- [ Css.borderSpacing (Css.px 3)
-- , Css.borderCollapse Css.separate
-- ]
-- ]
-- ]
-- ]
else
Html.text ""
]


Expand Down

0 comments on commit 633c5c1

Please sign in to comment.