+ All Categories

CSC1401

Date post: 06-Jan-2016
Category:
Upload: dyani
View: 30 times
Download: 0 times
Share this document with a friend
Description:
CSC1401. Animation Creating methods/instructions (class-level). Recall…. Princess Escape - PowerPoint PPT Presentation
Popular Tags:
23
CSC1401 Animation Creating methods/instructions (class-level)
Transcript
Page 1: CSC1401

CSC1401

Animation

Creating methods/instructions (class-level)

Page 2: CSC1401

Recall….Princess EscapeA princess has been grounded by her

father (a wizard) and kept inside the castle. Being a rather rebellious princess, she has emailed the local dragon taxi service. The dragon will fly to the princess and she will climb aboard the dragon to escape from the castle – to meet some friends at the village dance club.

Page 3: CSC1401

Textual Storyboard(pseudo code)

Do in order

dragon takes off

dragon flies to princess

princess climbs on dragon's back

dragon and princess escape

knight shakes his arm (and sword) in protest

Page 4: CSC1401

In our programs,we have been using…

Classes In Alice, classes are predefined as 3D models

Objects An object is an instance of a class.

Class: Frog (Uppercase name)

Objects: frog, frog1, frog2, frog3

(lowercase names)

Page 5: CSC1401

We have also used…

built-in (predefined) methods Examples: move, turn to face, say

World.my first method Example:

In the Dragon world, we wrote program code where a dragon took off (as the first step in our animation).

All the program code was written in this one method, see next slide…

Page 6: CSC1401
Page 7: CSC1401

Larger Programs

As you become more skilled in writing programs, you will find that programs quickly increase to many, many lines of code.

Games and other "real world" software applications can have thousands, even millions of lines of code.

Page 8: CSC1401

Potential ProblemThe program code just seemed to grow and grow.

If we continue to write programs this way the programs will become longer and more difficult to read and think about.

Page 9: CSC1401

Solution

A solution is to organize the instructions into smaller tasks.

Page 10: CSC1401

Stepwise Refinement

The process of breaking a problem down into large tasks and then breaking each task down into simpler steps is called stepwise refinement.

Once the storyboard is completed, we write a method for each task.

Page 11: CSC1401

Stepwise refinement - 1

How can a dragon "take off"?Do together

dragon moves up

dragon flaps wings

Do in order

dragon takes off

dragon flies to princess

princess climbs on dragon's back

dragon and princess escape

knight shakes his arm (and sword) in protest

Page 12: CSC1401

Stepwise refinement - 2

How can a dragon flap its wings?

Do together

dragon flap left wing

dragon flap right wing

Do together

dragon moves up

dragon flaps wings

Page 13: CSC1401

Stepwise refinement - 3

How can a dragon flap its left wing?Do in order

Do together dragon close left wing rolls right dragon far left wing rolls right

Do togetherdragon close left wing rolls leftdragon far left wing rolls left

Do together

dragon flap left wing

dragon flap right wing

Page 14: CSC1401

Demo: Create a class-level method

Page 15: CSC1401

Drag the code into the editor

Page 16: CSC1401

The complete method

Page 17: CSC1401

Calling a method

Page 18: CSC1401

Demo

Create the flapLeftWing method

Create an analogous flapRightWing method

Page 19: CSC1401

Create a flapWings method

Page 20: CSC1401

Demo

Create the flapWings method

Create a takeOff method, where the dragon moves up 2 meters and flaps its wings twice

What changes will you need to make to the duration= parameter to get the animation working?

Page 21: CSC1401

Summary

Why do we want to write our own methods? saves time -- we can call the method again and again without reconstructing code

reduces code size – we call the method rather than writing the instructions again and again

allows us to "think at a higher level"can think surprise instead of

“The alien moves up and says ‘Slithy toves?’ and then the robot's head turns around. "

the technical term for "think at a higher level" is "abstraction"

Page 22: CSC1401

Summary: Classes, Objects, & Methods

Object-oriented programming uses classes, objects, and methods as basic programming components.

These components help to organize a large program into small modules

design and think about an intricate program

find and remove errors (bugs)

Page 23: CSC1401

Assignment

Read Chapter 4, Section 3 Class-level Methods

How to create them

How to call them


Recommended