;; a position (posn) represents a dot (pixel) by its x and y ;; coordinates. Use a function make-posn to create a new ;; position and posn-x, posn-y to get x and y coordinates of ;; an already created position (make-posn 5 6) ; make a position with x = 5, y = 6 (define pos (make-posn 3 4)) ; make a position with x = 3, y = 4 and call it pos pos ; printing the value of pos (posn-x pos) ; getting x coordinate of pos ;; distance-to-0 : posn -> number ;; to compute the distance of a-posn to the origin (define (distance-to-0 a-posn) (sqrt (+ (sqr (posn-x a-posn)) (sqr (posn-y a-posn))))) ;; Tests (check-expect (distance-to-0 (make-posn 3 4)) 5) (check-expect (distance-to-0 (make-posn 8 6)) 10) (check-expect (distance-to-0 (make-posn 5 12)) 13) ;; drawing with positions -- teachpack draw.ss required (define pixel-10-10 (make-posn 10 10)) (define pixel-100-10 (make-posn 100 10)) (define pixel-150-150 (make-posn 150 150)) (define pixel-10-20 (make-posn 10 20)) ;; open the canvas (start 300 300) (draw-solid-line pixel-10-10 pixel-100-10 'green) (draw-solid-disk pixel-150-150 50 'orange) (draw-solid-rect pixel-10-20 100 1500 'blue) ;; sleep for a while (sleep-for-a-while 1) ;; clear drawings (clear-solid-line pixel-10-10 pixel-100-10) (sleep-for-a-while 1) (clear-solid-disk pixel-150-150 50) (sleep-for-a-while 1) (clear-solid-rect pixel-10-20 100 1500) ;; add more drawings: concentric circles