CSC151.01 2015S, Review Session Week 11: Vectors and Beyond =========================================================== _Overview_ * You ask questions, I attempt to answer. * We talk about the forthcoming quiz. Your Questions -------------- _Can we make the turtle choose its color based on its position?_ > Um ... (turtle-set-color! turtle (irgb-complement (image-get-pixel (turtle-x turtle) (turtle-y turtle)))) > Here's some code that almost works (define turtle-oppose! (lambda (turtle) (turtle-set-color! turtle (irgb-complement (image-get-pixel (turtle-world turtle) (turtle-x turtle) (turtle-y turtle)))))) _How would one tilt the area of an ellipse?_ > Wait until tonight when Sam distributes the code he wrote this afternoon because he was predicting this question. _Can I select something more complex using a turtle?_ > image-select-polygon (in the tips) shows a technique, including using a turtle. > Once you've selected, you can also use gimp-selection-grow and gimp-selection-feather, both in the PDB list. _Can I draw offset nested circles?_ > Here's a start. (define center-circle (lambda (image x y radius) (image-select-ellipse! image REPLACE (- x radius) (- y radius) (+ radius radius) (+ radius radius)) (image-stroke! image) (image-select-nothing! image))) (define off-center-circle (lambda (image x y radius percent angle) (let ([hyp (* percent radius)]) (center-circle image (+ x (* hyp (sin angle))) (+ y (* hyp (cos angle))) radius)))) About the Quiz -------------- Main topics: * Vectors. * Randomness. Likely quiz questions: * Interpret _this code_. * Finish writing _this code_ that is supposed to accomplish _this task_. * Find the bugs in _this code_ that is supposed to accomplish _this task_. Sample (define vector-sum (lambda (vec) (let kernel ([sum-so-far 0] [index 0]) (if (< index (vector-length vec)) (kernel (+ sum-so-far (vector-ref vec index)) (+ index 1)) sum-so-far)))) * I might leave out parts * I might swap or change the inequality * I might swap consequent and alternate * I might misspell `sum-so-var`.