Last active
October 14, 2015 07:33
-
-
Save deflexor/91764a87ce1b1fdbaa2c to your computer and use it in GitHub Desktop.
Elm-lang app that needs speed boost
This file contains hidden or 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
import Html exposing (..) | |
import Debug exposing (..) | |
import Array exposing (Array, repeat, set, get, toList, initialize) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (on, onClick, targetChecked) | |
import Signal exposing (Address) | |
import StartApp.Simple as StartApp | |
main = | |
StartApp.start { model = initialModel, view = view, update = update } | |
-- MODEL | |
type alias Model = Array Bool | |
w = 400 | |
h = 400 | |
initialModel = repeat (w * h) False | |
-- UPDATE | |
type Action | |
= Hi Int | |
update action model = | |
case action of | |
Hi i -> | |
let newval = if (get i model) == Just True then False else True | |
in | |
set i newval model | |
-- VIEW | |
view address model = | |
table [ style [("border-collapse", "collapse")] ] (toList (initialize h (\row -> | |
tr [] (toList (initialize w (\col -> | |
let i = w*row+col | |
bg = if (get i model)== Just True then "blue" else "white" | |
in | |
td [ onClick address (Hi i), style [("background", bg)] ] [ text "*" ] | |
))) | |
))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment