+ All Categories
Home > Documents > Shared Data

Shared Data

Date post: 15-Feb-2016
Category:
Upload: claus
View: 43 times
Download: 0 times
Share this document with a friend
Description:
Shared Data. Gail Carmichael [email protected]. Please Download:. www.scs.carleton.ca /~gail_c/comp1005/Robots1.zip www.scs.carleton.ca/~gail_c/comp1005/Birds1.zip. About Me. Sharing Resources. http://www.flickr.com/photos/marcosbessa/6260425373/. familyCar = new Car(“black”); - PowerPoint PPT Presentation
Popular Tags:
36
Shared Data Gail Carmichael [email protected]
Transcript
Page 1: Shared Data

Shared Data

Gail [email protected]

Page 2: Shared Data

Please Download:www.scs.carleton.ca/~gail_c/comp1005/Robots1.zip

www.scs.carleton.ca/~gail_c/comp1005/Birds1.zip

Page 3: Shared Data

About Me

Page 4: Shared Data

Sharing Resources

http://www.flickr.com/photos/marcosbessa/6260425373/

Page 5: Shared Data

familyCar = new Car(“black”);

mom.car = familyCar;dad.car = familyCar;teen.car = familyCar;

Page 6: Shared Data

teen.car.crash();

// Now the family car is not drivable!if (!mom.car.drivable()) mom.isStranded();if (!dad.car.drivable()) dad.isStranded();

Page 7: Shared Data

Robots Example

Page 8: Shared Data

Examine code inRobots1.pde

www.scs.carleton.ca/~gail_c/comp1005/Robots1.zip

Page 9: Shared Data

Robot

Robot

Robot

Beacon

Beacon

Beacon

Page 10: Shared Data
Page 11: Shared Data

Pros and cons?

Page 12: Shared Data

Let’s add movement(demo first)

Page 13: Shared Data

Step 1:Trigonometry to move forward in

current direction

x = x + speed * cos(direction)y = y + speed * sin(direction)

Page 14: Shared Data

Step 2:Change direction to head for beacon

Page 15: Shared Data

crossProduct = (r'x - rx)(gy - ry) - (r'y - ry)(gx - rx)

Page 16: Shared Data

Step 3:Add random error for realism

amountToTurn = θ + random(θ/4) - (θ/4)/2

Page 17: Shared Data
Page 18: Shared Data

Try implementing the move() method…

x = x + speed * cos(direction)y = y + speed * sin(direction)

crossProduct = (r'x - rx)(gy - ry) - (r'y - ry)(gx - rx)positive → left hand turn

negative → right hand turn

amountToTurn = θ + random(θ/4) - (θ/4)/2

Page 19: Shared Data

Let’s add drag-and-drop for the beacons

(demo first)

www.scs.carleton.ca/~gail_c/comp1005/Robots2.zip

Page 20: Shared Data

What if we want multiple robots per beacon?

www.scs.carleton.ca/~gail_c/comp1005/Robots3.zip

Page 21: Shared Data

Robot

Robot

Robot

Beacon

Beacon

Page 22: Shared Data
Page 23: Shared Data

Implement multiple robots per beacon.

Page 24: Shared Data

Bird Animation Example

Page 25: Shared Data

Please Download:www.scs.carleton.ca/~gail_c/comp1005/Birds1.zip

Study the code, run the program.

Page 26: Shared Data

How is the data in the program set up?Pros and cons?

Page 27: Shared Data

Where can data be shared?

Page 28: Shared Data

Implement sharing so each bird points to the same set of animation frames.

Page 29: Shared Data

Separating Shared Data

Page 30: Shared Data

Person molly = new Person(“Molly”);Person henry = new Person(“Henry”);

Person[] personList = new Person[2];

personList[0] = molly;personList[1] = henry;

Page 31: Shared Data

Person[] personListCopy = new Person[2];

for (int i=0; i < personList.length; i++){ personListCopy[i] = personList[i];}

Page 32: Shared Data

personListCopy[0].name = “Mallory”;

// Prints MallorySystem.out.println(personList[0].name);

Page 33: Shared Data

Person[] personListCopy = new Person[2];

for (int i=0; i < personList.length; i++){ personListCopy[i] = new Person(personList[i].name);}

Page 34: Shared Data

personListCopy[1].name = “Harry”;

// Still prints Henry since it’s unchangedSystem.out.println(personList[1].name);

Page 35: Shared Data

Shallow Copiesvs

Deep Copies

Page 36: Shared Data

Thanks!

Gail [email protected]


Recommended