Skip to content

Instantly share code, notes, and snippets.

@netzwerg
Last active January 16, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netzwerg/52aab6987cd57eb721a8 to your computer and use it in GitHub Desktop.
Save netzwerg/52aab6987cd57eb721a8 to your computer and use it in GitHub Desktop.
Demonstrates scanl to paste into http://www.elm-lang.org/try
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