CSC151 2010S, Class 18: Turtle Graphics Overview: * Modeling images through process: Turtle graphics. * Some historical notes. * Turtle graphics in MediaScheme. * Lab. Admin: * Reading for tomorrow: Iteration. * EC for Wednesday's panel on Open Information Culture (4:15 pm Burling). * EC for Thursday's convo (or Wednesday's talk). * EC for Thursday's CS Extra: Tony Pan on his internship at Microsoft (4:15 3821). * EC for Friday's CS Table: No Silver Bullet (noon, JRC PDR). * I know that there are questions on Assignment 4. Assignment 4 ;;; Procedure: ;;; weights ;;; Parameters: ;;; steps, a positive integer ;;; Purpose: ;;; Generate a list of weights between ;;; 0 and 1 ;;; Produces: ;;; waits, a list of real numbers ;;; Preconditions: ;;; [No additional] ;;; Postconditions: ;;; The values in waits are "evenly spaced". ;;; For all reasonable i, element i of waits ;;; is 1/steps greater than element i-1 of waits. ;;; waits has (steps+1) elements. ;;; waits only has values between 0 and 1. (define weights (lambda (steps) (map (lambda (n) (/ n steps)) ; "a function that, given n, divide n by steppes" (iota (+ steps 1))))) ; Testing: Does the name we use matter? (define weights1 (lambda (stupendous) (map (lambda (squigglemajig) (/ squigglemajig stupendous)) ; "a function that, given n, divide n by steppes" (iota (+ stupendous 1))))) (define weights2 (lambda (steps) (map / ; "a function that, given n, divide n by steppes" (iota (+ steps 1)) (make-list (+ steps 1) steps)))) (define weights3 (lambda (steps) (map (r-s / steps) ; "a function that, given n, divide n by steppes" (iota (+ steps 1))))) But wait! Where's the (lambda (n) ...) or (lambda (x) ...) or (lambda (sqasdfasdf) ...) in the function we're mapping? * The (lambda (x) (/ x steps)) is longhand for (r-s / steps) * The computer immediately turns (r-s / steps) into (lambda (x) (/ x steps)) Turtle Graphics * We know three ways of writing algorithms that make pictures * GIMP tools: image-select-xxx and then stroke or fill * drawings as values * Manipulating pixel-by-pixel with image-set-pixel! * We're adding an Nth: Turtle graphics * Turtle graphics: A simplified drawing system Place the pen Choose a direction Move forward Turn * A stateful way of thinking about drawing * A turtle has a particular direction that it is facing. So, what it draws will differ depending on the angle. * A turtle has a position * A turtle has a color * A turtle has a brush Why do we use this model? * Simple: Not many operations * Turns out that using just these operations and repetition you can create really cool images * Historically important Lab (Hah!) * Tomorrow