APCO 1P00 - Week 6 Lecture Slides

APCO 1P00 - Week 6 Lecture Slides - Week 6 String, Lists,...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
  1 Week 6 String, Lists, Modules, Drawing,  and Dot Notation (Some of Ch 10, Some of Ch 14)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  2 Objects Dot Notation and Drawing  Commands
Background image of page 2
  3 What is an Object? So far in this course, we have been using a form of programming referred to as “Procedural Programmming” This form of programming typically uses a main controller method, and many, many other methods/functions are called from it (or from each other). The dominant form of programming today, is “Object Oriented Programming”. We will cover it in more depth later. For now, just a VERY brief introduction to it.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  4 In this style of programming, we create “objects”, and those objects can be asked to do things. These objects have their own variables for keeping track of information about themselves. These objects also have their own methods that we can access, that do various things. Object A Variable1 Variable2 Method1 Method2 Method3
Background image of page 4
  5 As an example:  A pixel is an object! xPosition yPosition RedValue greenValue blueValue getRed() getGreen() getBlue() setRed() setGreen() setBlue() Pixel Object Variables Methods
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  6 So far, we have worked with pixels through “Procedural Progamming”. We call a generic function (also called a “Procedure”, hence the name of the programming style), and give it a pixel to work with. Eg: setRed ( somePixel , someRedValue ) In object oriented programming, we work with the pixel object directly by name. Eg: somePixel . setRed ( someRedValue )
Background image of page 6
  7 In the procedural version, essentially we are saying “Hey procedure – take this pixel and give it this new red value” In the object oriented version, essentially we are saying “Hey pixel – this is your new red value now”
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  8 Dot Notation Instead of passing an object in to a procedure, we use its own methods directly. We do this, with a system called “Dot Notation”. To specify which method of that object to use, we separate the objects name from the methods name with a simple period. This is where the name “Dot Notation” came from.
Background image of page 8
  9 Eg: somePixel . setRed ( someRedValue ) Object Name “Dot” Method Name Parameter(s) This example, is telling the pixel object named somePixel to change the value it is storing for its red value, to the value passed in as a parameter.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  10 A conceptual example of object use waterBottleObject maxCapacity = 500 presentCapacity = 0 fill( someAmount ) pour( someAmount ) getPresentCapacity ( ) Variables, and their initial values  Methods
Background image of page 10
  11 Variables maxCapacity 500 presentCapacity 0 >>> myBottle = waterBottleObject() >>> print myBottle.getPresentCapacity() 0 >>> myBottle.fill(400) >>> print myBottle.getPresentCapacity() 400 >>> myBottle.pour(150) >>> print myBottle.getPresentCapacity() 250 25 0 40 0
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  12 A few more examples def removeBlue( picture ): for p in getPixels ( picture ): p . setBlue (0) def reduceRed( picture ): for p in getPixels ( picture ): redValue = p . getRed () p . setRed (int( redValue * 0.5))
Background image of page 12
  13 Pictures are objects too!
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/30/2008 for the course APCO 1P00 taught by Professor Radue during the Spring '08 term at Brock University.

Page1 / 52

APCO 1P00 - Week 6 Lecture Slides - Week 6 String, Lists,...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online