ecs10-12-3

Ecs10-12-3 - Final ECS 10 12/3 This This room Mon Dec 8 8-10 AM 8Two Two programs Will cover the whole course Bring Bring a(Blue Scantron 2000

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 12/3/2008 Final ECS 10 12/3 This This room, Mon Dec 8, 8-10 AM 8Two Two programs. Will cover the whole course. Bring Bring a (Blue) Scantron 2000. Bring Bring book, notes. Recommended: print outs of homework programs, programs we did in class. Assignment Assignment Due Due tonight! Writing an Image Use Use the save method. save im.save('paleTurkey.jpg') ‘paleTurkey.jpg’ ‘paleTurkey.jpg’ is the name of the new file I want to create. PIL PIL knows that it is a jpeg because of the extension .jpg How do you find this? How How does someone learn what methods are available for a new data type added by a module (like Image)? They They read the documentation! Some Some concepts might be unfamiliar because we don’t know much about image processing. But But there are few Python concepts they expect you to know, that we haven’t covered... 1 12/3/2008 Classes A class is a new data type, created by the class is module. The Image module creates the Image class. An object An object is a data item. im = Image.open(‘turkey.jpg’) Creates an object called im, of type Image, by reading the file and putting the data from the file into the Image object. Analogy Analogy name = ‘Nancy Drew’ im = Image.open(‘turkey.jpg’) Name is a variable, containing a string. im is a variable, containing an Image. Strings and Images are two kinds of objects; the class string is built-in to Python, but the class Image was added by a module. Instance Instance There There can be lots of objects of type string in a program, and similarly lots of objects of type Image. Each Each object is an instance of its class. instance We We say im is an instance of type Image, or im is an Image instance. Factory Factory Functions Create Create instances of the class. The The Image module provides lots of ways to make Images (new image that is all one color, read read from file, combine two existing images to combine make make a new one…) Often Often (like here) these are the only functions in the module. Anything Anything that works with an existing Image is given as a method. 2 12/3/2008 Image Methods oldColor = im.getpixel(location) im.putpixel(location, color) im.save(‘paleTurkey.jpg’) Any Any function that starts with a single existing image is written here as a method method. Data Data in an Object Image Image lets the user have access to some (but not all) of the data stored in the object. You You can look at some of the data through methods for methods, for instance getpixel. getpixel You You can change some data through methods, like putpixel. putpixel. Some Some of the data you can look at directly through variables that are part of the object. These are called attributes. attributes. Object Object Oriented Programming A philosophy about how to organize philosophy programs. Keep Keep data organized into objects, along with methods methods to use or modify that data. Many Many languages, including Python, have a lot of syntactic sugar to make object oriented programming easier. Defining New Classes Define Define a constructor method, which makes an instance of the class. Define Define the data inside the objects. Define methods that can be used on the object. object. Circle Circle class Data Data in class is center, radius and color of circle. Method Method is report. Constructor gets called when a new circle object object is created. 3 12/3/2008 Changing Object Attributes Change Change the color using a method. Could Could also have changed it directly, but this is considered nicer. Using Using the Object We We can make as many circles as we want. Each Each is its own object. 4 ...
View Full Document

This note was uploaded on 03/23/2011 for the course ECS 10 taught by Professor Amenta during the Winter '07 term at UC Davis.

Ask a homework question - tutors are online