;; The structure represents a circle ;; The structure represents a circle ;; center is the position (posn structure) of the center ;; radius is its radius (a non-negative number), and ;; color is a symbol representing a color (define-struct circle (center radius color)) ;; draw-a-circle: circle -> true ;; the function draws a circle structure as a disk ;; and returns true (define (draw-a-circle a-circle) (draw-solid-disk (circle-center a-circle) (circle-radius a-circle) (circle-color a-circle)) ) ;; clear-a-circle: circle -> true ;; the function clears a disk corresponding to a circle ;; and returns true (define (clear-a-circle a-circle) (clear-solid-disk (circle-center a-circle) (circle-radius a-circle)) ) ;; move-circle: circle number number -> circle ;; the function creates a new circle from a given one ;; with coordinates shifted by x-shift and y-shift (define (move-circle a-circle x-shift y-shift) (make-circle (make-posn (+ (posn-x (circle-center a-circle)) x-shift) (+ (posn-y (circle-center a-circle)) y-shift)) (circle-radius a-circle) (circle-color a-circle) ) ) ;; The structure represents a rectangle ;; left-upper is the position (posn structure) of its ;; left upper corner, height and width are its height and ;; width (non-negative numbers), and ;; color is a symbol representing a color (define-struct rectangle (left-upper height width color)) ;; draw-a-rectangle: rectangle -> true ;; the function draws a rectangle structure as a solid rectangle ;; and returns true (define (draw-a-rectangle a-rectangle) (draw-solid-rect (rectangle-left-upper a-rectangle) (rectangle-height a-rectangle) (rectangle-width a-rectangle) (rectangle-color a-rectangle)) ) (define (draw-shapes alosh) (cond [(empty? alosh) true] [(circle? (first alosh)) (and (draw-a-circle (first alosh)) (draw-shapes (rest alosh)))] [(rectangle? (first alosh)) (and (draw-a-rectangle (first alosh)) (draw-shapes (rest alosh)))] ) ) ;; nested-squares: number number color boolean posn -> list of rectangles ;; what will the fucntion draw? (define (nested-squares width min-width color isWhite left-upper) (cond [(< width min-width) empty] [else (cons (make-rectangle left-upper width width (cond [isWhite 'white] [else color] ) ) (nested-squares (/ width 2) min-width color (not isWhite) (make-posn (+ (posn-x left-upper) (/ width 4)) (+ (posn-y left-upper) (/ width 4)))))] )) ;; change the function to make the nested rectangles alternate between two different ;; colors and each next one have 3/4 width of the previous one (start 300 300) (define squares (nested-squares 256 10 'blue false (make-posn 20 20))) (draw-shapes squares)