;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname structures) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp"))))) ;; 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) (define pos (make-posn 3 4)) pos (posn-x 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 (distance-to-0 (make-posn 3 4)) ;; expected value 5 (distance-to-0 (make-posn 8 6)) ;; expected value 10 (distance-to-0 (make-posn 5 12)) ;; expected value 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)