1 / 19

CSC 112: Alice Chapter 3, Section 1

CSC 112: Alice Chapter 3, Section 1. Programming: Putting Together the Pieces Pages 51 - 56. Review of Sec 2, Chapter 2. Animation Programming Read scenario Design storyboard Implement Test results. Implementation. Translate the actions in the storyboard to a program.

Download Presentation

CSC 112: Alice Chapter 3, Section 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 112: AliceChapter 3, Section 1 Programming:Putting Together the PiecesPages 51 - 56

  2. Review of Sec 2, Chapter 2 • Animation Programming • Read scenario • Design storyboard • Implement • Test results

  3. Implementation • Translate the actions in the storyboard to a program. • Your storyboard might say: Do the following actions in order snowman turns to face snowwoman snowman says something snowwoman turns head snowman “raises eyebrows” snowwoman blushes as she turns head back around

  4. Concepts in this first program • Program instructions may have arguments • Example: • Some of the following actions COULD be done together • snowman turns to face snowwoman • snowman says something • snowwoman turns head • snowman “raises eyebrows” • snowwoman blushes as she turns back around Sequential Action Block Simultaneous Action Block

  5. Testing • An important step in creating a program is to run it – to be sure it does what you expect it to do. • Use an incremental development process: • write a few lines of code and then run it • write a few more lines and run it • write a few more lines and run it… • And SAVE frequently…especially after running the show and it does what you want it to do!!!

  6. Putting together the pieces • A major part of programming is putting together the pieces" that compose a program • The purpose of this session is to • define the fundamental pieces of a program • demonstrate how to put the pieces together

  7. Today’s Agenda • Instruction: • Statement that executes to make objects perform a certain action • Control Structure • Statement that controls the execution of a block of instructions • Function • Asks a question about a condition or computes a value • Expression • Math operation on numbers or other kinds of values

  8. What’s an Instruction? • An instruction is a statement that executes (is carried out by the computer at runtime) • In Object Oriented Programming, an instruction is defined as a method. • We’ve used instructions to make objects perform a certain action.

  9. What’s a Control Structure? • Statement that controls which instructions are executed and in what order. • Do in order • Do together • If/else • Repetition Sequential All at once Conditional Looping

  10. Conditional…Functions • Functions ask question (to check a condition) or computes a value. • In Alice, a function is used to get the information needed about • the properties of objects • Is the snowwoman's face red? • the relationship of one object to another • What is the distance between the mummy and pyramid? • a current condition • What key (on the keyboard) was pressed?

  11. Problem Example • FirstEncounter world: • camera angle influences perception of scene • How many meters does the robot need to walk to reach the rocks where the alien is hiding? Distance?

  12. Built-in Functions • Categories • proximity • size • spatial relation • point of view • other This example illustrates some built-in proximity functions.

  13. Values • When a function is used to ask a question or perform a computation, an answer is returned. • The answer is called a value. • Type of value depends on the kind of function. • In our example, we want to ask the question: • What is the distance of the robot to the rock? • We expect to get a number value. It could be a whole number or a fractional value, such as • 3 meters or 1.2 meters

  14. Demo • Ch03Lec1FirstEncounterDistanceFunction • The built-in distance to function determines the distance from the center of one object to the center of another object. • A function is not a "stand-alone" instruction; it is nested within another instruction.

  15. Types of Values • In our example, we used a function that has a number value. Other types of values include: • Boolean • true,false • String • "Oh, Yeah!" • Object • snowman, helicopter • Position in the world • (0, 0, 0) – the center of an Alice world

  16. Problem: Collision • When the program is run, the robot collides with a rock. • The problem is the distance between two objects is measured center-to-center. • One way to avoid a collision is to subtract a small number (1 or 2) from the distance.

  17. Expressions • An expression is a math or logic operation on numbers or other types of values • Alice provides math operators for common math expressions: • addition + • subtraction  • multiplication * • division /

  18. Demo • Ch03Lec1FirstEncounterExpressionV2 • Subtracting 2 meters from the distance is an arbitrary amount. • To be more precise, we could subtract the width of the rock. • The resulting expression subtracts the value of one function from the value of another function.

  19. Assignment • Read Chapter 3 • Simple Control Structures • Tips and Techniques 3Engineering Look and Feel • Lab…DUE by beginning of class on Thursday • Complete Exercise 1.Robot to Lunar Lander • Complete Exercise 3.Hop • Questions… • Answer the Short Answer Concept Questions at bottom of Chapter 3 Section 1 Lab sheet • Submit to WebCT Vista by beginning of class on Thursday NOTE: ASSIGNMENT DUE DATE

More Related