|
| Greetings , I am trying to write a program that takes a list of posns
and by these posns(points) making a polygon by connecting them with
lines. Less or more I have written majority of the work however I am
stucked at a part that data sending for the recursion of the function
requires posn struct however the program is sending image thus giving
error. I am using a hybrid teachpack of world.ss and draw.ss from my
universty for using add-line and empty-scene function.
I will be greatful if someone correcting my program.
Thanks in advance.
PS: I have read the 1.2.3 part of the HTDP however still didnt help
much.
;;posn struct
;; x represents x coordinate of a point
;; y represents y coordinate of a point
(define-struct posn
(x y))
;;defining several posn structs
(define p1 (make-posn 250 250))
(define p2 (make-posn 100 80))
(define p3 (make-posn 90 160))
(define p4 (make-posn 350 350))
(define p5 (make-posn 320 110))
;;a list of posn structs
(define point-list (list p1 p2 p3 p4 p5))
;; posn struct , posn struct -> image
;;consumes 2 points and connects them by a line.
(define draw-line
(lambda (image point1 point2)
(add-line image (posn-x point1) (posn-y point1) (posn-x point2)
(posn-y point2) 'black))
)
;;ex: (draw-line (empty-scene 500 500) p1 p2)
(foldr (lambda (a b) (draw-line (draw-line (empty-scene 500 500) a b) a
b)) p1 (list p1 p2 p3 p4 p5))
|
|