Touch and accelerometer functionality available fo

posted in Programmology
Published July 20, 2009
Advertisement
Posted from http://jlongster.com/blog/:

--------------------------------------------

Touch and accelerometer functionality available for Scheme on the iPhone

July 20, 2009



I have finished the Gambit Scheme libraries for touch and accelerometer support. The green smudge was produced by my fingers, and the orange smudge was produced by tilting the phone.

I've introduced a basic events system. To capture a an event, you define an event handler using DEFINE-EVENT-HANDLER. Currently, the only events implemented are "touches-began", "touches-moved", "touches-ended", "touched-cancelled", and "did-accelerate". The arguments of the event are the same as they would be in Objective-C.

Here's an example, taken from the application shown above:
    (define-event-handler (touches-began touches event)      (for-each (lambda (touch)                  (let ((loc (UITouch-location touch)))                    (add-point (car loc) (cdr loc))))                touches))        (define-event-handler (touches-moved touches event)      (for-each (lambda (touch)                  (let ((loc (UITouch-location touch)))                    (add-point (car loc) (cdr loc))))                touches))        (define-event-handler (did-accelerate device accel)      (define (shift n weight)        (+ n (* weight 70)))            (add-point (shift 150 (UIAcceleration-x accel))                 (shift 100 (- (UIAcceleration-y accel)))))

** Download **

I'm still polishing up a few things in these FFIs, but they are ready to use. Soon, I will create a separate github project for Gambit Scheme FFIs. For now, they are included in my gambit scheme on the iphone example project.

Specifically:

lib/ffi/osx.scm
lib/ffi/osx#.scm
lib/ffi/iphone.scm
lib/ffi/iphone#.scm
lib/events.scm

Don't forget to setup a few hooks in your Objective-C app, as seen here (accelerometer) and here (touch).

You can view this iphone application included in my github project as well for example usage.
0 likes 4 comments

Comments

Telastyn
I'd not seen the original post, but I'd just like to be one of the first to say that Scheme + iPhone is both cool and disgusting.
July 20, 2009 01:33 PM
okonomiyaki
Thanks, besides the disgusting part! If you are implying Scheme is disgusting, I would heartily beg to differ. It's the only language that keeps me sane.
July 20, 2009 02:47 PM
Telastyn
Quote:Original post by okonomiyaki
Thanks, besides the disgusting part! If you are implying Scheme is disgusting, I would heartily beg to differ. It's the only language that keeps me sane.


I would assume so, since you're using scheme and all. But yes, I do find pretty much anything in the Lisp branch of the evolutionary tree to be rather distasteful (albeit conceptually elegant).
July 20, 2009 03:13 PM
okonomiyaki
Quote:Original post by Telastyn
Quote:Original post by okonomiyaki
Thanks, besides the disgusting part! If you are implying Scheme is disgusting, I would heartily beg to differ. It's the only language that keeps me sane.


I would assume so, since you're using scheme and all. But yes, I do find pretty much anything in the Lisp branch of the evolutionary tree to be rather distasteful (albeit conceptually elegant).


I respect that. I think you have a fair point. There are two main things which remove it's ugliness:

* After using it for a while, you really do stop seeing the parenthesis. And, to stimulate that even more, your code editor should be able to use a gray-ish font on the parenthesis, so they literally are barely noticeable.

* Gambit Scheme has an infix syntactic extension (see documentation), so you can avoid prefix notation when it truly is ugly, usually in mathematical formulas:


(define (calculate x y)
    \5+3-(sin(x)*cos(y)-6)/3.14;


Prefix notation has many benefits otherwise.

Also, paredit.el for Emacs makes editing Lisp code a dream. It's so hard for me to go back to editing code with ambiguous syntax.
July 20, 2009 03:29 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement