I am studying the book Realm of Racket.
On chapter 5, there is a challenge:
Find an image of a locomotive. Create an animation that runs the locomotive from just past the left margin to just past the right margin of the screen. Next, modify your program so the locomotive wraps around to the left side of the screen after passing the right margin.
I created the following code using Racket and Dr. Racket.
However, I bet it could be improved.
My doubt is specially about the transition from the right side to the left side. I think there should be a better way of doing this:
#lang racket
(require 2htdp/universe 2htdp/image)
(define LOCOMOTIVE image-inserted-through-DrRacket )
(define HEIGHT 800)
(define WIDTH 800)
;essa função muda a velocidade com que a figura se mexe
(define (add-3-to-state current-state)
(if (< current-state 1055)
(+ current-state 6)
(- current-state 800)))
(define (locomotive-running current-state)
(place-image LOCOMOTIVE current-state (/ WIDTH 2)
(empty-scene WIDTH HEIGHT)))
(big-bang 0
(on-tick add-3-to-state)
(to-draw locomotive-running))
That's the image that I used: