Permalink
Browse files

adding some examples

  • Loading branch information...
1 parent d4ecd2b commit 68277617ca6cd2cac4fef19450c032e64596f4a1 Danny Yoo committed Mar 30, 2011
Showing with 87 additions and 0 deletions.
  1. +48 −0 examples/falling-ball.rkt
  2. +4 −0 examples/make-falling-ball.rkt
  3. +4 −0 examples/make-sensors.rkt
  4. +31 −0 examples/sensors.rkt
View
@@ -0,0 +1,48 @@
+#lang planet dyoo/moby:3:9
+
+;; Simple falling ball example. A red ball falls down the screen
+;; until hitting the bottom.
+
+
+(printf "falling-ball.rkt\n")
+
+(define-struct world (radius y))
+
+
+;; The dimensions of the screen:
+(define WIDTH 320)
+(define HEIGHT 480)
+
+;; The radius of the red circle.
+(define RADIUS 15)
+
+;; The world is the distance from the top of the screen.
+(define INITIAL-WORLD (make-world RADIUS 0))
+
+;; tick: world -> world
+;; Moves the ball down.
+(define (tick w)
+ (make-world RADIUS (+ (world-y w) 5)))
+
+
+;; hits-floor?: world -> boolean
+;; Returns true when the distance reaches the screen height.
+(define (hits-floor? w)
+ (>= (world-y w) HEIGHT))
+
+;; We have some simple test cases.
+(check-expect (hits-floor? (make-world RADIUS 0)) false)
+(check-expect (hits-floor? (make-world RADIUS HEIGHT)) true)
+
+;; render: world -> scene
+;; Produces a scene with the circle at a height described by the world.
+(define (render w)
+ (place-image (circle RADIUS "solid" "red") (/ WIDTH 2) (world-y w)
+ (empty-scene WIDTH HEIGHT)))
+
+;; Start up a big bang, 15 frames a second.
+(check-expect (big-bang INITIAL-WORLD
+ (on-tick tick 1/15)
+ (to-draw render)
+ (stop-when hits-floor?))
+ (make-world 15 480))
@@ -0,0 +1,4 @@
+ #lang racket
+ (require (planet dyoo/moby:3:9))
+ (create-android-phone-package "falling-ball.rkt" "falling-ball.apk")
+
@@ -0,0 +1,4 @@
+ #lang racket
+ (require (planet dyoo/moby:3:9))
+ (create-android-phone-package "sensors.rkt" "sensors.apk")
+
View
@@ -0,0 +1,31 @@
+ #lang planet dyoo/moby:3:9
+ (require (planet dyoo/moby:3:9/phone/tilt))
+ (require (planet dyoo/moby:3:9/phone/location))
+
+ (define-struct gps (lat lng))
+ (define-struct tilt (a p r))
+ (define-struct accel (x y z))
+
+ (define-struct sensors (gps tilt accel))
+
+ (define (update-gps w lat lng)
+ (make-sensors (make-gps lat lng)
+ (sensors-tilt w)
+ (sensors-accel w)))
+
+ (define (update-tilt w a p r)
+ (make-sensors (sensors-gps w)
+ (make-tilt a p r)
+ (sensors-accel w)))
+
+ (define (update-accel w x y z)
+ (make-sensors (sensors-gps w)
+ (sensors-tilt w)
+ (make-accel x y z)))
+
+ (big-bang (make-sensors (make-gps "loading" "loading")
+ (make-tilt "loading" "loading" "loading")
+ (make-accel "loading" "loading" "loading"))
+ (on-location-change update-gps)
+ (on-tilt update-tilt)
+ (on-acceleration update-accel))

0 comments on commit 6827761

Please sign in to comment.