COMPUTER SCIENCE LESSONS

GRAPHIC PROGRAMS
LESSONS
Cartisian Plane Code
Copy and Paste the code below into DrScheme and Execute.
Remember to add the draw.ss from Language/add teachpack/htdp.
;;=======================TEACH PACK COORDINATE PLANE====================|
;;--------------------> Canvas Size <---------------------
(define L 400)     ;; Length of Canvas
(define M (/ L 2)) ;; Middle
(start L L)        ;; Starts a drawing canvas

;;------------------- > X-AXIS and Y-AXIS <------------------
(draw-solid-line (make-posn M 0) (make-posn M L))
(draw-solid-line (make-posn 0 M) (make-posn L M))

;;---------------------> Drawing Commands <---------------------------
;;line: posn posn color -> true
;;Draws a line given the start and end points and a color on a cartesian plane
(define (line start end color)
  (draw-solid-line (make-posn (+ (posn-x start)M) (- M (posn-y start)))
                   (make-posn (+ (posn-x end) M) (- M (posn-y end))) color))

;;circle: posn number color -> true
;;Draws a circle given the center point, radius and a color on a cartesian plane
(define (circle center radius color)
  (draw-circle (make-posn (+ M(posn-x center)) (- M (posn-y center))) radius color))

;;disk: posn number color -> true
;;Draws a solid-disk given the center point, radius and a color on a cartesian plane
(define (disk center radius color)
  (draw-solid-disk (make-posn (+ M(posn-x center)) (- M (posn-y center))) radius color))

;;rect: posn number number color -> true
;;Draws a solid-rectangle given the top-left corner point, the length, width and color
(define (rect corner L H color)
  (draw-solid-rect (make-posn (+ M (posn-x corner)) (- M (posn-y corner))) L H color))
;;=======================END OF TEACH PACK COORDINATE PLANE=========================|

;;--------------------> Grid Line Markers <-----------------
(line (make-posn -5 100) (make-posn +5 100) 'black)
(line (make-posn 100 -5) (make-posn 100 +5) 'blue)
(line (make-posn -5 -100) (make-posn +5 -100)'green)
(line (make-posn -100 -5) (make-posn -100 +5) 'red)

;;--------------------> Sample Object <------------------
(circle (make-posn 0 0) 80 'red)
(disk (make-posn 30 30) 15 'blue)
(disk (make-posn -30 30) 15 'blue)
(rect (make-posn -40 -30) 80 5 'red)

;;-------------------> YOUR PRACTICE FOR MASTERY <-------------
Following the above examples, add personality to the face.

PLAN ON GRAPH PAPER FIRST!!

TO REVIEW AND LEARN COPY SAMPLE CODE INTO SCHEME,
RUN, OBSERVE, COMPARE AND CONTRAST THE CODE!

Home