Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.

Slides:



Advertisements
Similar presentations
HTML5 CANVAS.  Rectangles  Arcs  Lines  Features we won’t look at  Images  Drag and drop  Animation  Widely supported DRAWING PICTURES IN HTML.
Advertisements

Lecture # 11 JavaScript Graphics. Scalable Vector Graphics (SVG) Scalable Vector Graphics (SVG), as the name implies, are - scalable (without pixelation):
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
Programming games Classwork: Show Favorite Sites. Show coin toss. Review concepts. Crooked coin toss. Homework: Complete coin toss examples. Upload files.
Programming games More drawing. Text. Radian measure. Faces. Homework: Do your own drawings. Create index.html file. Upload work.
CANVAS Fundamentals. What is Canvas? Canvas is a medium for oil painting. One of the earliest oils on canvas is a French Madonna from Canvas is.
Introduction to HTML5 Jeanine Meyer Purchase College/SUNY.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
1 Introduction to HTML5. 2 Introductions –Lecture is based on the book: –The Essential Guide to HTML5: Using Games to learn HTML5 & JavaScript.
IT Engineering I Instructor: Rezvan Shiravi
Create Interfaces College exercise. Continue HTML5: HTML5 logo, drawing images. Coin toss. Homework: acquire video & audio.
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 Recap. Upload work (Filezilla, index.html). Drawing lines. Drawing stars. Homework: Drawing exercises.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Homework: Finish dice game.
Programming Games Show your cannonball. HTML5 video. Miro. Classwork/Homework: Acquire video, convert to multiple formats, and produce simple (just html)
Brent M. Dingle, Ph.D Game Design and Development Program Mathematics, Statistics and Computer Science University of Wisconsin - Stout HTML5 – Canvas.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
Programming Games Simulated ballistic motion: cannon ball. Classwork: Final day for midterm project and all projects for first part of class. Homework:
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.
Programming games Reprise: coin toss on canvas. Dice game rules. Global and local variables. Homework: [Catch up. Upload projects, including index.html.]
Homework: New coin toss. [Start dice game.]
Creating Interfaces Defining users. College exercise. HTML5 drawing. Homework: Post or make comment on other postings on reflection on college exercise.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Programming Games Show project. Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Homework: Do your own.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Programming Games Reprise on drawing on canvas. Jargon (concepts): objects. Demonstrate slingshot. Mouse events. Work on your cannonball. Homework: Finish.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Programming games Show shaking screen, quiz show. Calculations Homework: (Finish basic Javascript Projects) Make proposal. Work on project.
CS 174: Web Programming October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Creating Graphics for the Web Learning & Development Team Telerik Software Academy.
Programming games HTML/JavaScript basics Functions, events, forms Classwork: [Show favorite sites.] Coin toss. Homework: GET WEB SPACE. Complete coin toss.
Programming games Show your virtual somethings. Demonstrate Hangman and Black Jack. Show credit card (or other form input & calculation) Homework: [Complete.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own 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.
School of Computing and Information Systems RIA Animation, part I.
Programming Games Show slide show (on your site). Bouncing something. Video element. Bouncing video element. Bouncing video drawn on canvas. Bouncing video.
07 – HTML5 Canvas (1) Informatics Department Parahyangan Catholic University.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
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.
HTML5 ProgLan HTML5 Making a Game on the Canvas Part 1.
Game Development with JS and Canvas 2D
That Gauge is COOL! 
What is a Function Expression?
Programming games HTML/JavaScript basics Functions, events, forms
CMPE 280 Web UI Design and Development September 12 Class Meeting
Canvas Notes
Web Development & Design Foundations with HTML5 7th Edition
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
The Canvas.
Drawing Graphics in JavaScript
Context of what we are doing.
HTML5 – Canvas JavaScript Simple Drawing
Graphics Canvas.
CSc 337 Lecture 20: Canvas.
Programming games Share your plans for your virtual something.
Catchup. Work on project.
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:
JavaScript – Let’s Draw!
Presentation transcript:

Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.

What is… a function? –how is it defined? –how is it called? What is a variable?

JavaScript function definition function functionname (args if there are any) { statements }

Function call Set up to be response to the submit event— clicking on a submit button for a form A form is an html element.

Event handling Speaking in general terms about something set up a variety of ways. Set up the when this event happens, … do this, maybe call this function Terms used: –event listener –event handler –event catcher sometimes restricted to potential errors: try { } catch

Other Function calls In tag as value of href Call fun In tag as value of onClick, onMouseover or onMouseOut Set up to be called after time interval. This statement will be somewhere in the code, perhaps within another function. tid = setInterval("moveit(dx, dy)",500);

Break Show coin toss and crooked coin toss if you haven't done so already. Will then start on drawing on canvas element.

HTML5 drawing on canvas canvas is a new type of element drawing is done using what is termed the 2d context of a drawing element –This requires statement done AFTER the body is loaded can draw rectangles, paths (lines and arcs), images, text, video! –can also display video directly.

Screen geometry Origin is upper left corner!!!! units are pixels (very small) Sometimes top and sometimes y is used for vertical –vertical values increase going down the screen Sometimes left and sometimes x is used for horizontal –horizontal values increase going to the right. Screen geometry holds for Flash (and Processing)

Drawings Default color is black. Drawing done for stroke versus fill. Colors are set using –names (for 16 specific colors or_names.htm. or_names.htm –red-green-blue values, each as numbers 0 to 255 –hexadecimal

0,0, default color, 10 by 10, stroke 0,300,green,30 by 30, stroke 500,300, 50 by 50, fill 500,0,default color,20 by 20, fill rgb(200,0,100)

Four rectangles var ctx; function init() { ctx = document.getElementById('canvas').getContext('2d'); ctx.lineWidth = 2; ctx.strokeRect(0,0,10,10); ctx.fillRect(500,0,20,20); ctx.strokeStyle = "green"; ctx.fillStyle = "rgb(200,0,100)"; ctx.strokeRect(0,300,30,30); ctx.fillRect(500,300,50,50); } Your browser doesn't support the HTML5 element canvas.

Next After you get this working, change it! Put rectangles of different sizes in different places. Change colors.

Errors JavaScript is scripting language: interpret statements at execution time. –NOT compiled, with error messages Semantic errors (errors of meaning) are more difficult to detect and fix! Syntactic errors are errors of form, analogous to grammatical errors –FireFox Tools/Error Console can help Most common: bad bracketing ctx.fillStyle("rgb(200,0,100)"); fillStyle is attribute,not method

Comments The drawing is done in the init function which is called when the body element is loaded. The canvas element with id="canvas" does not exist until the body is loaded. –if there was more than one canvas element, we would use different names for the ids. Default color is black. Red green blue values each are 0 to 255 (8 bits of intensity). The strokeStyle and the fillStyle are attributes, not methods. GO: experiment with colors (by name) and rgb (note the quotation marks) and location and width and height.

More comments Drawings are …paint on the canvas. These rectangles are not objects to be moved or referenced later. Use ctx.clearRect method to erase. Need to do calculations to detect hits. –See memory game in book. Alternative is dynamic placement of html markup –See quiz, hangman.

Next drawing Paths created with arcs and line segments Arcs are portions of circles, created using radians in place of degrees. Math.PI is available for use. A complete circle can be drawn from 0 to 2*Math.PI or –Math.PI to Math.PI, etc. Arcs can be stroke or fill. workshop/wkshopsmile.htmlhttp://faculty.purchase.edu/jeanine.meyer/html5 workshop/wkshopsmile.html workshop/wkshopfrown.htmlhttp://faculty.purchase.edu/jeanine.meyer/html5 workshop/wkshopfrown.html

Angles 0 (=2*PI) PI/4 PI/2 PI PI*3/2 true means counter- clockwise!.80*PI.20 * PI

arcs ctx.arc (x of center, y of center, radius, starting angle, finishing angle, true for counter-clockwise) No drawing (ink) at the center! This is important when connecting arcs and lines. EXPERIMENT

4 distinct paths, each made up of 1 arc. Default, "red" and "brown"

Strategy Use variables with some variable values defined in terms of others. Circle face and two eyes. Smile is (partial) arc. Brown eyes and red smile. body element same as before. –You can add the code for this to your rectangles drawing.

var ctx; var headx = 100; //center of face x coord. var heady = 200; // center of face y coord. var headrad = 50; //radius of face var smileoffsetx=0; //smile center x is same as face var smileoffsety = 15; //smile center y further down var smilerad=20; // smile radius var eyeoffsety = -10; //eyes up from center var lefteyeoffsetx = -15; //left eye var righteyeoffsetx = -lefteyeoffsetx; //right var eyerad = 8; // eye radius

function init() { ctx = document.getElementById('canvas').getContext(' 2d'); ctx.lineWidth = 5; ctx.beginPath(); ctx.arc(headx,heady,headrad,0,2*Math.PI,true); ctx.closePath(); ctx.stroke(); …

ctx.strokeStyle = "red"; ctx.beginPath(); ctx.arc(headx+smileoffsetx,heady+smileoffsety, smilerad,.80*Math.PI,.20*Math.PI,true); ctx.stroke(); ctx.fillStyle = "brown"; ctx.beginPath(); ctx.arc(headx+lefteyeoffsetx,heady+eyeoffsety,eyerad, 0,2*Math.PI,true); ctx.fill(); ctx.beginPath(); ctx.arc(headx+righteyeoffsetx,heady+eyeoffsety,eyerad, 0,2*Math.PI,true); ctx.fill(); }

Homework Practice [static] drawing(s). Next class we will a new version of coin toss triggered by clicking on the canvas. Upload work to your website –create an index file with list of projects and upload using an ftp program –upload the html and, if required, any image files