Skip to content

Instantly share code, notes, and snippets.

@xgrommx
Forked from jamesmacaulay/rainbow-lambda.elm
Created November 9, 2015 01:56
Show Gist options
  • Save xgrommx/615952d6d198b4a8fab3 to your computer and use it in GitHub Desktop.
Save xgrommx/615952d6d198b4a8fab3 to your computer and use it in GitHub Desktop.
-- paste into http://elm-lang.org/try and click "compile"
-- http://imgur.com/gallery/W6TwgZw
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Text
import Color exposing (..)
import Time
import Signal
lambdaForm scaleFactor color pos =
Text.fromString "𝝀"
|> Text.color color
|> text
|> scale scaleFactor
|> move pos
colors =
[purple, blue, green, yellow, orange, red]
|> List.map (List.repeat 12)
|> List.concat
animatedColors =
let step _ colorLists =
case colorLists of
(color::colors)::_ -> (colors ++ [color]) :: colorLists
[] -> []
in
List.foldr step [colors] colors
|> List.map (\xs -> xs ++ [lightOrange])
|> List.reverse
|> List.indexedMap (\i x -> if i % 2 == 0 then Just x else Nothing)
|> List.filterMap identity
positions start diffX diffY =
let step _ xs =
case xs of
(x,y) :: _ -> (x + diffX, y - diffY) :: xs
[] -> []
in
List.foldr step [start] colors
model = animatedColors
update _ remainingFrames =
case remainingFrames of
[_] -> animatedColors
[] -> animatedColors
_::tl -> tl
view remainingFrames =
let colors = remainingFrames |> List.head |> Maybe.withDefault []
in
(rect 400 400 |> filled lightGrey)
:: List.map2 (lambdaForm 30) colors (positions (-62,90) 1.5 0.75)
|> collage 400 400
main : Signal Element
main =
Time.fps 24 |> Signal.foldp update model |> Signal.map view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment