Functional Problem Solving (CSC 151 2015S) : EBoards

CSC151.01 2015S, Review Session Week 11: Vectors and Beyond


Overview

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:

Likely quiz questions:

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))))