Last active
January 16, 2016 12:49
-
-
Save netzwerg/52aab6987cd57eb721a8 to your computer and use it in GitHub Desktop.
Demonstrates scanl to paste into http://www.elm-lang.org/try
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
import Color exposing (..) | |
import Graphics.Collage exposing (..) | |
import Graphics.Element | |
import Debug exposing (..) | |
type alias Rect = { width: Float, color: Color } | |
toForm : (Rect, Float) -> Form | |
toForm (r, offset) = | |
filled r.color (rect r.width 100) | |
|> alpha 0.8 | |
|> moveX (r.width / 2) | |
|> moveX offset | |
main = | |
let | |
rects = [ Rect 20 yellow, Rect 100 lightGreen, Rect 20 lightBlue ] | |
widths = List.map (\r -> r.width) rects | |
offsets = List.scanl (+) 0 widths | |
rectsWithOffsets = List.map2 (,) rects offsets | |
in | |
collage 400 400 (List.map toForm rectsWithOffsets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment