Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Created November 1, 2017 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitaibu/0ac0a4d98785ba52822995d65e239a74 to your computer and use it in GitHub Desktop.
Save amitaibu/0ac0a4d98785ba52822995d65e239a74 to your computer and use it in GitHub Desktop.
Rockets
module Main exposing (..)
type alias Rocket =
{}
type alias Point =
{ x : Int, y : Int }
{-| This is holding the current points, and the
previous/ first one.
-}
type alias PointDict =
Dict Int Point
{-| Random dict of points, for the 1st generation.
-}
initDict : PointDict
initDict =
[ ( 1, Point 1 1 )
, ( 2, Point 2 2 )
, ( 3, Point 3 3 )
]
|> Dict.fromList
calcPoints : PointDict -> PointDict
calcPoints pointDict =
Dict.map calcPoint pointDict
calcPoint : Point -> Point
calcPoint point =
{ x = point.x + 1, y = point.y + 1 }
main =
-- Get the first generation executed.
{ generation = calcPoints initDict
, currentStep = 1
}
type alias Model =
{ generation : PointDict
, currentStep : Int
}
update : Msg -> Model -> Model
update msg model =
case msg of
Tick time ->
let
currentStep =
model.currentStep + 1
in
if Dict.length model.generation > currentStep then
{ model | currentStep = currentStep }
else
{ model
| generation = calcPoints model.generation
, currentStep = 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment