SCHEME DRAWING COMMANDS

advertisement
SCHEME DRAWING COMMANDS
;;
start
make-posn
draw-circle
draw-solid-disk
draw-solid-rect
draw-solid-line
DEFINITIONS
define
COLOR CONSTANTS
‘white
‘black
‘red
‘blue
‘green
‘yellow
ARITHMETIC OPERATORS
+
/
*
LOGICAL OPERATOR
and
Pre-defined FUNCTION CALLS
(start 640 480)
(make-posn 320 240)
(draw-circle (make-posn 150 200) 38 ‘red)
(draw-solid-disk (make-posn 320 150) 50)
(draw-soilid-rect (make-posn 0 450) 640 30 ‘green)
(draw-solid-line (make-posn 150 240) (make-posn 150 350))
CONSTANT DEFINITIONS
(define MID-X 320)
(define MID-Y 240)
PROGRAM DEFINITIONS
(define (centerCircle radius color)
(draw-circle (make-posn MID-X MID-Y) radius color))
CALLS
(centerCircle 30 ‘red)
(centerCircle 25 ‘blue)
| How to Design Programs, TeachScheme! Project, Software
| Graphic Programming Module Lessons
Commands are case-sensitive, use lower-case
Documentation, not a command, comments for human user
Opens a drawing canvas, 2 arguments – width and height
Plots a point, a position, 2 arguments – X and Y coordinates
3 arguments – center position, radius, color
3 arguments – center position, radius, color
4 parameters – top left corner, width, height, color
4 parameters – left end point, right end point, color
(color optiona l - defaults to black)
Uses open and close parenthesis
Defines a constant and a function
Case-sensitive – use lower-case characters
Can erase part of a shape if on top and background is white
Used to outline objects
R
B
G RBG are basic colors in digital graphics
More colors available in advanced graphics library
(operator operand..operand) (action data)
(+ 3 4)
(+ ½ ¼)
(- 3 4)
(- (+ 5 6) (- 8 9) )
(/ 3 4) (+ (/ 5 6) -8)
(* 3 4)
(- (* 9 8) (* 3 4) )
Can use the interaction window for parameter value planning
(Returns a Boolean value – true or false)
Used to combine shapes - drawing commands always returns true
Set library: Language / TeachPack / HTDP / draw.ss
;; (start canvasWidth canvasHeight)
;; (make-posn x-coordinate y-coordinate)
;; (draw-circle centerPoint radius color)
;; (draw-solid disk centerPoint radius color)
;; (draw-solid-rect topLeftPostion width height color)
;; (draw-solid-line startPoint endPoint color)
;; Note the color is optional, default to black
;;(define NAME value)
;;Midpoints of a 640 x 480 canvas
;;contract showing input and output
;;centerCircle: number color -> Boolean
;;returns true and draws a circle centered on a 640x480 canvas
of variable size and color
;;call function by its name then the actual data
;; variable parameters are matched with input values
(functionName dataForRadius dataForColor)
www.htdp.org See book for tutorial and more commands |
www.knorth.info under Graphics link |
Download