School of Computing and Information Systems RIA Animation, part I.

Slides:



Advertisements
Similar presentations
Bring Life to Your Web Pages with JavaScript and HTML5 Part 2 Ole Ildsgaard Hougaard -
Advertisements

HTML5 CANVAS.  Rectangles  Arcs  Lines  Features we won’t look at  Images  Drag and drop  Animation  Widely supported DRAWING PICTURES IN HTML.
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
Image Maps and Graphics Internet Basics and Far Beyond! Mrs. Wilson.
Aim: Use the given examples to record examples and our own ideas in our journal 1.Write technical examples in journal and/or participate in full.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Sequencing Miss Regan. Blood Hound  Does anyone know what the Bloodhound project is?  Video 1 Video 1  Video 2 Video 2  Link to website Link to website.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
HTML, HTML5 Canvas, JavaScript PART 3 LOOKING MORE CLOSELY AT FULL BLOWN GAME DESIGN A PATTERNED BACKGROUND (CREATED WTIH LOOPS) WITH A MOVING OBJECT CHALLENGES.
Introduction to TouchDevelop
Introduction to Scratch!
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
Programming games Recap. Upload work (Filezilla, index.html). Drawing lines. Drawing stars. Homework: Drawing exercises.
Set 7: Events and Animation IT452 Advanced Web and Internet Systems.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
HTML 5 Tutorial Chapter 5 Canvas. Canvas The tag is used to display graphics. The Canvas is a rectangular area we control each and every pixel of it.
HTML5 CANVAS. SAVING INFORMATION BETWEEN FUNCTION CALLS.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
Visual Basic .NET BASICS
XP Tutorial 1 Introduction to Macromedia Flash MX 2004.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Programming Games Show project. Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Homework: Do your own.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved.
Spring /6.831 User Interface Design and Implementation1 Lecture 24: Animation HW2 out, due next Sunday look for your evaluation assignment on.
Creating User Interfaces Recap HTML/HTML5 JavaScript features Homework: keep working on user observation studies. Review JavaScript.
Programming Games Reprise on drawing on canvas. Jargon (concepts): objects. Demonstrate slingshot. Mouse events. Work on your cannonball. Homework: Finish.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
Chapter2: Drawing a Window
Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.
Fall UI Design and Implementation1 Lecture 13: Animation.
Lab 5: More on Events and Introduction to the Canvas Tag User Interface Lab: GUI Lab Sep. 23 rd, 2013.
CS 490: Computer Graphics Graphics Programming and HTML Canvas.
08 – Canvas(2) Informatics Department Parahyangan Catholic University.
07 – HTML5 Canvas (1) Informatics Department Parahyangan Catholic University.
Dreamweaver MX. 2 Timeline Overview (p. 480) n Animations can be achieved with DHTML (__________ HTML) using JavaScript code and _____ or later browsers.
Programming games Show work on site. Work on slide show. Timed event for bouncing ball. Homework: [Finish slide show and upload to site.] Acquire a short.
Game Development with JS and Canvas 2D
Sound and more Animations
Unit 5: Canvas Painter.
What is a Function Expression?
Internet of the Past.
Scratch for Interactivity
Week 4: Introduction to Javascript
Introduction to Web programming
JavaScript and Events.
Visual Basic Properties, Methods and Events
ISC440: Web Programming II Ch14: HTML5 Canvas
Learn… Create… Program
Lesson 17: Building an App: Canvas Painter
Learn… Create… Program
Introduction to jQuery
Exercise 1 Modify some parameters in the histogram.js and see what would happen (one by one) 20 in Line 2  in Line 3  in Line 15  .9.
E-commerce Applications Development
Tutorial 10: Programming with javascript
Learn… Create… Program
Learn… Create… Program
Programming Games Reprise on drawing on canvas. Jargon (concepts): objects. Demonstrate slingshot. Mouse events. Work on animation project. Homework: Finish.
Programming Games Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Show project. Classwork/Homework:
CS7026 jQuery Events.
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
Web Programming and Design
JavaScript – Let’s Draw!
Presentation transcript:

School of Computing and Information Systems RIA Animation, part I

School of Computing and Information Systems What is it? real life is continuous, right? with modern video equipment we talk about frames with a fast enough frame rate and small changes between frames, we get the illusion of motion

School of Computing and Information Systems Animation Styles video can be recorded or authored and simply played back in an HTML canvas javascript can be used to repeatedly draw the frames of the animation macro languages can be used to create the animation using rules and a starting description

School of Computing and Information Systems Tools the HTML5 canvas object to draw the shapes javascript to write the procedural code jQuery to provide access to the DOM objects and to provide load function

School of Computing and Information Systems jQuery jQuery ready function executes after all elements have been loaded – better than javascript's onload function the.resize and.attr methods allow a convenient way to redraw the canvas when the browser dimensions have changed $('#myTag') to get access to html elements

School of Computing and Information Systems Canvas Context Methods use fillStyle and strokeStyle to change the color rect, fillRect and strokeRect to draw rectangles lines are drawn by starting a path and using lines, arcs and other methods to define the line once path is closed it can be filled to display a shape

School of Computing and Information Systems Example of Drawing a Solid Circle canvas = $("#myCanvas"); var ctx = canvas.get(0).getContext("2d"); ctx.fillStyle="rgb(23,198,45)"; ctx.beginPath(); // Start the path ctx.arc(10,25,15,0,2*Math.PI); ctx.closePath(); // Close the path ctx.fill(); // Fill the path circle at x=10, y=25, radius=15

School of Computing and Information Systems Writing the Javascript code use HTML to create a canvas element use Javascript to get canvas context: canvas = $("#myCanvas"); var ctx = canvas.get(0).getContext("2d"); use the context methods in Javascript to draw objects remember origin (0,0) is top left x y

School of Computing and Information Systems Timeouts timeouts control the frame rate basic format of timeout is (sets it only once): setTimeout(funct, milliseconds); to have a periodic timeout, use recursion: function timerThingy(){ doSomething(); setTimeout(timerThingy(),1000); }

School of Computing and Information Systems Starting and Stopping use a variable to flag whether animation is "on" use an if statement in the function that controls the timeout. If the variable is set to "on" then draw the animation. use a click method of the canvas to change the animation flag

School of Computing and Information Systems Use Objects the animated objects should be stored at javascript objects in an array all objects should have a draw method that determines when it should look like and how to move draw all objects in a loop: for(s in shapes) shapes[s].draw(ctx);

School of Computing and Information Systems Refresh Rate your app may redraw every 10 ms but the refresh rate may be less than that. to save battery, only push a new redraw when a frame is ready use requestAnimationFrame animation redraw monitor refresh

School of Computing and Information Systems User Interaction animation without user interaction can paint a picture or tell a story but it does not involve the user using keyboard or mouse events allows the user to become involved in the experience opens the possibilities to games, education, training and survey/voting

School of Computing and Information Systems Interaction for the user to interact with the objects on the canvas: – must detect what user did (click, hover, etc) – "where" they are (location of mouse) – what objects were involved programmer must poll events and compare to state and location of objects

School of Computing and Information Systems What happened jQuery has events associated with the canvas object that programmer can use to write code to respond to events mouse events: click, dblclick, mousedown, mouseover, mouseleave, many more. keyboard events include keydown, keyup and keypress (small differences)

School of Computing and Information Systems Where with mouse events a parameter can be used to determine the mouse location: canvas.click=function(e){...} the object e contains information about the mouse at the time the event fired: e.pageX is the x location of the pointer e.pageY is the y location

School of Computing and Information Systems Determining Interaction programmer is responsible for finding out if the user clicked (or hovered...) on or near an object must check every object (using arrays makes it easier) determining interaction depends on the shape of the object

School of Computing and Information Systems Rectangles and Circles rectangles are the easiest:  x1 ≤ x ≤ x2  y1 ≤ y ≤ y2 for circles use the formula (x-x1) 2 + (y-y1) 2 ≤ r 2 (x2,y2) (x,y) r (x1,y1)

School of Computing and Information Systems Triangles are a little harder B C A function triSign(x,y,x1,y1,x2,y2){ return (x - x2) * (y1 - y2) - (x1 - x2) * (y - y2); } function insideTri(t,x,y){ var sign1=triSign(x,y,t.ax,t.ay,t.bx,t.by)<0; var sign2=triSign(x,y,t.bx,t.by,t.cx,t.cy)<0; var sign3=triSign(x,y,t.cx,t.cy,t.ax,t.ay)<0; return sign1==sign2 && sign1==sign3; }

School of Computing and Information Systems Other forces for each object there should be a speed for both the x and y direction you can also have accelleration for both this allows you to simulate:  gravity  friction  wind  other forces