[racket] place-image winking effect with low y coord

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Oct 6 10:10:49 EDT 2014

Sorry, I don't understand what you mean. I have modified the main function so that (1) the whole thing is slower and (2) it records the whole thing as an animated gif: 

(define (main)
  (big-bang 0                                        ;; initial state 
            (record? #t)                             ;; <---------------
            (on-tick add-3-to-state 1/10)            ;; when the clock ticks, add ...   <-------------
            (to-draw draw-a-ufo-onto-an-empty-scene) ;; when the state changes, draw ... 
            (stop-when state-is-300)))               ;; when the UFO's y coordinate is 300, stop. 



The animated gif is here: 

 http://www.ccs.neu.edu/home/matthias/Tmp/UFO/i-animated.gif

-- Matthias



On Oct 5, 2014, at 11:52 PM, Brian Craft <bcboy at thecraftstudio.com> wrote:

> The same effect occurs in racket/share/pkgs/realm/chapter5/ufo-source.rkt.  When the state is increasing from 0, the image is not moving down the screen. It stays in one place, but is initially clipped to 0 horizontal lines. Then 1 line, then 2, and only when the state is 1/2 the image height does it start moving down the screen.
> 
> Also, if I call (draw-a-ufo-onto-an-empty-scene 0) in the interactions window, I once again get a different result: it renders the lower half of the image. This is the same behavior I see with my code.
> 
> Maybe a platform issue? (version) reports 6.0. I'm running it on ubuntu.
> 
> 
> 
> On Sun, Oct 5, 2014 at 6:13 PM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> 
> Can you send the full program please? Thanks -- Matthias
> 
> 
> 
> On Oct 5, 2014, at 8:52 PM, Brian Craft wrote:
> 
> > Hello -- Newbie here. I'm going through "Realm of Racket". I'm seeing an odd effect when using this to-draw handler in big-bang:
> >
> > (define (draw-a-ufo-onto-an-empty-scene game)
> >   (let ([pos (game-pos game)])
> >     (place-image IMAGE-of-UFO (round (vec-x pos)) (round (vec-y pos))
> >                  (empty-scene WIDTH HEIGHT))))
> >
> > vec is (struct vec (x y))
> >
> > As the y coordinate approaches zero, IMAGE-of-UFO gets clipped on the top and bottom, looking a bit like it's winking out of existence, rather than sliding off the canvas. This doesn't happen on any other edge. It's only as y approaches zero. It starts when the edge of the image meets the edge of the scene. That is, if the image is 20px high, and y starts at 30, and decreases by 1 on each tick, it will move up the canvas for 30..10, but from 10 on the image will not change position, but will instead be clipped on the top & bottom, until it disappears.
> >
> > This does not happen in the interactions window. If I call the above function in the interactions window, it renders as expected, with the image moving smoothly off the edge.
> >
> >
> > ____________________
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
> 
> 



Posted on the users mailing list.