Skip to content

Instantly share code, notes, and snippets.

@chribben
Created August 18, 2013 14:54
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 chribben/6262042 to your computer and use it in GitHub Desktop.
Save chribben/6262042 to your computer and use it in GitHub Desktop.
MoveableAndClickableBouncingFruit
import Random
import Mouse
import Keyboard
data Fruit = Apple | Orange | Banana | Melon | Guava
rand = Random.range 0 4 (Mouse.clicks)
fruit n = if | n == 0 -> Apple
| n == 1 -> Orange
| n == 2 -> Banana
| n == 3 -> Melon
| otherwise -> Guava
fruitText = toForm <~ (asText <~ (fruit <~ rand))
time = lift (inSeconds . fst) (timestamp (fps 40))
pos = Keyboard.arrows
signalX p = lift (\p -> p.x) p
accX = (foldp (\x xp -> x + xp) 0) (signalX pos)
scene dx dy form = collage 300 300 [move (toFloat dx * 7, 100 * cos dy) form]
main = lift3 scene accX time fruitText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment