Programming Games Show project. Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Homework: Do your own.

Slides:



Advertisements
Similar presentations
Pages and boxes Building quick user interfaces. learning objectives o Build a quick UI with pages and boxes o understand how pages and boxes work o click.
Advertisements

HTML5 CANVAS.  Rectangles  Arcs  Lines  Features we won’t look at  Images  Drag and drop  Animation  Widely supported DRAWING PICTURES IN HTML.
Flash Animation Using Linear Transformations By Kevin Hunter Kevin Hunter Marcus Yu Marcus Yu.
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
Programming games More drawing. Text. Radian measure. Faces. Homework: Do your own drawings. Create index.html file. Upload work.
Information Technology Center Hany Abdelwahab Computer Specialist.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Create Interfaces College exercise. Continue HTML5: HTML5 logo, drawing images. Coin toss. Homework: acquire video & audio.
JavaScript Form Validation
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.
Programming Games Review for midterm. Work session. Homework: Prepare for midterm.
Programming games Recap. Upload work (Filezilla, index.html). Drawing lines. Drawing stars. Homework: Drawing exercises.
Programming Games Basic HTML5 audio example. Catch-up. Work on basic video. Homework: Complete basic video.
Locally Edited Animations We will need 3 files to help get us started at
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
Programming Games Google Map API examples. CSS. Classwork/homework: Catch up. Upload work. Show your [more] complex Google Maps API example. Plan your.
Programming Games Simulated ballistic motion: cannon ball. Classwork: Final day for midterm project and all projects for first part of class. Homework:
Programming Games Show your simple video. More video examples. Audio. Classwork/Homework: Produce more complex video program.
HTML5 CANVAS. SAVING INFORMATION BETWEEN FUNCTION CALLS.
Art 315 Lecture 6 Dr. J. Parker. Variables Variables are one of a few key concepts in programming that must be understood. Many engineering/cs students.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
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.
Programming games Flash drawing trick(s). Past due: Your completion of rock-paper-scissors) Classwork: Bouncing ball: read tutorial. Start coding.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Programming Games Preview Video & Audio. Work on cannonball. Homework: finish cannonball!
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.
Programming games Show shaking screen, quiz show. Calculations Homework: (Finish basic Javascript Projects) Make proposal. Work on project.
Programming Games [Show Google Maps project.] Demonstrate more examples. Classwork/Homework: Decide on final project. Post proposal to moodle.
Programming games Show your virtual somethings. Demonstrate Hangman and Black Jack. Show credit card (or other form input & calculation) Homework: [Complete.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
Programming Games Logic. Slide show. Range input. Storage. Datatypes. Binary numbers. Homework: Catch up. This includes uploading projects to your server.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Unit 10 – JavaScript Validation Instructor: Brent Presley.
Programming Games Show your rock-paper-scissors. Demonstrate bouncing ball. Demonstrate and examine Bo the dog. Homework: Modify Bo to make your own.
Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Creating User Interfaces HTML5 video & audio. Role of video and audio. Homework: Complete your own [small/simple] HTML5 video and audio projects.
Computer Science I Share plans for virtual something. Text. Show my virtual dog. Classwork: Plans for your virtual something. Homework: start implementation.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Computer Science I Variables. Methods. Classwork/Homework: Re-do or do new drawing using variables & function(s). Zip folder and upload to Moodle dropbox.
Project Two Adding Scrolling Messages! Page 2.4 to 2.18 Today’s Agenda Look at scrolling message coding. Create a web page with a text box. Create a web.
School of Computing and Information Systems RIA Animation, part I.
Programming Games Reprise: credit cards. Show video projects. Demonstrate Find Daniel and Virtual Dog. Homework: [Catch up.] Post proposal for your JavaScript.
Programming Games Show slide show (on your site). Bouncing something. Video element. Bouncing video element. Bouncing video drawn on canvas. Bouncing video.
Computer Science I Text input. Transformations. Yet another jigsaw. Classwork/Homework: Create new application making use of transformations.
Computer Science I Slingshot example. ProcessingJS example. Review for midterm quiz. Classwork/Homework: study for midterm. Work on midterm project.
Creating User Interfaces Reprise on guest speaker. Usability checklists. Reprise on user- centered. Semantic tags. Responsive design. Classwork/homework:
Programming Games Reprise Credit Cards! Reprise Binary. Overall time limit, setTimeout Homework: [Show virtual something.] Make proposal as reply to my.
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.
What is a Function Expression?
MOM! Phineas and Ferb are … Aims:
Classwork: Examine and enhance falling drop(s) or make your own.
Computer Science I Variables. Methods.
Web Development & Design Foundations with HTML5 7th Edition
Web Programming– UFCFB Lecture 17
Programming Games Computer science big ideas and Computer Science jargon: review of things we have used in examples. Show virtual dog Homework: [Catch.
ISC440: Web Programming II Ch14: HTML5 Canvas
Programming games Classes and objects (used for Jigsaw, Bouncing stuff, other projects) Homework: Complete cannonball. Video or Audio. Your own project.
Context of what we are doing.
Programming games Demonstrate cannonball
Programming games Share your plans for your virtual something.
Catchup. Work on project.
Creating User Interfaces
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:
Chapter 9 Using Decisions to
JavaScript – Let’s Draw!
Presentation transcript:

Programming Games Show project. Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Homework: Do your own bouncing something.

Midterm project Due today! Will accept next class and then we move on! There will be another chance to do a project totally of your own design.

Coordinates Recall for canvas or for screen horizontal values: from the left vertical values: from the top pixel unit: very small!

Canvas path Set variable (any name your want, I chose ctx) to be ctx = document.getElementById("canvas").getContext ('2d'); Paths used to be drawn in outline (stroke) or filled in (fill) ctx.moveTo(x,y) moves to position ctx.lineTo(x,y) sets up line drawn ctx.arc(center_x, center_y, radius, starting_angle, ending_angle, true or false); Angles given in radians, NOT degrees. 90 degrees is Math.PI/2. A circle is 2*Math.PI.

Note Drawing a complete circle is easy: ctx.arc(centerx,centery,radius,0,2*Math.PI, true); OR ctx.arc(centerx,centery,radius,0,2*Math.PI, false); OR ???

Paths ctx.beginPath(); sequence of moveTo, lineTo, arc statements ctx.closePath(); NOTHING happens until: ctx.fill(); and/or ctx.stroke();

HTML5 logo Example of drawing on canvas input type="range" –May appear as text in older browsers Called graceful degradation changing coordinate system using translate and scale semantic tags html5/html5logoscale.htmlhttp://faculty.purchase.edu/jeanine.meyer/ html5/html5logoscale.html

range input AKA slider Scale percentage: Does form validation. Note the event handler

event handler function changescale(val) { factorvalue = val / 100; dologo(); } So…. You can guess that dologo uses the variable factorvalue in its code and you would be correct!

Note This is yet another way to specify an event (changing the slider) and the event handler. Flash ActionScript is more consistent: –All events specified using addEventListener

Shield

Transformations …. change origin of coordinate system or scale of coordinate system or both. –ctx.translate(x,y); –ctx.scale(xfactor, yfactor); ctx.save(); saves current system so that your code can ctx.restore(); This is done using a stack –last in, first out –restore pops the stack

Use of transformations for logo use to change scale based on input use translate to write out HTML and then 'move down' and draw the logo.

Recall on animation Produce a succession of pictures. Produced in my virtual dog, a succession of times to make decisions on the state of the dog. Use setInterval(what to do, length of interval in milliseconds) NEW (future?) alternative: window.requestAnimationFrame –look up and try. Standard seems to be unsettled. –fixed timed period of 60pfs Bouncing ball (or anything similar): re-draw canvas at the intervals –erase using clearRect( ) –draw

Tea party [Not political reference, but reference to html5/teapartytest.htmlhttp://faculty.purchase.edu/jeanine.meyer/ html5/teapartytest.html Animation (appearance of life/motion) done by continually erasing and re- drawing images on a canvas. Some images are positioned off of the canvas: not an error (in this case)

Performance issues duty cycle –Think of night watchman. Are there too many tasks to do before doing next round? battery life One approach –use second (alternate/buffer/prerender) canvas –Look up and post on moodle.

Bouncing ball Circle: html5/bouncingballinputs.html html5/bouncingballinputs.html Image: html5/bouncingballinputsimg.html html5/bouncingballinputsimg.html

How do I/you program bouncing something? You actually know how to do this! What are the tasks (subtasks) that your code needs to do?

[sub]Tasks Set up to do the drawing at intervals of time. How? Draw at a specific place on the canvas. Do a calculation (check a condition) to determine if the ball needs to bounce, namely if it is outside the box.

Speed of ball Horizontal and vertical speed set using a form. Note: some validation is done by browser. –try putting in letters The movement of the ball is done using the variables ballvx and ballvy set (changed) if and when the form is submitted.

Study source code (can also look at chapter 3 in The Essential Guide to HTML5 book) In this example, I don’t want ball to go outside of box drawn on canvas. functions are –init: initialization, invocation set by onLoad in body –moveball: invoked by init and by action of setInterval –moveandcheck: invoked by moveball –change: invocation set by onSubmit in the form

Did I need? to extract the moveandcheck code from the moveball code? –No. However, several small functions generally works better than fewer larger functions.

Drawn circle versus image Code is nearly the same. Drawing the image uses: var img = new Image(); img.src = "pearl.jpg"; //use your image …. In moveball function: ctx.drawImage(img,ballx-ballrad,bally- ballrad,2*ballrad,2*ballrad) NOTE: image needs to be positioned at its upper left corner, not the center of the ball.

Repeat: Events and Event Handling You (your code) sets up an event for which you specify an event handler. HTML & JavaScript does this in multiple ways! –HTML tags contain onLoad, onClick, onSubmit, onChange, … –JavaScript has setInterval and setTimeout –JavaScript has object.addEventListener Note: other languages, for example Flash ActionScript, has most consistent approach balltimer.addEventListener(TIMER,…)

Advice Mentally step back and think about concepts… –including realizing when things are inconsistent This will enable you to build your own projects as opposed to just remembering specific coding.

Classwork/homework Stop everything else and work on a final project. It can be a more elaborate virtual something or some elaboration on past work. –Post proposal!!! Finish your project. Last date is next class. Today's assignment is bouncing something. It can be a decorated drawn object and/or an image. Make other changes as you wish.