1 / 21

Comp 401 Animation Loops

Comp 401 Animation Loops. Instructor: Prasun Dewan. Prerequisite. Loops Advanced. Shuttle Animation. Basic Architecture. APlotted Shuttle. setShuttleX (Y)(). AShuttleAnimator. animateFromOrigin (). Main Class. main. AnimateFromOrigin Semantics. Animate from Origin.

gittel
Download Presentation

Comp 401 Animation Loops

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. Comp 401Animation Loops Instructor: Prasun Dewan

  2. Prerequisite • Loops Advanced

  3. Shuttle Animation

  4. Basic Architecture APlotted Shuttle setShuttleX(Y)() AShuttleAnimator animateFromOrigin() Main Class main

  5. AnimateFromOrigin Semantics

  6. Animate from Origin publicvoidanimateFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime) { intoriginalX = shuttle.getShuttleX(); intoriginalY = shuttle.getShuttleY(); intcurX = 0; intcurY = 0; shuttle.setShuttleX(curX); shuttle.setShuttleY(curY); animateYFromOrigin(shuttle, animationStep, animationPauseTime, curY, originalY); animateXFromOrigin(shuttle, animationStep, animationPauseTime, curX, originalX); }

  7. Animating to a Destination Location

  8. Animating to a Destination Location

  9. Pausing Program* void sleep (intpauseTime) { intnumberOfAssignments = pauseTime; //ASSIGNMENT_TIME; for (inti = 0; i < numberOfAssignments; i++) { int dummy = 0; // nonsense assignment } • ASSIGNMENT_TIME different on different computers! • Unnecessarily using the CPU (Busy Waiting) • Need the OS to suspend program for pause time

  10. Pausing Program: ThreadSupport.Sleep() public void sleep(intpauseTime) { try { // OS suspends program for pauseTime Thread.sleep(pauseTime); } catch (Exception e) { // program may be forcibly interrupted while sleeping e.printStackTrace(); }; }

  11. Animation in Y Direction protectedvoidanimateYFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime, intstartY, intendY) { // make sure we don’t go past final Y position while(startY < endY) { ThreadSupport.sleep(animationPauseTime); startY+= animationStep; shuttle.setShuttleY(startY); } // move to destination Y position shuttle.setShuttleY(endY); }

  12. Animation in X Direction protectedvoidanimateXFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime, intstartX, intendX) { while(startX < endX) { ThreadSupport.sleep(animationPauseTime); startX+= animationStep; shuttle.setShuttleX(startX); } shuttle.setShuttleX(endX); }

  13. AnimateFromOrigin publicvoidanimateFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime) { intoriginalX = shuttle.getShuttleX(); intoriginalY = shuttle.getShuttleY(); intcurX = 0; intcurY = 0; shuttle.setShuttleX(curX); shuttle.setShuttleY(curY); animateYFromOrigin(shuttle, animationStep, animationPauseTime, curY, originalY); animateXFromOrigin(shuttle, animationStep, animationPauseTime, curX, originalX); }

  14. Main Method publicstaticvoid main(String[] args) { PlottedShuttleshuttle = newAPlottedShuttle(50, 100); OEFrameoeFrame = ObjectEditor.edit(shuttle); oeFrame.hideMainPanel(); oeFrame.setSize(450, 450); ShuttleAnimatorshuttleAnimator = newAShuttleAnimator(); shuttleAnimator.animateFromOrigin(aShuttle, 5, 100); } No animation, nothing happens on the screen Using non observable version of plotted shuttle

  15. No Refresh protectedvoidanimateYFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime, intstartY, intendY) { // make sure we don’t go past final Y position while(startY < endY) { ThreadSupport.sleep(animationPauseTime); startY+= animationStep; shuttle.setShuttleY(startY); } // move to destination Y position shuttle.setShuttleY(endY); } Shuttle being displayed by some GUI code (e.g. ObjectEditor) Even if the method was called by it and it does automatic refresh GUI needs to be told when shuttle coordinates change Automatic refresh done when the method returns, not at indeterminate intermediate points

  16. Manual Full Refresh protectedvoidanimateYFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime, intstartY, intendY, OEFrame frame) { // make sure we don’t go past final Y position while(startY < endY) { ThreadSupport.sleep(animationPauseTime); startY+= animationStep; shuttle.setShuttleY(startY); frame.refresh(); } // move to destination Y position shuttle.setShuttleY(endY); }

  17. Manual Full Refresh publicclassShuttleAnimationDriver { publicstaticvoiddemoShuttleAnimation( ShuttleAnimatoraShuttleAnimator, PlottedShuttleaShuttle, OEFrameanOEFrame) { aShuttleAnimator.animateFromOrigin(aShuttle, 5, 100); aShuttleAnimator.animateFromOrigin(aShuttle, 5, 100, anOEFrame); } publicstaticvoid main(String[] args) { PlottedShuttleshuttle = newAPlottedShuttle(50, 100); OEFrameoeFrame = ObjectEditor.edit(shuttle); oeFrame.hideMainPanel(); oeFrame.setSize(450, 450); ShuttleAnimatorshuttleAnimator = newAShuttleAnimator(); demoShuttleAnimation(shuttleAnimator, shuttle, oeFrame); } } Both animateFromOrigins take the same amount of time The refreshing one changes the display, the other one does not

  18. Refreshing Architecture Component APlotted Shuttle setShuttleX(Y)() repaint() paint() ObjectEditor refresh() AShuttleAnimator animateFromOrigin animateFromOrigin() Main Class main

  19. Animation Steps • Animation consists of one or more animation steps • An animation step updates one or more animating graphical properties such as size, location, and icon of one or more graphical objects and then pauses execution

  20. Pausing Execution • Execution can be paused using busy waiting or a sleep call provided by the operating system • Busy waiting has the problem that it is platform-specific and does not allow other activity to proceed while the animation is paused • Therefore using the sleep call is preferable

  21. Incremental Updates • After each animation step, all displays of the animation must be updated • The refresh operation can be used to do ensure these updates are made.

More Related