Arrows


arrow.ss

The teachpack arrow.ss implements controller for moving pictures across a canvass. It provides three operations:

  • control-left-right : shape number move -> true :
    It consumes a shape, a number, and a move program. The move program consumes a shape and a number and re-draws the shape on some canvas and produces a shape that is translated by N pixels left or right.

  • control-up-down : shape number move -> true :
    It consumes a shape, a number, and a move program. The move program consumes a shape and a number and re-draws the shape on some canvas and produces a shape that is translated by N pixels up or down.

  • control : shape number move-lr move-ud -> true :
    It consumes a shape, a number, and two move programs. The move programs consume a shape and a number and re-draw the shape on some canvas and produces a shape that is translated by N pixels left or right.
  • Example:

    (define RAD 10)
    
    (define (translate sh delta)
      (make-posn (+ (posn-x sh) delta) (posn-y sh)))
    
    (define (move sh delta)
      (cond
        [(and (clear-solid-disk sh RAD) (draw-solid-disk (translate sh delta) RAD))
         (translate sh delta)]
        [else false]))
    
    (start 100 100)
    
    (control-left-right (make-posn 10 20) 10 move)