This is a rough file with all the features implemented so far and comments on them and in no way an end-product documentation. This document is intended for the developers. This will eventually be replaced by clean documentation (for kids! :D) Ideas: Start off building a 2D physics simulator using Box2D. Continuously keep porting parts of Box2D to scheme code, (performance problems here! :/) We can fallback to box2D wherever performance becomes an issue. Should the examples start off at a high level? I think yes, that would be interesting, then if the user is interested, he could look at the lover levels of abstractions. That's how everyone learns to code. This method gives better feedback to the user in the beginning stages. Implemented Functions: 1. add-body (adds a body to the world) 2. remove-body (removes a body of given id from the world) 3. alert (invokes alert) 4. on (adds an event handler) when the 1st argument happens, procedure passed as second argument is executed (adds the event handler to the event) Supported handlers : -> 'mouseup: e.g : (on 'mouseup (lambda (x y) (remove (body-at (vector2 x y))))) -> 'mousedown -> 'mousemove : e.g : (on 'mousemove (lambda (x y) (apply-impulse (body-at (vector2 x-before y-before) (vector2 (- x-after x-before) (- y-after y-after)))"))) ;;applies an impulse proportional to extent of mouse movement -> 'mouseover -> 'mouseout -> 'keydown : e.g : (on 'keydown (lambda (code) (if (= key-down 65) (apply-impulse "id3" (vector2 50.0 50.0))))) -> 'keyup Complex example: drag (not primitive, but can be implemented) e.g : (define (add-drag-handler handler) (define (start-drag) (on 'mousemove handler)) (define (stop-drag) (~on 'mousemove handler)) (on 'mousedown start-drag) (on 'mouseup stop-drag) (on 'mouseout stop-drag)) 5. ~on (removes event handler(s) , undoes 'on') Can be used in two ways: 1. Remove all handlers of an event (~on 'mouseup) 2. Remove one specific handler of an event (on 'mouseup foo) (~on 'mouseup foo) For this to work you must have a reference to the callback procedure. This means you can't use lambdas as handlers if you want to later remove them. 6. handler-data (returns a list of all handlers of event(s)) 7. change-bg-color (changes the background color) 8. change-body-color (changes a body's color) 9. random (returns a random number) 10. apply-impulse (apply impulse and change the momentum of a body) e.g : (apply-impulse "id3" (vector2 10.0 150.0)) 11. apply-force (apply force for a required period of time on a body) e.g : (apply-force "id3" (vector2 1000.0 150.0) 5000) -> applies force for 5000 ms (Body information returning functions : ) 12. body-com (center of mass position of a body) 13. body-angle (angle of a body) 14. body-vertices (vertices of a body (as was initiialized)) 15. body-linear-velocity (velocity of a body) 16. body-attributes (attributes (density, friction, restitution) of a body) 17. body-color (color of a body) 18. set-gravity (set the gravity of a world) 19. body-at (id of the body at the specified coordinates) Global Variables : 1. body-count (number of bodies in the world) 2. body-list (list of ids of all bodies in defined in the world) 3. canvas-width & canvas-height (dimensions of the HTML5 canvas in pixels) Sample programs : 1. Change colors of all bodies to random colors when a mouseup occurs (define (change-all-colors) (define (helper b-list) (if (not (null? b-list)) (begin (change-body-color (car b-list) (color (random) (random) (random))) (helper (cdr b-list))))) (helper body-list)) (on 'mouseup (lambda (x y) (change-all-colors))) 2. Move a body around, with WASD keys (define (jump code) (define id "id2") (cond ((= code 65) (apply-impulse id (vector2 -500 0))) ((= code 68) (apply-impulse id (vector2 500 0))) ((= code 87) (apply-impulse id (vector2 0 500))) ((= code 83) (apply-impulse id (vector2 0 -500))) )) (on 'keydown jump) 3. Repeatedly shoot bullets every second ;;generates an id (define (gen-id) (string-concat (list "id" (+ body-count 1)))) (define (shoot-bullet) (define b-shape (rect-shape 10.0 10.0)) (define b-attribs (attributes 1.0 0.5 0.3)) (define b-position (vector2 50.0 400.0)) (define b-color (color 0.3 0.4 0.65)) (define b-angle 0.0) (define id (gen-id)) (begin (add-body dynamic b-shape b-position b-angle b-attribs b-color id) (apply-impulse id (vector2 300 -500)) (sleep 1) (shoot-bullet))) (shoot-bullet) 4. Create a drag and throw effect on bodies (define (add-drag-handler handler) (define x-before 0) (define y-before 0) (define (handler-wrapper x y) (handler x-before y-before x y) (set! x-before x) (set! y-before y)) (define (start-drag x y) (set! x-before x) (set! y-before y) (on 'mousemove handler-wrapper)) (define (stop-drag x y) (~on 'mousemove handler-wrapper)) (on 'mousedown start-drag) (on 'mouseup stop-drag) (on 'mouseout stop-drag)) (add-drag-handler (lambda (x-before y-before x-after y-after) (apply-impulse (body-at (vector2 x-before y-before)) (vector2 (* 50 (- x-after x-before)) (* 300 (- y-after y-before))))))