;RPI desk set
;Contains (4): rect-gradient, draw-rect-border, draw-circ-border, draw-desk

;Function: rect-gradient
;Consumes: pos (posn), x (integer), ratio (real number) count-hor (has to be equal to x), count-ver (has to be 0), color1 (color symbol), color2 (color symbol)
;Returns: A four-sided polygon, in which the ratio length::height is equal to 'ratio'. A half of the polygon shall be color1 and the second half color2 (each half being 
;a triangle).

;Notes: If 'x' is not divisble by 'ratio', the halves will differ in some manner. This manner will depend on the remainder if we were to evaluate (/ x ratio).


(define (rect-gradient pos x ratio count-hor count-ver color1 color2)
  [cond
    ((<= count-hor 0) true)
    (else [and
           (draw-solid-line (make-posn (posn-x pos) (+ (posn-y pos) count-ver)) (make-posn (+ (posn-x pos) count-hor) (+ (posn-y pos) count-ver)) color1)
           (draw-solid-line (make-posn (+ (posn-x pos) count-hor) (+ (posn-y pos) count-ver)) (make-posn (+ (posn-x pos) x) (+ (posn-y pos) count-ver)) color2)
           (rect-gradient pos x ratio (- count-hor ratio) (+ count-ver 1) color1 color2)
           ]
     )
  ]
 )

;Testing (remove semi-colons to run):
;(start 1000 1000)
;(rect-gradient (make-posn 100 100) 99 pi 99 0 'firebrick 'darkred)

;Function: draw-rect-border
;Consumes: pos (posn), length "x" (integer), height "y" (integer), rect-color (color symbol), rect-border (color symbol)
;Returns: A rectangle with the provided length and heigh and color at the position specified, with a 1 pixel border of the color chosen.

(define (draw-rect-border pos x y rect-color rect-border)
  [and
   (draw-solid-rect pos x y rect-border)
   (draw-solid-rect (make-posn (+ 1 (posn-x pos)) (+ 1 (posn-y pos))) (- x 2) (- y 2) rect-color)
  ])

;Function: draw-circ-border
;Consumes: center (posn), radius (integer), border-size (insteger), circ-color (color symbol), circ-border (color symbol)
;Returns: A circle in the provided position with the radius and color given, said circle having a border around it of the specified color and size.

(define (draw-circ-border center radius border-size circ-color circ-border)
  [and
   (draw-solid-disk center (+ radius border-size) circ-border)
   (draw-solid-disk center radius circ-color)
   ])

;Function: draw-desk
;Consumes: var (integer multiple of 100), pos (posn), wood (color symbol), patch (color symbol), outline (color symbol)
;Returns: A default RPI dorm room desk. All the objects used in the drawing are in function of "var", in order to maintain a correct proportion. 
;The "patch" determines the color of the 'center' of said desk. Everything else seems self-explanatory.
;If in any case it is wished to determine which of the "draw-rect-border" functions draws which rectangle, simply replace 'wood' with a color symbol.

;Notes: 'var' has to be a multiple of 100 (sorry for the many inconveniences this may cause).

(define (draw-desk var pos wood patch outline)
 [and
  (draw-rect-border pos (* 0.05 var) var wood outline)
  (draw-rect-border (make-posn (- (posn-x pos) (* 0.05 var)) (+ (posn-y pos) (- var 1))) (* 0.05 var) (* 1.5 var) wood outline)
  (draw-rect-border (make-posn (+ (posn-x pos) (- (* 0.05 var) 1)) (+ (posn-y pos) (* 0.02 var))) (* 2 var) (* 0.13 var) wood outline)  
  (draw-rect-border (make-posn (+ (posn-x pos) (- (* 0.05 var) 1)) (- (+ (posn-y pos) (* 0.25 var))1)) (* 2 var) (+ 2 (* 0.65 var)) patch outline)
  (draw-circ-border (make-posn (+ (posn-x pos) (* 1.85 var)) (+ (posn-y pos) (* 0.3 var))) (* 0.05 var) 5 'white 'black)
  (draw-rect-border (make-posn (+ (posn-x pos) (- (* 0.05 var) 1)) (- (+ (posn-y pos) (* 0.15 var))1)) (* 2 var) (* 0.12 var) wood outline) 
  (draw-rect-border (make-posn (+ (posn-x pos) (- (* 0.05 var) 1)) (+ (posn-y pos) (* 0.90 var))) (* 2 var) (* 0.1 var) wood outline)
  (draw-rect-border (make-posn (- (posn-x pos) 1) (- (+ (posn-y pos) var)1)) (* 1.50 var) (* 0.25 var) wood outline) 
  (draw-rect-border (make-posn (+ (posn-x pos)  (- (* 2.05 var) 2)) (posn-y pos)) (* 0.05 var) var wood outline)
  (draw-rect-border (make-posn (+ (posn-x pos) (- (* 1.5 var) 2)) (+ (posn-y pos) (- var 1))) (* 0.65 var) (* .35 var) wood outline)
  (draw-rect-border (make-posn (+ (posn-x pos) (- (* 1.5 var) 2)) (+ (posn-y pos) (- (* 1.35 var) 2))) (* 0.65 var) (* .35 var) wood outline)
  (draw-rect-border (make-posn (+ (posn-x pos) (- (* 1.5 var) 2)) (+ (posn-y pos) (- (* 1.70 var) 3))) (* 0.65 var) (* .80 var) wood outline)
  (draw-rect-border (make-posn (- (posn-x pos) 1) (+ (posn-y pos) (- (* 2 var) 1))) (* 1.5 var) (* .15 var) wood outline)
  (draw-circ-border (make-posn (+ (posn-x pos) (* 1.85 var)) (+ (posn-y pos) (* 0.75 var))) (* 0.05 var) 5 'white 'black)
  ])
  
  
;Testing (remove semi-colons to run):
;(start 1000 1000)
;(draw-desk 200 (make-posn 50 50) 'burlywood 'darkred 'black)