130 likes | 275 Views
This presentation introduces key concepts of objects and object-oriented programming (OOP) through engaging and interactive examples. It defines what an object is, its unique identification through properties and actions, and demonstrates how objects are categorized into classes. The presentation utilizes the Alice programming environment to illustrate 3-D modeling, motion in space, and syntax rules for instructions. Learn about the role of time in animations, composite objects, and the essence of OOP as it relates to programming in a virtual world.
E N D
Objects and Object-Oriented Programming CS 110 – Honors Slides by Wanda Dann, Ithaca College
Objects • What is an object ? • any thing that can be identified as unique from other things • How is an object identified as unique? • has a name • has properties: • width, height, color, location, age, ss#, id# • has a purpose: • associated actions it can perform • tasks it can carry out
Peter Person Paul Mary Spike Dogs Scottie Fluffy Class • Objects are categorized into classes • Each object is an instance of the class. • All objects in a class have similar propertiesand generally can perform the same tasks.
Objects in a Virtual World • In Alice, each 3-D model is an object • has a unique name • Bunny, Bunny1, Bunny2 • has color(s) • Pink, White, Grey, Black, Blue, …. • has 3 dimensions • height, width, depth
Object Orientation • Each object has 6 degrees of orientation • front, back, left, right, up, down • Orientation is relative to the object itself • Bunny.move(left, 1, …) is a move to the Bunny's left • But, an object is aware of its orientation relative to other objects • Bunny.pointAt(Helicopter)
3-D Space • An object is located in 3-D space y (0,0,0) x x is left - right y is up - down z is front - back z
Repositioning • Movement of an object changes its position in space. • Some movements are translational • Bunny.move(back, 0.5, …) • Other movements are rotational • Bunny.turn(left, 0.5, …)
Motion Distance • Translational Distance • 1 unit is about 1 meter (relative to the Virtual World dimensions) • Rotational Distance • 1 unit is 1 rotation (360 degrees -- full turn) • Can specify • fractional parts of a unit • 1/2 • 0.5 • multiple units • 2
Instructions • An instruction such as Bunny.move(left, 1, …) is a statement that asks an object to perform an action or carry out a task. • Instructions must follow certain rules of syntax objectName.actionName(argumentList) • Note: • Instructions may have 0, 1, 2, … or more arguments • Some arguments are optional, some are required
Time • Animation takes time -- even on fancy computers! • By default, executing an instruction in Alice takes 1 unit of time (approx. 1 second) • You can specify the amount of time Bunny.move(left, 1, duration = 2) Note: This instruction would slow down the move -- how could you speed it up?
Object Parts • Many objects are made up of parts (we say they are composites) • A part of an object moves • with the entire object, by default • on its own, if given a specific instruction • Bunny.head.leftear.turn(down, 1/8) • Syntax: objectName.partNameList.actionName(argumentList)
Object-Oriented Programming • An Alice program is: • a scene containing • stationary objects -- like props on a stage • active objects -- will move around the scene • a list of instructions that ask the objects to perform tasks in the virtual world • So, an Alice program is object-oriented.
Reading and Lab • See handouts. • Note: Lab exercises and projects require that you show me the code and execution of the programs created. I must "initial" your lab sheet for the exercises and projects or you will not get credit for them!