Active Objects Animations! What are they? –Snapshots of objects i n different positions –When viewed quickly appear to be moving.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
Programs Involving Repetition Drawing Grass Drawing grids Printing marks on a ruler Repeatedly rolling dice in craps game.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Building Memory… Day 4 – November 20, Some clean up from last time Applet class can now be run as either an Applet or an Application Made picture.
Sketchify Tutorial Exercises sketchify.sf.net Željko Obrenović
Programming What is a program? –A set of instructions –Understood by a computer.
Recall: Accessing Location Info private Location firstPoint; public void onMousePress( Location pressPt ) { new Text("Pressed", pressPt, canvas ); firstPoint.
Threads A thread is a program unit that is executed independently of other parts of the program A thread is a program unit that is executed independently.
A Sample Program A rudimentary solar simulation: We want a click of the mouse in the window to make the ‘sun’ rise.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
Lesson 35: Review of the Java GUI. The JFrame, Container and JButton.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Overview of our Approach Program Structure –Data, variables, and parameters –Basic control structures (conditionals, loops and Threads) –Class definitions.
Peter Andreae Python for Level 3 CS4HS see website: ecs.vuw.ac.nz/Main/PythonForSchools.
Teaching Loops Facilitated by introducing simple threads Few interesting loop examples before arrays –Boring calculations –Interaction –Drawing –Animation.
Java Loops (Java: An Eventful Approach, Ch 7 and 13), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture 16 6 November 2012.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Java: An Eventful Approach An innovative approach to teaching Java in CS1 † Recursion Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially.
Introduction to Windows Programming
© A+ Computer Science - Chicken yeller = new Chicken();
Lesson 34: Layering Images with Java GUI. The FlowLayout RECAP.
The Drawing program – Java Applets
Animating GIF. What is it? Think of how a flip book works. Each page is a different picture and when flipped through quickly, it looks as though objects.
12/5/00SEM107, Kamin & ReddyReview - 34 Events Event types Catching different event types Getting information from components and events Distinguishing.
1 Numbering Is Helpful the pages of a book (chapters and sections too) days of a month years small collections-often use distinct names days of the week.
Georgia Institute of Technology Movies Barb Ericson Georgia Institute of Technology April 2006.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Chapter 2 Objects and Mutator Methods. A Sample Program A rudimentary solar simulation: We want a click of the mouse in the window to make the ‘sun’ rise.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Graphics basic 1. 2 Objectives Understand Java coordinate systems. Draw things using the methods in the Graphics class. Override the paintComponent method.
A Class of Our Own We’ve used many classes: –Location –FilledRect –Color –Text –And More! –But what if we want to make our own class?
Java Object Oriented Programming Encapsulation, Inheritance, Polymorphism (Java: An Eventful Approach - Ch. 17, 21.7), Slides Credit: Bruce, Danyluk and.
Test 2 Review. General Info. All tests are comprehensive. You are still responsible for the material covered prior to the first exam. You will be tested.
CS100A, Fall 1998 Key Concepts 1 These notes contain short definitions of the basic entities that make up a Java program, along with a description of the.
Practical Session 10: Animation. Animation kinds There are three basic kinds of animation: 1. Moving object 2. Changing pictures 3. Combination of 1 and.
Unit 7 – Desktop Publishing Animation Animation Skills Lesson – Overview of Adobe Flash Canvas TimeLine Tools Properties.
Java Working with Numbers (Java: An Eventful Approach, Ch 3), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture October 2012.
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה. בשבוע שעבר  paint  Graphics  repaint.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
Chapter 4Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapters 4 and 5: Excerpts l Class and Method Definitions l Information.
Week 12 - Monday.  What did we talk about last time?  Defining classes  Class practice  Lab 11.
Chapter 9 Active Objects + Boxball Project Design Animations! What are they? –Snapshots of objects i n different positions –When viewed quickly appear.
VG101 RECITATION 8 By TAs. CONTENTS Brief review of class Strategy for assignment 9 Questions about assignment 7, 8.
Java Objects (Java: An Eventful Approach, Ch 2), Slides Credit: Bruce, Danyluk and Murtagh CSCI 120 Lecture October 2012.
Teaching Control Structures, using objectdraw Chris Nevison Barbara Wells.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Chapter 4 - Finishing the Crab Game
using System; namespace Demo01 { class Program
What’s cheating and what is not?
Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College
Java Classes (Java: An Eventful Approach, Ch. 6),
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
Chapter 10 Algorithms.
Programs Involving Repetition
BBC Microbit.
Chapter 10 Algorithms.
More programming with "Processing"
by Pixer and Didney Animation Studios
PreAP Computer Science Review Quiz 08
Animation Practice ADd an entrance, emphasis and exit animation to the above title. Ensure each animation is initiated with a click.
Chapter 10 Algorithms.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
Text on screen: Recall that DNA is a double helix before packaging
Presentation transcript:

Active Objects Animations! What are they? –Snapshots of objects i n different positions –When viewed quickly appear to be moving

A Virtual Flipbook:

Animating an Object First create an object Then –Move it a little –Pause for the user to see it –Repeat

FallingBall public class FallingBall extends ActiveObject { public FallingBall( Location initialLocation, DrawingCanvas aCanvas ){ canvas = aCanvas; ballGraphic = new FilledOval (initialLocation, SIZE, SIZE, canvas ); start(); } public void run() { while ( ballGraphic.getY() < canvas.getHeight() ) { ballGraphic.move( 0, Y_STEP ); pause( DELAY_TIME ); } ballGraphic.removeFromCanvas(); }

Defining an Active Object define a class that extends ActiveObject ensure the class includes a run method pause occasionally within the run method include start(); usually as the last statement in the constructor

Using Active Objects public class FallingBallController extends WindowController { private FallingBall droppedBall; public void begin() { new Text("Click to make a falling ball…”, INSTR_LOCATION, canvas ); } public void on MouseClick( Location point ) { droppedBall = new FallingBall( point, canvas ); }

What if… We wanted the falling object to look like a raindrop

Image and VisibleImage Classes In the controller class: private Image rainPicture; rainPicture = getImage("raindrop.gif" ); Can be used anywhere: new VisibleImage( rainPicture, 0, canvas.getWidth()/2, canvas );

A Controller Class public class FallingRainPicController extends WindowController { private Image rainPicture; public void begin() { new Text("Click to make a falling raindrop…", INSTR_LOCATION, canvas ); rainPicture = getImage( "raindrop.gif" ); } public void onMouseClick( Location point ) { new FallingRainDrop( rainPicture, point, canvas ); }

A Falling Raindrop public class FallingRainDrop extends ActiveObject { private static final int DELAY_TIME = 33; private static final double Y_SPEED=4; private VisibleImage ballGraphic; private DrawingCanvas canvas; public FallingRainDrop( Image rainPic, Location initialLocation, DrawingCanvas aCanvas ) { canvas = aCanvas; rainGraphic = new VisibleImage( rainPic, initialLocation, canvas ); start(); } public void run() { while ( rainGraphic.getY() < canvas.getHeight() ) { rainGraphic.move( 0, Y_SPEED ); pause ( DELAY_TIME ); } rainGraphic.removeFromCanvas(); }

Active Object Interactions Accomplished with methods and parameters A RainCloud: –RainCloud continuously generates drops –Drops fall and disappear at the bottom

The RainCloud Class public class RainCloud extends ActiveObject { public RainCloud( DrawingCanvas aCanvas, Image aRainPic) { rainPic = aRainPic; canvas = aCanvas; start(); } public void run() { RandomIntGenerator xGenerator = new RandomIntGenerator( 0, canvas.getWidth() ); int dropCount = 0; while ( dropCount < MAX_DROPS ) { new FallingRainDrop( rainPic, new Location( xGenerator.nextValue(), 0 ), canvas); pause( DELAY_TIME ); dropCount++; }

Interactions Between Active and Non-Active Objects An Active Object: –Droplet in the shape of an oval Created at the top of canvas, falls to the bottom A Non-Active Object: –Waterline in the shape of a FilledRect Rises as drops fall

A New Kind of Raindrop 1.Created at the top of the screen 2.Falls to the bottom 3.Raises the waterline

Falling Droplet public class FallingDroplet extends ActiveObject { private FilledOval dropletGraphic; private FilledRect collector; public FallingDroplet( Location initialLocation, DrawingCanvas canvas, FilledRect aCollector ) { dropletGraphic = new FilledOval( initialLocation, SIZE, SIZE, canvas ); collector = aCollector; start(); } public void run() { while ( dropletGraphic.getY() < collector.getY() ) { dropletGraphic.move( 0, Y_STEP ); pause( DELAY_TIME ); } dropletGraphic.removeFromCanvas(); if ( collector.getY() > 0 ) { collector.setHeight( collector.getHeight() + SIZE/4 ); collector.move( 0, -SIZE/4 ); }

Active Objects without Loops Not required to loop public class CreditScroller extends ActiveObject { public CreditScroller( DrawingCanvas aCanvas ) { canvas = aCanvas; start(); } public void run() { new Credit( “Producer... Martha Washington “, canvas ); pause(DELAY_TIME); new Credit( “Director... George Washington “, canvas ); pause(DELAY_TIME); }

Credits public class Credit extends ActiveObject { private Text roleAndName; public Credit( String scrollingLine, DrawingCanvas canvas ) { roleAndName = new Text( scrollingLine, 0, canvas.getHeight(), canvas ); roleAndName.move( (canvas.getWidth() – roleAndName.getWidth())/2, 0 ); start(); } public void run() { while( roleAndName.getY() > -roleAndName.getHeight() ) { roleAndName.move( 0, -Y_STEP ); pause( DELAY_TIME ); } roleAndName.removeFromCanvas(); }

Final Notes Smoothness of animation depends on: –The delay between movements –The size of each movement