Skip to content

Instantly share code, notes, and snippets.

@jamesmacaulay
Last active April 18, 2022 11:23
Show Gist options
  • Save jamesmacaulay/048ecc7b789524e84b37 to your computer and use it in GitHub Desktop.
Save jamesmacaulay/048ecc7b789524e84b37 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 : Float -> Color -> (Float, Float) -> Form
lambdaForm scaleFactor color pos =
Text.fromString "𝝀"
|> Text.color color
|> text
|> scale scaleFactor
|> move pos
colors : List Color
colors =
[purple, blue, green, yellow, orange, red]
|> List.map (List.repeat 12)
|> List.concat
animatedColors : List (List Color)
animatedColors =
let step _ colorLists =
case colorLists of
(head :: tail) :: _ -> (tail ++ [head]) :: 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 : (Float, Float) -> Float -> Float -> List (Float, Float)
positions start diffX diffY =
let step _ xs =
case xs of
(x,y) :: _ -> (x + diffX, y - diffY) :: xs
[] -> []
in
List.foldr step [start] colors
model : List (List Color)
model = animatedColors
update : Float -> List (List Color) -> List (List Color)
update _ remainingFrames =
case remainingFrames of
[] -> animatedColors
_ :: [] -> animatedColors
_ :: tail -> tail
viewFrame : List Color -> Element
viewFrame colors =
let lambdaView = lambdaForm 30
lambdas = List.map2 lambdaView
colors
(positions (-62,90) 1.5 0.75)
background = (rect 400 400 |> filled lightGrey)
in
collage 400 400 (background :: lambdas)
view : List (List Color) -> Element
view remainingFrames =
remainingFrames |> List.head |> Maybe.withDefault [] |> viewFrame
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