Title: Working with pictures in JES
1Working with pictures in JES
2Review
- JES command area program area
- Defining/using functions
- specifying a sequence of steps for what the
function should do. - JES Functions for file manipulation JES-gtFiles
- JES Functions for interacting with user
JES--gtInput/Output - JES Functions for picture manipulation
JES--gtPictures
3Reminder Manipulating Pictures
gtgtgt file pickAFile() gtgtgt pic
makePicture(file) gtgtgt show(file) The error
wassample Name not found globally. A local or
global name could not be found. You need to
define the function or variable before you try to
use it in any way. gtgtgt show(pic) gtgtgt print
pic Picture, filename C\Documents and
Settings\mpapalas\Desktop\sample.jpg height 1200
width 1600
Oops!
4Lets make some pictures
- gtgtgt pic1 makeEmptyPicture(200,100)
- gtgtgt show(pic1)
- gtgtgt setAllPixelsToAColor(pic1, red)
- gtgtgt show(pic1)
- gtgtgt addText(pic1,30,50,hello")
- similarly can add rectangles, lines, etc.
5Making new Colors
- Some names for common colors are predefined try
using the names yellow, black, white, etc. - makeColor() takes red, green, and blue values (in
that order) between 0 and 255, and returns a
Color object - pickAColor() lets you use a color chooser and
returns the chosen color
6red108
green86
blue142
y 9
Color(108,86,142) Position (12,9)
x 12
7Encoding RGB
- Colors go from
- (0,0,0) to (255,255,255)
gtgtgt pic2 makeEmptyPicture(200,100) gtgtgt
show(pic2) gtgtgt seafoam makeColor(153, 255,
204) gtgtgt setAllPixelsToAColor(pic2, seafoam) gtgtgt
show(pic2)
8Saving to a file
- setMediaPath()Prompts the user to pick a folder
on the computer. JES then will look for files in
that directory unless given a full path, i.e. one
that starts with "c\" - writePictureTo(picture, path)picture the
picture you want to be written out to a
filepath the path to the file you want the
picture written toTakes a picture and a file
name (string) as input, then writes the picture
to the file as a JPEG. - Example
- writePictureTo(pic, mypic.jpg)
9Conditionals
- if age lt 18
- showInformation(Sorry, not allowed to vote
yet.) - else
- showInformation(Please select candidate.)
10Repetition
- for number in range(0,N)
- pic ....
- filename base str(number)
- writePictureTo(pic, filename)
-
11Lists
- hi, hello, howdy, hiya, yo
- 10, 23, 15
-
- range(0,6)
- range(1,4)
- range(3,8)
12Assignment
- Create a function makeMeSwatches() that makes
lots of color swatches (small solid-colored image
files). Specifically, your function should - display a welcome message to the user
- ask the user to say how many swatches
- ask the user to select a folder for storing the
swatches - create small files with images of solid color and
save them in the selected folder - display a message letting the user know that it
is finished. - Test your function well to make sure that it
works and have it checked by the TA before
submitting.