Download Presentation
## GBK Programming 1

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**GBK Programming 1**Jordan Johnson**Today’s plan**Greeting Review cond Lesson: movement in two dimensions Homework Clean-up**Cond-expressions**(cond …)**Problem**Develop the function sign that takes a number and returns its sign (-1 for negative numbers, 1 for positive numbers, 0 for 0).**Problem**(define W 200) (define H 300) Suppose we’rewriting pong: Develop the function ball-state that takes the ball’s x-coordinate and returns “play” if the ball is onscreen, “L” if the ball has gone off the left side, “R” if it’s gone off the right side.**Movement in 2-D**• So far, our worlds are simple: • a number • a string • Pong requires 2 dimensions… • …and for that we need posns.**posns: points in 2-space**• A posn is a (make-posnnumbernumber)where the numbers together represent an x- and y-coordinate pair. • e.g., (3, 7) would be (make-posn3 7) • Laws of posns: • (posn-x (make-posna b)) a • (posn-y (make-posna b)) b**posn functions**make-posn is the posnconstructor. posn-x and posn-y are accessors or selectors. We also get posn?, which is a type predicate.**Homework**• Due Wednesday: HW on cond. • See web site.**Clean-up**• Before you leave, please . . . • Log out. • Push in your chair. • Make sure you’ve got everything. • Make sure all trash ends up in the trash can.