programming in alice

22
Programming in Alice Chapter 2 Part 2

Upload: frayne

Post on 06-Jan-2016

27 views

Category:

Documents


1 download

DESCRIPTION

Programming in Alice. Chapter 2 Part 2. Events Editor. Identifies what method is executed (run) when the “Play” button is hit. Deleting Instructions. Right-click the instruction and select delete Drag the instruction tile to the trash can. Copying Instruction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Programming in Alice

Programming in Alice

Chapter 2 Part 2

Page 2: Programming in Alice

Events Editor

Identifies what method is executed (run) when the “Play” button is hit

2

Page 3: Programming in Alice

Deleting Instructions

Right-click the instruction and select delete

Drag the instruction tile to the trash can

3

Page 4: Programming in Alice

Copying Instruction

Right-click the instruction and select make copy

Drag the instruction tile to the clipboardo When the clipboard turns

green, drop the tileo Click on the clipboard

and drag it back to the Method Editor

4

Page 5: Programming in Alice

Objects With Custom Methods In addition to primitive methods some

objects have custom methods When objects are selected

from gallery, a listing ofcustom methods appears

Names of the custommethods give clues as towhat the method does What do you think

the foottap custom method does?

5

Page 6: Programming in Alice

Naming Conventions

Names are known as identifiers because they identify items in a program

Use a name that provides meaningo Name of method should indicate the method’s

purpose

6

Which one coaches the Knights and

which one coaches the Cougars?

Page 7: Programming in Alice

Naming Conventions

Dot notationo world.my first method

Dot (period) separates pieces of informationo Left side: object that the method belongs to

The WORLD object in this caseo Right side: name of the method

“my first method” in this case

7

the periodis called a

“dot”

Page 8: Programming in Alice

8

Naming Conventions

Most programming languages do NOT recognize spaceso Alice allows spaces, good practice is to not use

them method.my first method

Without spaces, how do you have more than one word in names?o Lower case first lettero Capitalize first letter of next wordso Called camelCase (camel’s hump)

Notethe

space

Notethe

space

Which is easier to read?

onehumpcamel

or

oneHumpCamel

Page 9: Programming in Alice

Class Names

Method names begin with a lower case letter

Class names are capitalized No spaces, so each word is capitalized

o This convention is called PascalCase

9

Page 10: Programming in Alice

Renaming

Objectso Right-click object’s tile in

the object tree and selectrename

Custom methodso Select the world objecto Select the methods tab from the Details Panelo Right-click the my first method tile and select

renameo If right-click does not work

then hit Control & click

10

Page 11: Programming in Alice

Orientation and Movement A translation in computer graphics

o Moves an object a specified distance in a specified direction

o Move instruction in Alice moves object Left, right, up, down, forward, backward

All movements of objects are egocentrico They move from their perspective, not ours

11

Page 12: Programming in Alice

Pivot Point Examples

Center of rotation

12

Page 13: Programming in Alice

Turn Method Causes rotational motion Can turn an object

o Left, right – similar to turning door on hinges Along the horizontal plane

o Forward, backward – lifting or closing hinged lid on a box

Along the vertical plane forward and backward

13

Page 14: Programming in Alice

Roll Method Object is rotated left or right

o Along the vertical plane clockwise or counter-clockwise Rotation depends on where center is

14

Page 15: Programming in Alice

Subpart Rotation

Center for rotational motion is where subpart connects to objecto Also called a pivot point

Turn rotation of Monkey’s left arm subpart

15

Page 16: Programming in Alice

Circling Other Objects Object’s turn method spins the

object aroundo Can also get an object circle around

another object

The asSeenBy optional argument causes an object to turn around the asSeenBy’s objects center point

Example: hawk turns one complete revolution around the tree from the tree’s perspective

16

Page 17: Programming in Alice

Orient to Method

Used when two objects need to move together synchronization

Objects might be pointing in different directions

Use orient to method to align themo Argument is object to orient to method

ForwardNotice change orientationof ball changed

17

Page 18: Programming in Alice

Facing and Pointing Objects Turn to face

o Causes object to turn toward another object Point at

o Aligns two objects from the center of one to center of other

o Centers are not always in good spot They could collide in odd places or cause odd

movement

18

Page 19: Programming in Alice

“Move to” Instruction Moves an object to another object

o Instead of a distance with move instruction The centers of both objects align

o This will make it look like they collide Better to use “move toward” instruction

o Need to know distance though and be careful of center

o Be very careful Will match center of both objects together If centers are at different heights the object will be

moved off ground or into ground to align centers Use “turn to face” object then move distance to object

19

Page 20: Programming in Alice

Exporting Code for Printing

20

Code can be exported to an HTML file

From File – Choose Export Code for Printing

You MUST add your name as the authoro Author’s name is printed

with the exported code

Author’s name

Page 21: Programming in Alice

Lab Lab exercises require you to demonstrate your

program to the professor When you write code you must explain to

professor what each line of code does and why. Professor will sign lab sheet after you do that You only get full credit for lab exercise if professor

signs lab sheet If you hand in lab without explaining code then

you will lose half credit

Page 22: Programming in Alice

Homework Read chapter 2 Do lab assignments in handout

o Exercise 6, 7 and custom exercise of fish circling island

Due one week after its assigned

22