Skip to content

Commit

Permalink
render gray square
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Jan 7, 2020
1 parent 1669a22 commit 0b93ab8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
38 changes: 35 additions & 3 deletions src/Main.elm
@@ -1,13 +1,14 @@
module Main exposing (..)

import AssocSet as Set
import Browser
import Color.Transparent as Color
import Css
import Css.Reset as Reset
import Grid
import Html as RootHtml
import Html.Styled as Html exposing (Html)
import Html.Styled.Attributes exposing (css)
import Html.Styled.Attributes exposing (css, style)
import Image exposing (Image)
import Wave

Expand Down Expand Up @@ -94,8 +95,39 @@ main =
, recurse
|> Grid.windows { width = 3, height = 3 }
|> Wave.init { width = 20, height = 20 }
|> Debug.toString
|> Html.text
|> Wave.view
(\colors ->
let
{ reds, blues, greens, opacities } =
colors
|> Set.toList
|> List.filterMap (Grid.get { row = 0, column = 0 })
|> List.foldl
(\color soFar ->
let
rgba =
Color.toRGBA color
in
{ reds = rgba.red :: soFar.reds
, blues = rgba.blue :: soFar.blues
, greens = rgba.green :: soFar.greens
, opacities = Color.opacityToFloat rgba.alpha :: soFar.opacities
}
)
{ reds = [], greens = [], blues = [], opacities = [] }

average items =
List.sum items / toFloat (List.length items)
in
Image.viewColor
(Color.fromRGBA
{ red = average reds
, green = average greens
, blue = average blues
, alpha = Color.customOpacity (average opacities)
}
)
)
]


Expand Down
23 changes: 22 additions & 1 deletion src/Wave.elm
@@ -1,8 +1,12 @@
module Wave exposing (Wave, init)
module Wave exposing (Wave, init, view)

import Array exposing (Array)
import AssocSet as Set exposing (Set)
import Cell exposing (Cell)
import Css
import Grid exposing (Grid)
import Html.Styled as Html exposing (Html)
import Html.Styled.Attributes exposing (css)


type Wave a
Expand All @@ -27,3 +31,20 @@ init { width, height } windows =
-- becomes a library.
Err problem ->
Debug.todo (Debug.toString problem)


view : (Set a -> Html msg) -> Wave a -> Html msg
view viewItems (Wave { items }) =
Grid.view
(\cell ->
case Cell.state cell of
Cell.Blocked ->
Html.td [] [ Html.text "X" ]

Cell.Done item ->
viewItems (Set.singleton item)

Cell.Remaining remaining ->
Html.td [] [ viewItems remaining ]
)
items

0 comments on commit 0b93ab8

Please sign in to comment.