Last active
August 29, 2015 14:05
-
-
Save nebuta/804a0ae92f21a38afd26 to your computer and use it in GitHub Desktop.
Bouncing ball
This file contains hidden or 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
main = lift scene state | |
state = foldp step initial (fps 60) | |
initial = State 0 -70 100 8 0 | |
data State = State Float Float Float Float Float | |
scene (State t x y vx vy) = collage 400 400 [box, ball x y] | |
box = filled (hsl (pi/2) 0.5 0.5) | |
<| path [ (-90,100), (-100,100), (-100,-50),(100,-50), | |
(100,100), (90,100), (90,-40), (-90,-40), (-90,50)] | |
ball x y = move (x,y) | |
<| filled (hsl 0 0.5 0.5) | |
<| circle 10 | |
step _ (State t x y vx vy) = | |
let vy2 = if y < -27 then -vy*0.95 else vy-0.2 | |
vx2 = (if x < -80 then -vx else | |
(if x >=80 then -vx else vx)) * (if y < -27 then 0.8 else 1) | |
in State t (x+vx2) (y+vy2) vx2 vy2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment