Question: The following question uses a program called Dr.Racket. The textbook is called how to design programs http://www.htdp.org/ Question 1: ;; sierpinski : posn posn posn

The following question uses a program called Dr.Racket. The textbook is called "how to design programs" http://www.htdp.org/

Question 1:

;; sierpinski : posn posn posn -> true ;; to draw a Sierpinski triangle down at a, b, and c, ;; assuming it is large enough (define (sierpinski a b c) (cond [(too-small? a b c) true] [else (local ((define a-b (mid-point a b)) (define b-c (mid-point b c)) (define c-a (mid-point a c))) (and (draw-triangle a b c) (sierpinski a a-b c-a) (sierpinski b a-b b-c) (sierpinski c c-a b-c)))])) ;; mid-point : posn posn -> posn ;; to compute the mid-point between a-posn and b-posn (define (mid-point a-posn b-posn) (make-posn (mid (posn-x a-posn) (posn-x b-posn)) (mid (posn-y a-posn) (posn-y b-posn)))) ;; mid : number number -> number ;; to compute the average of x and y (define (mid x y) (/ (+ x y) 2)) 

Exercise 27.1.1. Develop the functions

;; draw-triangle : posn posn posn -> true

;; too-small? : posn posn posn -> bool

to complete the definitions in figure 72.

Use the teachpack draw.ss to test the code. For a first test of the complete function, use the following definitions:

(define A (make-posn 200 0)) (define B (make-posn 27 300)) (define C (make-posn 373 300) 

Create a canvas with (start 400 400). Experiment with other end points and canvas dimensions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!