Sound and Animation
In order to play a sound on a unix machine you must give a call like this:
(exec "mpg123 mysoundfile.mp3 &")
where mysoundfile.mp3 is an mp3 that you have.
Note: please do not make this too large a file. (Your account cannot be too large).
If you want to animate your images you have to do it in an inconvenient, roundabout way. You must have
a bunch of pictures which are frames of an animation (as in a .gif, but not embedded in it; each frame must be a separate file). Here is some cool code to animate the
frames for you:
(define flicker
(lambda (picture-list tag speed)
(let* ((a 1)
(kill #f)
(func
(lambda (f)
(after speed (lambda ()
(set! a (remainder a (length picture-list)))
(set-image! tag (list-ref picture-list a))
(set! a (+ a 1))
(if (not kill)
(f f)))))))
(func func)
(lambda () (set! kill #t)))))
Note: You should have no idea why this works, and that is fine. Set! should be a mystery to
you and it should continue to be so. You call the function by giving it a list of paths of pictures like:
(define pic-list (list "gamesman/images/xicongreen.gif" "gamesman/images/xiconred.gif" "gamesman/images/xicongrey.gif"
"gamesman/images/xiconyellow.gif")) , the tag that you want to change the picture of, and the speed which
that it goes through pictures (in milliseconds).
The function call returns a procedure of no arguments that stops the animation when it is called.
Here are some example interactions:
(draw-image 100 100 "gamesman/images/xiconred.gif" 'tag 'bigx1)
(define stop1 (flicker pic-list 'bigx1 100))
(draw-image 300 300 "gamesman/images/xiconred.gif" 'tag 'bigx2)
(define stop2 (flicker pic-list 'bigx2 100))
;; Now Both are animated
(stop1)
;; The first has stoped being animated.
(stop2)
;; The second is now stopped.
Remember, any and all questions are welcome on the CS3 bSpace forum!
|