[plt-scheme] Graphycs with Scheme

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Mar 15 15:33:35 EDT 2009

I don't completely understand your request. But here are two

1. Make sure to separate the state of the world (where is Mario) from  
the rendering of the world on a canvas or whatever.

2. Here is how a freshman at NEU would do it after about five weeks:

(require 2htdp/universe) ;; actually set the teachpack in drscheme  

;; Nat -> Scene
;; place the appropriate ufo into an empty scene at height h

;; tests: omitted

(define (render h)
   (place-image (cond
                  [(<= 0 h THIRD) ufo1]
                  [(<= THIRD h 2THIRD) ufo2]
                  [(<= 2THIRD h FULL)  ufo3])
                50 h mt))

;; physical constants
(define FULL 300)
(define THIRD (* 1/3 FULL))
(define 2THIRD (* 2/3 FULL))

;; visual constants
(define mt (nw:rectangle 100 FULL 'solid 'white))
(define ufo1 (overlay (rectangle 40 4 'solid 'green) (circle 10  
'solid 'green)))
(define ufo2 (overlay (rectangle 40 4 'solid 'green) (circle 10  
'solid 'red)))
(define ufo3 (overlay (rectangle 40 4 'solid 'red) (circle 10 'solid  

;; run program run (tell the computer to make the clock tick (with  
height = # clock ticks)
;; and to use render as the function that turns the state (clock  
ticks) into a scene
(run-simulation render)

On Mar 14, 2009, at 12:43 PM, CHAMLY wrote:

> Hi all.
> I'm programming a game with some friends for a project we have to do
> on Scheme.
> So all our work is on a canvas... With a map that moves , and the
> object that stays put. (Like mario).
> Right now i am working on my object, that should move with the mouse
> click,( You click the object goes up, otherwise it falls down) .  That
> is not supposed to be to hard to do.
> But the object in question, has to change shape when going up, and
> when going down. (Same example with mario, when he jumps, he puts his
> hand up).
> What's the best way to do it. I had an idea but didn't know if it was
> possible. It was, to Put Two pictures on the same location moving both
> of them at the same time, and when you click, the old picture becomes
> invisible (Is that possible) and the new one Visible, And visa versa
> when you unclick. If the visible/invisible command exists, if someone
> could please tell me how to use it :D or where i could read about it,
> I'd appreciate it. If it doesn't If anyone has a better Idea, I'm open
> to all suggestions.
> Thank you
> Marc
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.