{"size": 1897, "ext": "scrbl", "max_stars_repo_path": "htdp-doc/teachpack/htdp/scribblings/arrow.scrbl", "max_stars_repo_name": "bdeket/htdp", "max_stars_repo_stars_event_min_datetime": "2015-01-14T20:28:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T04:04:26.000Z", "max_issues_repo_path": "htdp-doc/teachpack/htdp/scribblings/arrow.scrbl", "max_issues_repo_name": "bdeket/htdp", "max_issues_repo_issues_event_min_datetime": "2015-01-14T19:50:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-19T21:38:00.000Z", "max_forks_repo_path": "htdp-doc/teachpack/htdp/scribblings/arrow.scrbl", "max_forks_repo_name": "bdeket/htdp", "max_forks_repo_forks_event_min_datetime": "2015-01-14T19:11:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T05:11:39.000Z"}
{"max_stars_count": 85, "max_issues_count": 132, "max_forks_count": 81, "avg_line_length": 25.9863013699, "max_line_length": 75, "alphanum_fraction": 0.6684238271}
#lang scribble/doc

@(require scribble/manual "shared.rkt"
          (for-label scheme teachpack/htdp/arrow))

@teachpack["arrow"]{Managing Control Arrows}

@;declare-exporting[teachpack/htdp/arrow]
@defmodule[#:require-form beginner-require htdp/arrow]

The teachpack implements a controller for moving shapes across a canvass.  

@defproc[(control-left-right
	   [shape Shape]
	   [n number?]
	   [move (-> number? Shape Shape)]
	   [draw (-> Shape true)]) true]{Moves shape @racket[n] pixels left
(negative) or right (positive).} 

@defproc[(control-up-down
	   [shape Shape]
	   [n number?]
	   [move (-> number? Shape Shape)]
	   [draw (-> Shape true)]) true]{Moves shape @racket[n] pixels up
(negative) or down (positive).} 

@defproc[(control
	   [shape Shape]
	   [n number?]
	   [move-lr (-> number? Shape Shape)]
	   [move-ud (-> number? Shape Shape)]
	   [draw (-> Shape true)]) true]{
Moves shape @racket[N] pixels left or right and up or down, respectively.} 

Example:
@(begin
#reader scribble/comment-reader
(racketblock 
;; A shape is a structure:
;;   (make-posn num num)

;; RAD : the radius of the simple disk moving across a canvas
(define RAD 10)

;; move : number shape -> shape or false
;; to move a shape by delta according to translate
;; effect: to redraw it
(define (move delta sh)
  (cond
    [(and (clear-solid-disk sh RAD)
          (draw-solid-disk (translate sh delta) RAD))
     (translate sh delta)]
    [else false]))

;; translate : shape number -> shape
;; to translate a shape by delta in the x direction
(define (translate sh delta)
  (make-posn (+ (posn-x sh) delta) (posn-y sh)))

;; draw-it : shape -> true
;; to draw a shape on the canvas: a disk with radius
(define (draw-it sh)
  (draw-solid-disk sh RAD))

;; Run:

;; this creates the canvas
(start 100 50)

;; this creates the controller GUI
(control-left-right (make-posn 10 20) 10 move draw-it)
))
