CSC151.02 2016S, Class 22: Images as Functions from Position to Colors
======================================================================

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions.
* Models of images.
* Iterating over positions: Images as functions from position to color.
* Blends and other positionally-computed images.
* Drawing simple shapes.
* Some strange computations.

Preliminaries
-------------

### Admin

* Thanks to JS the Elder for the notes!
* Continue partners!
* Prof. Curtsinger will be teaching class for the rest of the week.
    * If anyone wants to take notes for eboards, I'll provide extra credit.

### Reminders

* No more office hours this week.
    * I'll do a lot of email or text Q&A this week.
* Tutor hours
    * Sunday, 3-5 p.m.
    * Sunday-Thursday, 7-10 p.m.
* Weekly review sessions:
    * Wednesday at 8pm in the CS Commons with 
    * No Thursday review session this week .... )-:
    * Thursday at 8pm in the CS Commons with 

### Upcoming Work:

* Reading for Tuesday
    * [Building Data Structures with Heterogenous Lists](../readings/heterogeneous-lists-reading.html)
* [Assignment 5](../assignments/assignment.05.html) due TONIGHT
  at 10:30 p.m.
* Exam 2 to be distributed on Wednsday.
* Lab Writeup: Exercise 3
    * Send email titled __CSC 151 Lab Writeup 22 (Your Names)__
    * Do not include the underscores.
    * Send to <CSC151-02-grader@grinnell.edu>
    * Due before class on Friday.

### Extra Credit

* Send your reports to <rebelsky@grinnell.edu> with subject 
  "CSC 151 Extra Credit".  (Do not include the quotation marks.)
* Send opportunities to me before class with subject
  "CSC 151 EXTRA CREDIT OPPORTUNITY!"

#### Academic / Artistic

* Met Opera Simulcast, Saturday, March 5.

#### Peer

* Pub Quiz Wednesday at 10, hosted by Neuro/Psych SEPC.  You can
  eat food, or pay to participate in the quiz ($3/team).
#### Regular Peer

* Social Dance Workshop Tuesdays 7:00-8:00 in Bucksbaum Dance Studio
* Pun club Saturdays at 4pm in Younker 
* Electronic Potpourri on KDIC Fridays at Five 
* Space Odyssey KDIC Fridays at Six
* Fridays 7:30-8:30 Younker Lounge, Bollywood Dancing Team Fun Gathering

#### Misc

* Christine Tran show in Smith Gallery.
* Thursday evening Pub talk on Plans - Grinnell's own contribution to
  social media

#### Far in the Future

* Lords of the Flies, April.

### No Extra Credit, But Still Good

### Questions

Using `image-compute`
---------------------

* A bit like `image-variant`
    * `image-variant` takes a function from colors to colors
    * `image-compute` takes a function from positions to colors
* Useful for making a few kinds of images

Demos!
------

<pre class="screen">
> (define blend1
    (lambda (col row)
      (irgb (* 255 (/ col 200)) 0 0)))
> (image—show (image-compute blend1 200 200))
</pre>

What do you think will this show?

* No blue component, probably no green as well
* Heavy black gradient until you reach right side where it becomes redder
* If we changed col w/ row, we would get a vertical gradient

<pre class="screen">
> (define blend2
    (lambda (x y)
       (irgb (* 255 (/ x 200))
             0
             (- 255 (* 255 (/ x 200))))))
> (image-show (image-compute blend2 200 200))
</pre>

What do you think will this show?

* It will fade from blue to purple to red because it will kind of invert it.
* That’s right!

<pre class="screen">
> (define blend3
     (lambda (x y)
        (irgb (remainder (*10 x) 256) 0 0)))
> (image-show (image-compute blend3 200 200))
</pre>

What do you think will this show?

* Maybe it’ll get this funky black to red type of thing that cycles?
* Yep!

<pre class="screen">
> (define blend4
    (lambda (x y)
      (irgb (abs (- 255 (remainder (* 10 x) (* 255 2))))
            0
            0)))
> (image-show (image-compute blend4 200 200))
</pre>

What do you think it will show?
* It will kind of be like the last one where it cycles?
* It will cycle by going up first then back down.
* Unlike the last one where it goes from a sharp turn from red to black, 
  it’ll slowly go back from red to black again

<pre class="screen">
> (define blend4
    (lambda (x y)
       (irgb (abs (- 255 (remainder (* 10 x) (* 255 2))))
             (abs (- 255 (remainder (* 10 y) (* 255 2))))
             0)))
</pre>

* We have a new component using the row.  So we’ll get something that
looks like a cheesy high school background

We can do stuff other than cool blends.

<pre class="screen">
> (define thing1
        (lambda (x y)
                (if (and (> x 50) (< x 100) (> y 50) (< y 100))
                (irgb 255 0 0)
                (irgb 0 0 255))))
</pre>

What will this show?

* Two different sections, red and blue.
* Red square in a blue background

<pre class="screen">
> (define thing2
    (lambda (x y)
      (let ([num (remainder (truncate (/ x 20)) 3)])
        (cond 
          [(= num 0) 
           (irgb 255 0 0)]
          [(= num 1) 
           (irgb 0 255 0)]
          [else 
          i (irgb 0 0 255)]))))
</pre>

What will this show?

* It’ll be cycling like we’ve seen.
* If it lands on a 0, it’ll be red.
* If it lands on a 1, it’ll be green.
* Otherwise, it’ll be blue.

<pre class="screen">
> (define thing3
        (lambda (x y)
                (let ([num (remainder (truncate (/ x 20)) 3)]
                        [comp (* 255 (/ y 200))])
                (cond ((= num 0)
</pre>

Lab
---

Writeup: Problem 3 (Class 22)
