Skip to content

Instantly share code, notes, and snippets.

@pulcheri
Created February 17, 2016 16:06
Show Gist options
  • Save pulcheri/e7a43e4ac8ad9630a44f to your computer and use it in GitHub Desktop.
Save pulcheri/e7a43e4ac8ad9630a44f to your computer and use it in GitHub Desktop.
import Random
import Mouse
import Graphics.Collage exposing (toForm, move, collage)
import Graphics.Element exposing (show)
import List exposing (..)
import Time
type Fruit = Apple | Orange | Banana | Melon | Guava
-- For module global declarations, it is often helpful to
-- explicitly annotate the types.
fruits : List Fruit
fruits = [Apple, Orange, Banana, Melon, Guava]
-- especially for functions :)
fruit : Int -> Fruit
fruit n = Maybe.withDefault Apple <| head <| drop n fruits
type alias RandModel = (Int, Random.Seed)
rr2 : RandModel -> RandModel
rr2 m = Random.generate
(Random.int 0 (length fruits - 1))
(snd m)
rand : Signal Int
rand = Signal.map fst <| Signal.foldp (always rr2) (0, Random.initialSeed 0) Mouse.clicks
fruitText : Signal Graphics.Collage.Form
fruitText = Signal.map (toForm << show << fruit ) rand
time = Signal.map
(Time.inSeconds << fst)
(Time.timestamp (Time.fps 40))
scene dy form = Graphics.Collage.collage 300 300 [move (0, 100 * cos dy) form]
main = Signal.map2 scene time fruitText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment