PasteRack.org
Paste # 88525
2017-06-22 02:30:23

Fork as a new paste.

Paste viewed 54 times.


Embed:

sd

  1. #lang racket
  2. (require picturing-programs)
  3. (define WIDTH 200)
  4. (define HEIGHT 200)
  5. (define BACKGROUND     (empty-scene WIDTH HEIGHT))
  6. (define obj1 (circle 10 "solid" "red"))
  7. (define-struct posn (x y))            ;объявляем структуру
  8. (define INIT-WORLD (make-posn 100 100) )
  9. (define (change-current-world-key current-world a-key-event) ;обработка "событий" клавиатуры
  10.   (cond
  11.     [(key=? a-key-event "up")
  12.      (make-posn (posn-x current-world) (- (posn-y current-world) 5))]
  13.     [(key=? a-key-event "down")
  14.     (make-posn (posn-x current-world) (+ (posn-y current-world) 5))]
  15.     [(key=? a-key-event "left")
  16.      (make-posn (-(posn-x current-world)5) (posn-y current-world) )]
  17.     [(key=? a-key-event "right")
  18.     (make-posn (+(posn-x current-world)5) (posn-y current-world) )]
  19.     [else current-world]))
  20. (define (redraw current-world)
  21.   (place-image obj1
  22.                (posn-x current-world)
  23.                (posn-y current-world)
  24.                BACKGROUND))
  25. (big-bang INIT-WORLD
  26. (on-key change-current-world-key)
  27. (on-draw redraw) )

=>