Created
November 1, 2017 19:15
-
-
Save amitaibu/0ac0a4d98785ba52822995d65e239a74 to your computer and use it in GitHub Desktop.
Rockets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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