Working with pictures in JES - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Working with pictures in JES

Description:

'hi', 'hello', 'howdy', 'hiya', 'yo'] [10, 23, 15] range(0,6) range(1,4) ... create small files with images of solid color and save them in the selected folder ... – PowerPoint PPT presentation

Number of Views:94
Avg rating:3.0/5.0
Slides: 13
Provided by: maryangela
Category:
Tags: jes | create | make | pictures | pix | sory | working

less

Transcript and Presenter's Notes

Title: Working with pictures in JES


1
Working with pictures in JES
2
Review
  • 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

3
Reminder 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!
4
Lets 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.

5
Making 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

6
red108
green86
blue142
y 9
Color(108,86,142) Position (12,9)
x 12
7
Encoding 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)
8
Saving 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)

9
Conditionals
  • if age lt 18
  • showInformation(Sorry, not allowed to vote
    yet.)
  • else
  • showInformation(Please select candidate.)

10
Repetition
  • for number in range(0,N)
  • pic ....
  • filename base str(number)
  • writePictureTo(pic, filename)

11
Lists
  • hi, hello, howdy, hiya, yo
  • 10, 23, 15
  • range(0,6)
  • range(1,4)
  • range(3,8)

12
Assignment
  • 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.
Write a Comment
User Comments (0)
About PowerShow.com