Created
August 18, 2013 14:54
-
-
Save chribben/6262042 to your computer and use it in GitHub Desktop.
MoveableAndClickableBouncingFruit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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