We all come from Red, Green, and Blue!
Pixels and Arrays in Python


Identify Red, Blue, Green components of Pixels.
Describe an array as holding a list of values.  
Write functions in Python to manipulate Pixel data within arrays.
Use for loops to move through Pixel Arrays


BCS-BP-4:   Students will explore different representations of images and music in a computer.
BCS-BP-10:  Students will write programs that process two-dimensional arrays.

Prior Knowledge:

Students will know how to start the JES environment.
Students will know how to type, save, and load programs from the program area.
Students will know the standard format for class programs

# Title and Short Description of Program
# By:  FirstName LastName

# Define Functions

# Define main method

# Run main method


Students will know how to take ScreenShots of windows.  (They will learn "writePictureTo()" in a later lesson)

1 Computer with JES for each student. (Students can work in pairs)
Library of small images in .jpg format for students to use.
Several copies of Introduction to Computing and Programming in Python for student reference.

Vocabulary of Code for Activity:

pickAFile() Select a file (picture) from file system on computer
Creates an array of Pixels in JES
Displays a picture from array of Pixels to the computer screen

setRed(p, value)
Sets Red value for a given Pixel in a picture.
setBlue(p, value)
Sets Blue value for a given Pixel in a picture.
setGreen(p, value)
Sets Green value for a given Pixel in a picture.

Returns a list of all the pixels in a picture Array.

Project Requirements:

1.  Select picture from library to edit.
2.  Write a function to select and convert a picture file to an array.
3.  Write three functions:
    a.  Remove all the Red and Blue Pixels from picture and show.  (Green Only)
    b.  Remove all the Red and Green Pixels from picture show. (Blue Only)
    c.  Remove all the Green and Blue Pixels from the picture and show. (Red Only)
4.  Run functions and take Screenshots of each picture.  
5.  Save program and pictures to Student's file area.  (Use Screen Shot to save pictures)
    a.  MyNamePictures.py
    b.  MyNameGreen.jpg
    c.  MyNameBlue.jpg
    d.  MyNameRed.jpg

1.  Read Pages 67 to 71 in Introduction to Computing and Programming in Python and write additional functions for Negative and Grayscale.
2.  Save these pictures to your file area.

1.  Opening Activity:  Video Clip ->
    "Color and Light" from Sunday in the Park wth George by Steven Soundheim  (1:10 to 2:30)
    (Musical is about artist George Seurat and his painting of A Sunday Afternoon on the Island of La Grande Jatte)

Examine Painting A Sunday Afternoon on the Island of La Grande Jatte by George Seurat - Points of Light to Create Picture. 
Discuss how Computers use points of light -> Pixels to create pictures.

2.  Students Open JES and write the following program: (Students may copy and paste program into JES)

# Pictures and Arrays
# FirstName LastName

# Define Functions

# This function allows user
# to select a picture and display to the screen

def pickAndShowPicture():
  Pic = pickAFile()
  Pic = makePicture(Pic)

# Function to return an Array of pixels for a picture

def pickAndMakePicture():
  Pic = pickAFile()
  Pic = makePicture(Pic)
  return Pic

# Make the picture Green only

def keepGreen(pic):
  for p in getPixels(pic):

# Make the picture Blue only
# Write your function here

# Make the picture Red only
# Write your function here

def main():
  Pic1 = pickAndMakePicture()
  Pic1 = keepGreen(Pic1)

# Run main method


3.  Save program as "MyNamePictures.py"

4.  Load Program and Run.  Have students select a picture from the Picture Library.  Make sure all the students' programs work.  An example picture run by the program is here:

Original Picture
Green Picture

5.  Describe how pickAndShow() works. 
    a. Type pickAndShowPicture() in the Interactions Area
    b. Notice how JES shows original Picture on screen.

6.  Examine individual Pixels in a Picture:
    a. Type Pic1 = pickAndMakePicture() in the Interactions Area.
    b. Select MediaTools -> Picture Tool from JES menu bar.
    c. Hover curser over points in picture and note the x and y coordinates and the Red, Green, Blue Values

7. Class discussion: How does the keepGreen(pic) function work?
    a. for p in getPixels(pic) -> Makes a list of all the pixels in the Picture.  Moves through them one at a time. (Like passing out papers to a class)
    b. setBlue(p,0) -> Make the Blue part of the array equal to 0.
    c. setRed(p,0) -> Make the Red part of the array equal to 0.
    d. show(pic) -> Show the changed picture.

8.  Direct the students to create their own functions for "keepBlue()" and "keepRed()."  They should write them where the comments indicate.

9.  Alter the def main(): code to select a new function ( either keepBlue() or keepRed() )  Run the program and make Blue and Red versions of the picture.

10.  Save the program and Screen Shot the Red, Green, and Blue pictures and save them to your file area.


Does Not Meet the Standard
Meets the Standard
Exceeds the Standard
Format of Code
No use of comments.
No main method.
No Description of program.
Uses comments to define sections of program.
Uses main method.
Comments are concise and description.
Sections of program are clearly laid out.
Function and Content of Program
Program does not run. 
Did not complete Red or Blue Functions.
Pictures and or Program are not saved to File Area.
Program runs without errors. 
Red, Green, and Blue pictures and program are saved to file area.
Created additional functions for grayScale() and negative().
Saved additional grayscale and negative pictuers to file area.