You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.4 KiB
67 lines
1.4 KiB
import Grid exposing (..)
|
|
import RingList exposing (..)
|
|
|
|
import Html exposing (..)
|
|
import Html.Attributes exposing (..)
|
|
import Html.App as App
|
|
import Html.Events exposing (..)
|
|
import Random
|
|
import Color exposing (..)
|
|
import Time exposing (Time, second)
|
|
|
|
|
|
main =
|
|
App.program
|
|
{ init = init
|
|
, view = view
|
|
, update = update
|
|
, subscriptions = subscriptions
|
|
}
|
|
|
|
width = 21
|
|
height = 16
|
|
|
|
-- MODEL
|
|
|
|
type alias World = Grid (Int, Float)
|
|
type alias Model =
|
|
{ grid : World
|
|
, history : List (Int, Float)
|
|
}
|
|
|
|
init : (Model, Cmd Msg)
|
|
init = (Model (Grid.generate width height (\x y -> (x, toFloat y))) [], Cmd.none)
|
|
|
|
|
|
-- UPDATE
|
|
|
|
type Msg
|
|
= Update World
|
|
|
|
succ (n, m) = (n + 1, m * 2)
|
|
|
|
update : Msg -> Model -> (Model, Cmd Msg)
|
|
update msg model =
|
|
case msg of
|
|
Update grid -> (Model grid (Grid.extract grid :: model.history), Cmd.none)
|
|
|
|
|
|
-- SUBSCRIPTIONS
|
|
|
|
subscriptions : Model -> Sub Msg
|
|
subscriptions model = Sub.none
|
|
|
|
|
|
-- VIEW
|
|
|
|
butt : World -> Html Msg
|
|
--butt rl = button [ onClick (Update (RingList.edit succ rl)) ] [ RingList.extract rl |> toString |> text ]
|
|
butt grid = button [ onClick (Update (Grid.edit succ grid)) ] [ Grid.extract grid |> toString |> text ]
|
|
|
|
view : Model -> Html Msg
|
|
view model = let
|
|
dupmodel = Grid.duplicate model.grid
|
|
butts = Grid.map butt dupmodel
|
|
listm = Grid.toList butts
|
|
viewm = List.map (\row -> div [] (br [] [] :: row)) listm
|
|
in div [] <| viewm ++ [div [] [model.history |> toString |> text]]
|
|
|