;; ======= spider web ===============
;;
;;  draw-web posn number number symbol -> true
;;
;;  (draw-web center width depth color) draws a hexagonal
;;   spider web centered at the point specified by the posn
;;     struct center. 
;;     width is the radius of a containing circle.
;;     depth is the number of webs draw (each 20 pixels apart).
;;
;;   sample usage:
;;  (draw-web (make-posn 150 150) 100 5 'blue)
;;
;; Note that this function uses recursion to draw the web...

(define (draw-web center width depth color)
  (cond 
    [ (= depth 0) true ]
    [ (and 
	   ;; draw a hexagon
       (draw-hex center width color)
	   ;; and draw a web within the hexagon
       (draw-web center (- width 20) (- depth 1) color))
      true ]
    ))


;; draw-hex posn number color -> true
;;
;; (draw-hex center width color)
;;    draws a hexagon centered at the point specified by the
;;      posn (the argument center).
;;      width is the radius of a containing circle.
;;    This function also draw a line from each vertex of
;;      the hexagon to the center (used to draw the web).
;;      
;;   sample usage:
;;  (draw-hex (make-posn 100 100) 50 'Red)
;;
(define (draw-hex center width color)
  (and
   (draw-solid-line (make-point center width 0)
              (make-point center width 60) color)
   (draw-solid-line (make-point center width 60)
              (make-point center width 120) color)
   (draw-solid-line (make-point center width 120)
              (make-point center width 180) color)
   (draw-solid-line (make-point center width 180)
              (make-point center width 240) color)
   (draw-solid-line (make-point center width 240)
              (make-point center width 300) color)
   (draw-solid-line (make-point center width 300)
                     (make-point center width 0) color)
   ;
   ; radial lines from center
   ;
   (draw-solid-line center (make-point center width 0) color)
   (draw-solid-line center (make-point center width 60) color)
   (draw-solid-line center (make-point center width 120) color)
   (draw-solid-line center (make-point center width 180) color)
   (draw-solid-line center (make-point center width 240) color)
   (draw-solid-line center (make-point center width 300) color)
   
   ))


;;
;; make point consumes a posn number number -> posn.
;;
;; (make-point center width angle) creates a point that 
;;    is on the circle centered at the posn passed as the
;;    first argument (center) with radius = width. The x.y
;;    coordinated of the point are based on the angle provided
;;    in degrees. An angle of 0 degrees is along the positive 
;;    x axis, and 90 would be on the positive y axis.
;;
;; sample usage:
;;  (make-point (make-posn 100 100) 50 60)

(define (make-point center width angle)
  (make-posn
   (+ (posn-x center) 
      (* width
         (cos (* pi (/ angle 180)))))
   (+ (posn-y center)
      (* width
         (sin (* pi (/ angle 180)))))))


;;
;; sample code that will draw a web
;;(start 300 300)
;;(draw-web (make-posn 150 150) 100 5 'blue)