Created
December 30, 2016 00:16
-
-
Save Chadtech/f2f5f1d714eea51a8a0b687b93110b15 to your computer and use it in GitHub Desktop.
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 (p, text, div, canvas, Html) | |
| import Html.Attributes exposing (id, style) | |
| import Html.Events exposing (..) | |
| import List exposing (repeat, concat) | |
| import Array exposing (Array, fromList) | |
| import Color exposing (rgb, Color) | |
| import Debug exposing (log) | |
| main = | |
| Html.program | |
| { init = (model, Cmd.none) | |
| , view = view | |
| , update = update | |
| , subscriptions = always Sub.none | |
| } | |
| -- MODEL | |
| type alias Canvas = | |
| { id : String | |
| , imageData : ImageData | |
| } | |
| type alias ImageData = | |
| { width : Int | |
| , height : Int | |
| , data : Array Int | |
| } | |
| type alias Model = Canvas | |
| type Msg | |
| = Draw | |
| model : Canvas | |
| model = | |
| let | |
| width = 500 | |
| height = 400 | |
| in | |
| { id = "the-canvas" | |
| , imageData = | |
| { width = width | |
| , height = height | |
| , data = | |
| black | |
| |>repeat (width * height) | |
| |>concat | |
| |>fromList | |
| } | |
| } | |
| black : List Int | |
| black = | |
| [ 0, 0, 0, 255 ] | |
| prettyBlue : Color | |
| prettyBlue = | |
| rgb 23 92 254 | |
| -- UPDATE | |
| update : Msg -> Model -> (Model, Cmd Msg) | |
| update message canvas = | |
| case message of | |
| Draw -> | |
| let _ = log "draw" "draw" in | |
| (canvas, Cmd.none) | |
| -- VIEW | |
| view : Model -> Html Msg | |
| view canvas = | |
| div | |
| [] | |
| [ p [] [ text "v--- stack overflow if you click there :^(" ] | |
| , Html.canvas [ onMouseDown Draw ] [] | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment