06-Intro-Object-Oriented-Prog1 Barb Ericson Georgia Institute of Technology July 2009 Introduction to Object-Oriented Programming in Python.

Slides:



Advertisements
Similar presentations
Introduction to Object-Oriented Programming in Alice and Java
Advertisements

TOPIC 12 CREATING CLASSES PART 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Programming in Python Turtle Graphics Dr. Kristine Nagel Genie Yang Raquel Lawrence Dr. Kristine Nagel Genie Yang Raquel Lawrence Georgia Gwinnett College.
Chapter 16: Topics in Computer Science: Object-Oriented Programming.
Georgia Institute of Technology Drawing in Java part 1 Barb Ericson Georgia Institute of Technology September 2006.
Chapter 16: Topics in Computer Science: Object-Oriented Programming.
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
04-Intro-Object-Oriented-In-Java1 Barb Ericson Georgia Institute of Technology Sept 2009 Introduction to Object-Oriented Programming in Java.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
Introduction to Computers and Programming – Computer Programming.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 1.
AP Computer Science Principles Data Abstraction and Procedural Abstraction Curriculum Module.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
CreatingClasses-part11 Creating Classes part 1 Barb Ericson Georgia Institute of Technology Dec 2009.
Object-Oriented Programming. Object-oriented programming  First goal: Define and describe the objects of the world  Noun-oriented  Focus on the domain.
Microsoft® Small Basic
Methods in Java CSC1401. Overview In this session, we are going to see how to create class-level methods in Java.
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
CS1315: Introduction to Media Computation Referencing pixels directly by index number.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 2.
Class 2 Introduction to turtle graphics
Agent P, I have been hearing some rumours about a Python Turtle.
1 Turtle Graphics and Math Functions And how you can use them to draw cool pictures!
An introduction to Logo Mike Warriner Engineering Director, Google Note: This course is not an endorsement of Logo by Google. All views in this document.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Georgia Institute of Technology Processing Sound Ranges Barb Ericson Georgia Institute of Technology July 2005.
CONTROL SYSTEMS Control Systems A command is a directive that performs a specific task An argument is a variable that can be used by the function reveiving.
Java Introduction part 2 CSC1401. Overview In this session, we are going to examine some of the instructions from the previous class in more detail.
CreatingSubclasses1 Barb Ericson Georgia Institute of Technology Dec 2009.
Georgia Institute of Technology Simulations Barb Ericson Jan 2005.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Drawing with the Pen Barb Ericson Georgia Tech June 2011.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology Aug 2006 Introduction to Object-Oriented Programming in Alice and Java.
Chapter 17: Topics in Computer Science: Object-Oriented Programming.
Georgia Institute of Technology More on Creating Classes part 3 Barb Ericson Georgia Institute of Technology Nov 2005.
LOGO For the beginner Made by Rio Narazaki. W HAT I S L OGO ? Logo is a computer programming language used in Education. Logo is very easy to use. The.
Digital Art in Scratch part 2 Barb Ericson Georgia Tech Nov 2010.
Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.
CSC1401 Drawing in Java - 1. Goals Understand at a conceptual and practical level How to use the Turtle class to draw on a picture How to use the java.awt.Graphics.
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology Sept 2006 Introduction to Object-Oriented Programming in Alice and Java.
Georgia Institute of Technology Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah Branch King Abdulaziz University.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
CS 101: Introduction to Computing Referencing pixels directly by index number Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified.
Computer Programming.
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
More methods, more capabilities
Barb Ericson Georgia Institute of Technology Dec 2009
Introduction to Object-Oriented Programming in Alice and Java
Introduction to Object-Oriented Programming in Java
Agent P, I have been hearing some rumours about a Python Turtle.
Barb Ericson Georgia Institute of Technology August 2005
البرمجة مع لغة PYTHON TURTLE
Teaching Java using Turtles part 2
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
Introduction to Media Computation
Overview of OOP Terminology
Introduction to Object-Oriented Programming in Alice and Java
Workshop for Programming And Systems Management Teachers
Introduction to Object-Oriented Programming in Alice
Barb Ericson Georgia Institute of Technology May 2006
More on Creating Classes
Processing Sound Ranges part 3
More on Creating Classes part 3
Teaching Java using Turtles
Teaching Java using Turtles part 2
U3L4 Using Simple Commands
From Barb Ericson Georgia Institute of Technology June 2008
Using Modules.
Presentation transcript:

06-Intro-Object-Oriented-Prog1 Barb Ericson Georgia Institute of Technology July 2009 Introduction to Object-Oriented Programming in Python

06-Intro-Object-Oriented-Prog2 Learning Goals Compare procedural programming and object-oriented programming Introduce computation as simulation Create objects in Python Invoke methods on objects in Python Create a subclass Create a method in a class Pass a parameter to a method in a class

06-Intro-Object-Oriented-Prog3 Procedural Programming Focus is on the procedures –The tasks that need to be done –Break large tasks into smaller tasks Write a function for each task Problems with procedural –The data is passed around and any function can change the data –It is hard to find the function They can be in many files with many names

06-Intro-Object-Oriented-Prog4 Object-Oriented Programming The focus is on who does each task as well as the tasks to be done –Responsibility driven Advantages –Manage complexity by distributing responsibility across objects –Make systems robust by making objects work independently –Support reuse because objects provide services

06-Intro-Object-Oriented-Prog5 Computers as Simulators “The computer is the Proteus of machines. Its essence is its universality, its power to simulate. Because it can take on a thousand forms and serve a thousand functions, it can appeal to a thousand tastes.” Seymour Papert in Mindstorms

06-Intro-Object-Oriented-Prog6 Creating a Simulation Computers let us simulate things –We do this by creating models of the things we want to simulate –We need to define what types of objects we will want in our simulation and what they can do Classes define the types and create objects of that type Objects act in the simulation

06-Intro-Object-Oriented-Prog7 Creating objects We have been creating objects in Python using –makePicture(file) –makeSound(file) But, these are functions we created to make it easy to create objects from these classes

06-Intro-Object-Oriented-Prog8 Creating objects in python Use ClassName(value1,value2,…) –Picture(file) # create a picture –Sound(file) # create a sound –World() # create a world Name the objects that are created >>> earth = World() >>> tina = Turtle(earth) >>> sue = Turtle(earth) Use the name to ask the object to do something objName.function() >>> tina.forward()

06-Intro-Object-Oriented-Prog9 Turtle Behaviors forward() # forward by 100 pixels forward(amount) # forward by amount turnLeft() # 90 degree left turnRight() # 90 degree right turn(degrees) # pos right and neg is left penUp() # pick up the pen penDown() # put pen down moveTo(x,y) # move to x and y location setColor(blue) # set the color setPenWidth(width) # size of pen trail setVisible(false) # don't draw turtle

06-Intro-Object-Oriented-Prog10 Challenge Use a turtle to draw a square Use a turtle to draw blocks of color using a wide pen trail

06-Intro-Object-Oriented-Prog11 Create a Subclass class SmartTurtle(Turtle): def drawSquare(self): for i in range (0,4): self.turnRight () self.forward () >>> earth1 = World() >>> smarty = SmartTurtle(earth1) >>> smarty.drawSquare()

06-Intro-Object-Oriented-Prog12 Passing Parameters to Methods class SmartTurtle(Turtle): def drawSquare(self): for i in range (0,4): self.turnRight () self.forward () def drawSquare(self, width): for i in range (0,4): self.turnRight () self.forward(width) >>> mars = World () >>> tina = SmartTurtle(mars) >>> tina.drawSquare (30) >>> tina.drawSquare (150) >>> tina.drawSquare (100)

06-Intro-Object-Oriented-Prog13 Creating the Slide Class class Slide: def show(self): show(self.picture) blockingPlay(self.sound) >>> slide1=Slide() >>> slide1.picture = makePicture(getMediaPath("barbara.jpg")) >>> slide1.sound = makeSound(getMediaPath("bassoon-c4.wav")) >>> slide1.show()

06-Intro-Object-Oriented-Prog14 Constructors class slide: def __init__(self, pictureFile,soundFile ): self.picture = makePicture(pictureFile) self.sound = makeSound(soundFile) def show(self ): show(self.picture) blockingPlay(self.sound)

06-Intro-Object-Oriented-Prog15 Testing the constructor def playSlideShow2 (): pictF = getMediaPath("barbara.jpg") soundF = getMediaPath("bassoon -c4.wav") slide1 = slide(pictF,soundF) pictF = getMediaPath("beach.jpg") soundF = getMediaPath("bassoon -e4.wav") slide2 = slide(pictF,soundF) pictF = getMediaPath("church.jpg") soundF = getMediaPath("bassoon -g4.wav") slide3 = slide(pictF,soundF) pictF = getMediaPath("jungle2.jpg") soundF = getMediaPath("bassoon -c4.wav") slide4 = slide(pictF,soundF) slide1.show () slide2.show () slide3.show () slide4.show ()

06-Intro-Object-Oriented-Prog16 Object-oriented with Pictures >>> pic=Picture(getMediaPath("barbara.jpg")) >>> pic.show() >>> pic.getWidth() >>> pic.getHeight() >>> pixels = pic.getPixels() >>> pixel = pic.getPixel(0,0) >>> color = pixel.getColor(); >>> red = pixel.getRed()

06-Intro-Object-Oriented-Prog17 Picture Functions def show(picture ): if not picture.__class__ == Picture: print "show(picture ): Input is not a picture" raise ValueError picture.show ()

06-Intro-Object-Oriented-Prog18 Summary Procedural programming has a focus on the procedures (tasks) Object-oriented programming has a focus on the objects and on simulation You can create objects from classes in Python –Picture(file) or Class(parameters) You can create subclasses in Python –class SmartTurtle(Turtle): You can overload methods by passing different parameters