I am working through Realm of Racket chapter 5, last exercise was: Find an image of a locomotive and create an animation which wraps around to the left side of the screen after passing the right margin.
I have a solution which is below, but have some questions: 1. Is the solution below a reasonable one? How could I have done it better? 2. I don't really understand what is happening with the big-bang on-tick. The big-bang function is passed 50 as the initial state. Does the big-bang function somehow internally keep the state variable cached and then it gets updated by the change-state function. That bit seems a little confusing to me. Or should I just read more of the book until it is clearer? My background is imperative languages, eg C, C++, Java, python, etc. Not sure if that helps. My solution to problem: #lang racket (require 2htdp/universe 2htdp/image) (define LOCO-IMAGE <loco-image-here>) (define WIDTH 800) (define HEIGHT 200) (define (change-state current-state) (cond [(>= current-state 750) 0] [else (+ current-state 3)])) (define (draw-a-ufo-onto-an-empty-scene current-state) (place-image LOCO-IMAGE current-state (/ HEIGHT 2) (empty-scene WIDTH HEIGHT))) (big-bang 50 (on-tick change-state) (to-draw draw-a-ufo-onto-an-empty-scene)) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.