Notices Assn 4 posted. Due last day of class. Note that Exercise 10 contains the JavaFX code for three simple GUI programs. Winter 2016CMPE212 - Prof.

Slides:



Advertisements
Similar presentations
INTRODUCTION TO ADOBE FLASH CS4
Advertisements

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Chapter 6 Photoshop and ImageReady: Part II The Web Warrior Guide to Web Design Technologies.
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Agenda – Week 8, Day 1 Debrief from InDesign Transition to Flash/Animation Explore assignment Flash tutorials Lesson 1 - Workspace Lesson 2 - Drawing Lesson.
Chapter 3 Working with Symbols and Interactivity.
Website design Feng Zhao College of Educatioin California State University, Northridge.
2D Graphics: Part 2.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
BUILDING RICH MEDIA ELEMENTS. Design Decisions Based on Design Specification  Following the design specification will ensure that the application is.
Click your mouse for next slide Flash – Introduction and Startup Many times on websites you will see animations of various sorts Many of these are created.
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
Tutorial 2 Drawing Text, Adding Shapes, and Creating Symbols.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
© 2012 Adobe Systems Incorporated. All Rights Reserved. Copyright 2012 Adobe Systems Incorporated. All rights reserved. ® INTRODUCTION TO FLASH ANIMATION.
® Copyright 2010 Adobe Systems Incorporated. All rights reserved. ® ® 1 INTRODUCTION TO ADOBE FLASH PROFESSIONAL CS5.
XP Tutorial 1 Introduction to Macromedia Flash MX 2004.
SE 320 – Introduction to Game Development Lecture 8: Animations, GUIs, Debugging and IDEs Lecturer: Gazihan Alankuş Please look at the last two slides.
Introduction to Flash. Topics What is Flash? What can you do with it? Simple animation Complex interactive web application, such as an online store. Starting.
CSC 361/661 Digital Media Spring 2010 Professor Burg.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
Agenda – Week 8, Day 2 Tuesday Intro to Flash Animation process Computer animation Lesson 1 – Overview Lesson 2 – Drawing Lesson 4 – Layers Lesson 8 –
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
2006 Adobe Systems Incorporated. All Rights Reserved. 1 INTRODUCTION TO ADOBE FLASH CS3.
SVG for Designers Tom Hoferek. Objectives Introduce SVG Illustrate its capabilities Demonstrate SVG in action Speculate, discuss, answer questions.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
XP Tutorial 3 Creating Animations. XP New Perspectives on Macromedia Flash MX Elements of Animation Layers are used to organize the content of.
Fall UI Design and Implementation1 Lecture 13: Animation.
Introduction to Tool Panel. The tools in the Tools panel let you draw, paint, select, and modify artwork, as well as change the view of the Stage If the.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
Notices Assn 3 is posted – due tomorrow. Quiz marking underway (still – sigh…). Alternate solution code was added on Tuesday to the assignment 3 statement.
Today Threading, Cont. Multi-core processing. Java Never Ends! Winter 2016CMPE212 - Prof. McLeod1.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
Today Advanced JavaFX animation and 3D demos from Oracle. Threading. Winter 2016CMPE212 - Prof. McLeod1.
Notices Assn 4 posted. Due last day of class. Last quiz this week in Moodle, in the lab. Would the student doing the USATS please get them from Emily Crawford.
Android Application 2D Graphics cs.
Flash Interface, Commands and Functions
2D Graphics: Part 2.
CISC124 Quiz 3 grading underway, still... Assn 5 due tomorrow.
CMPE212 – Stuff… Marking finished for Quiz 3.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 15 Event-Driven Programming and Animations
ISC440: Web Programming II Ch14: HTML5 Canvas
INTRODUCTION TO ADOBE FLASH CS4
CISC124 Last Quiz this week. Topics listed in last Tuesday’s lecture.
Chapter Lessons Use the Macromedia Flash drawing tools
CMPE212 – Stuff… Assignment 4 due March 23 – this Friday.
CISC124 Last Quiz next week. Topics listed in Tuesday’s lecture.
INTRODUCTION TO FLASH ANIMATION
Working with Symbols and Interactivity
CISC124 Quiz 3 marking underway, still. Assn 5 due Friday, still.
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
CMPE212 – Reminders Assignment 2 sample solution is posted.
Using Animation and Multimedia
CMPE212 – Reminders Assignment 2 due today, 7pm.
CMPE212 – Reminders Assignment 5, a JavaFX GUI, due this Friday.
CMPE212 – Reminders Assignment 5, a JavaFX GUI, due next Friday.
Exercise : Animated Navigation Structure in Animate (= Flash)
Presentation transcript:

Notices Assn 4 posted. Due last day of class. Note that Exercise 10 contains the JavaFX code for three simple GUI programs. Winter 2016CMPE212 - Prof. McLeod1

JavaFX That You Need for Assn 4 You don’t have to use the stylesheet and the fxml file, but it makes it easier and the code is much tidier: –Styling with the css file. –Using SceneBuilder to work with the fxml file and assist with the controller *.java file. Panes and layout managers. Obtaining and restricting user input. The Canvas object and how to draw to it using its GraphicContext object. Animation using Timeline, AnimationTimer, Duration and KeyFrame. Winter 2016CMPE212 - Prof. McLeod2

Today Drawing and Animation: –Canvas and GraphicsContext. –Animation using classes in the javafx.animation package: Timeline, AnimationTimer, KeyFrame, KeyValue. –Imitating the behaviour of the old swing Timer thread. –Suggestions for animating the fireworks. Winter 2016CMPE212 - Prof. McLeod3

Canvas Control See: canvas.htm Canvas is a Node, is not visible by itself, but is not a Pane type Node so it cannot contain other nodes. Hint: Make sure the Canvas has a size and is where you think it is – otherwise you will not see anything! Winter 2016CMPE212 - Prof. McLeod4

Canvas Control, Cont. All drawing to the Canvas will take place through its GraphicsContext object: Canvas canvas = new Canvas(300, 250); // width, height GraphicsContext gc = canvas.getGraphicsContext2D(); (Also has an empty, default constructor.) Draw by setting colours first using: gc.setFill(Color.RED); // The fill colour gc.setStroke(Color.BLUE); // The line colour Winter 2016CMPE212 - Prof. McLeod5

Canvas Control, Cont. Set the line thickness using: gc.setLineWidth(5); // 5 pixels See the GraphicsContext API docs for all the drawing methods. A method starting with “stroke…” draws the outline of the shape. Starting with “fill…” draws a filled shape. Winter 2016CMPE212 - Prof. McLeod6

Canvas Control, Cont. Of interest to Assignment 4: Draw a line from (x1, y1) to (x2, y2) in pixels as doubles: gc.strokeLine(x1, y1, x2, y2); Don’t forget that the (0, 0) pixel position of a Canvas is the top, left corner of the canvas. Winter 2016CMPE212 - Prof. McLeod7

Canvas Control, Cont. A filled oval: gc.fillOval(x, y, width, height); (x, y) is the upper left corner of a rectangle enclosing the oval of size width by height. (For a circle, width==height…) Winter 2016CMPE212 - Prof. McLeod8

Canvas Control, Cont. You can draw many other shapes and curves including Bezier curves. Can also draw text. Effects such as linear and radial colour gradients can be applied by supplying LinearGradient and RadialGradient objects to the setStroke and setFill objects instead of just a single colour. The Canvas object itself can be translated, rotated and otherwise transformed in any way you can imagine. Winter 2016CMPE212 - Prof. McLeod9

Canvas Control, Cont. Display images using.drawImage() – takes an Image object. Images can be in.bmp,.jpg,.gif or.png formats. You can load an image from a local file or from a URL. Use.getPixelWriter to obtain an object that will allow you to edit individual pixels. Winter 2016CMPE212 - Prof. McLeod10

Canvas Control, Cont. Drawings are often built and edited in layers. Each layer can be a separate Canvas object. Layer them using StackPane or just Pane. Draw to each layer using individual GraphicsContext objects. Use a method like.toFront() on the Canvas layer to move it to the top. Winter 2016CMPE212 - Prof. McLeod11

Canvas Control, Cont. Mouse/cursor interaction by adding an event handler to the Canvas object and listening for a MouseEvent: canvas.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler () public void handle(MouseEvent e) { gc.fillOval(e.getX(),e.getY(),20,20); } }); Winter 2016CMPE212 - Prof. McLeod12

JavaFX Animation Lots of videos and tutorials “out there”. A couple of links to use as a starting point: m#CIHDHJHC and: _JavaFX_Timeline_Animation.htm Winter 2016CMPE212 - Prof. McLeod13

JavaFX Transition Animation Transitions can be used to animate single nodes or many nodes in parallel. A property (color, rotation, position, etc.) is changing from a start value to an end value over a specified length of time. Fairly easy to set up and useful for simpler node animations. See a code “snippet” on the next slide that moves a red rectangle 300 pixels in the x direction over 3 seconds, and back and forth, forever… Winter 2016CMPE212 - Prof. McLeod14

JavaFX Transition Animation, Cont. Rectangle rect = new Rectangle(10, 10, 100, 100); rect.setFill(Color.RED); TranslateTransition translate = new TranslateTransition(Duration.millis(3000), rect); translateTransition.setFromX(10); translateTransition.setToX(310); translate.setAutoReverse(true); translate.setCycleCount(Timeline.INDEFINITE); translate.play(); Winter 2016CMPE212 - Prof. McLeod15

JavaFX Timeline Animation Timeline animations are better suited for more complex animation. A Timeline object is constructed with a series of KeyFrame objects that are individual frame specifications along the animation. A KeyFrame is constructed using at a minimum a Duration object and at least two KeyValue objects. Optionally, an EventHandler object can be used to execute some code when the KeyFrame is finished. Winter 2016CMPE212 - Prof. McLeod16

JavaFX Timeline Animation, Cont. A KeyValue object consists of a single state for a mutable node property value. You can also add an Interpolator object, which specifies how you interpolate between KeyValues. The default Interpolator is Interpolator.LINEAR. You can specify others or define your own, which is handy for specifying a specific path if your property is a position. Winter 2016CMPE212 - Prof. McLeod17

JavaFX AnimationTimer An AnimationTimer object can be created if you wish to trigger an event every time a frame is drawn to the screen. Not directly associated with the Timeline. This is an abstract class, so you need to implement the void handle(long now) method, where now is the timestamp in nanoseconds. This method will be called at the beginning gof every frame refresh. Not to be confused with the javax.swing.Timer class! Winter 2016CMPE212 - Prof. McLeod18

JavaFX Timeline Animation, Cont. Start a Timeline by invoking.play() or even better.playFromStart(), which stops the current animation, if running, and re-starts it from the beginning. Stop a Timeline by invoking.stop(). (Platform.exit() will stop all running threads including the Timeline thread.) Start an AnimationTimer using.start() and stop it using.stop(). Winter 2016CMPE212 - Prof. McLeod19

JavaFX Timeline Animation Demo Borrowed (shamelessly!) and slightly modified from Oracle: See the TimelineDemo project. Has a filled oval and a text label in a StackPane that increments the count in the label using an AnimationTimer. The oval continuously grows and shrinks and then translates every 2 seconds. Winter 2016CMPE212 - Prof. McLeod20

JavaFX Timeline Animation Demo The label counts up to about 235, so the AnimationTimer handle method is being invoked about 117 times per second or at the rate of 117 Hz. Impressive, but is this necessary? What is the highest animation fps that you can hope for? Winter 2016CMPE212 - Prof. McLeod21

Aside – Maximum Frame Rate Common monitor refresh rates are 60 Hz, for example. There is no point in trying to update frames at any rate higher than this! So, the lowest time between frames would be: 1000 / 60 or about 17 milliseconds. A gamer would be very happy if his game updated at 60 fps. What is a more realistic expectation? How slow can an animation get before it gets “choppy”? Winter 2016CMPE212 - Prof. McLeod22

Imitating javax.swing.Timer This class creates its own thread and fires an event at specified intervals. JavaFX does not “like” this separate timer thread since it already has its own animation thread running. You can use a Timeline object to imitate a Timer object in JavaFX. Build the object using only two KeyFrame objects: Winter 2016CMPE212 - Prof. McLeod23

Imitating javax.swing.Timer, Cont. Timeline timeline = new Timeline( new KeyFrame(Duration.ZERO, actionEvent -> drawFireworks()), new KeyFrame(Duration.millis(1000 / desiredFrameRate))); timeline.setCycleCount(Timeline.INDEFINITE); If desiredFrameRate is 60 then, this timeline object will invoke the drawFireworks() method every 17 milliseconds. Winter 2016CMPE212 - Prof. McLeod24

Assignment 4 Animation, Suggestions Inside drawFireworks(), invoke.getFireworks() on the instantiated ParticleManager object. Wipe the canvas! (You could just draw a large rectangle, for example.) Draw the launch tube as a line. Iterate through the collection. A spark can be drawn as an oval, say 2 pixels in diameter. Draw a streak as a line, and the Star as a larger oval. Winter 2016CMPE212 - Prof. McLeod25