HTML5 Examples drawing on canvas (paths, text, video), mouse events, timed events, objects, semantic elements, etc. Jeanine Meyer Purchase College/SUNY.

Slides:



Advertisements
Similar presentations
HTML5 Overview Owen Williams owen at dynabooks daht com Owen Williams owen at dynabooks daht com.
Advertisements

Bring Life to Your Web Pages with JavaScript and HTML5 Part 2 Ole Ildsgaard Hougaard -
Cascading Style Sheets
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
Cascading Style Sheets By: Valerie Kuna. What are Cascading Style Sheets? Cascading Style Sheets (CSS) are a standard for specifying the presentation.
CSS Tips and Tricks for Designing Accessible Websites Presented by Grace Strother.
End User Computing An Introduction to CSS Sujana Jyothi Research Lab1, Callan Building, Department of Computer Science
Advance CSS (Menu and Layout) Miftahul Huda. CSS Navigation MENU It's truly remarkable what can be achieved through CSS, especially with navigation menus.
CSS normally control the html elements. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style.
Robotics Coordinates, position, orientation kinematics. HTML5 reading file. Homework: Prepare for lab. Postings.
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.
Cascading Style Sheet (CSS) Instructor: Dr. Fang (Daisy) Tang
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.
CSS/Photoshop Layouts - Quiz #5 Lecture Code:
Introduction to HTML5 Jeanine Meyer Purchase College/SUNY.
TECH2018 Multimedia and the Internet More about CSS and Page Layouts.
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.
Tutorial #3 Cascading Style Sheets. Review: Last Class Image sizing Pathnames Project Default Path Relative Path Absolute Path Blackboard Homework Submission.
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.
Chapter 12 Cascading Style Sheets: Part II The Web Warrior Guide to Web Design Technologies.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
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:
Programming Games Show your simple video. More video examples. Audio. Classwork/Homework: Produce more complex video program.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
Programming games Reprise: coin toss on canvas. Dice game rules. Global and local variables. Homework: [Catch up. Upload projects, including index.html.]
Most of the attributes of the body element specify colors for the Web page. Note: The background attribute won’t be useful till we learn about graphics.
University of Sunderland CDM105 Session 6 Dreamweaver and Multimedia Fireworks MX 2004 Creating Menus and Button images.
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.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Creating User Interfaces Recap HTML/HTML5 JavaScript features Homework: keep working on user observation studies. Review JavaScript.
Programming Games [Show Google Maps project.] Demonstrate more examples. Classwork/Homework: Decide on final project. Post proposal to moodle.
UPLOAD / DOWNLOAD april  HTML5 is just the next iteration of HTML  Previous version was technically HTML 4.01, which incorporated XHTML 1.0.
Web Development 101 Presented by John Valance
Programming games Show your virtual somethings. Demonstrate Hangman and Black Jack. Show credit card (or other form input & calculation) Homework: [Complete.
Introduction to CSS. Why CSS? CSS Provides Efficiency in Design and Updates CSS relatively easy to use Can give you more flexibility and control Faster.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
XHTML Formatting font with a style declaration. Formatting Font HTML uses the font tag to change size and family of font But… the font tag is being deprecated.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
HTML 5 Hands On By Rohit Ghatol
Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.
Cascading Style Sheets Primary readings Presentations Explain & review projects with class mates.
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.
Lab 5: More on Events and Introduction to the Canvas Tag User Interface Lab: GUI Lab Sep. 23 rd, 2013.
WEB DESIGN PRINCIPLES Dale Blasingame School of Journalism & Mass Communication Texas State University.
1 CS428 Web Engineering Lecture 07 Font, Text & Background (CSS - II)
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.
WebD Introduction to CSS By Manik Rastogi.
That Gauge is COOL! 
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Canvas Notes
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Programming Games [Show Google Maps project.] Demonstrate more examples. Classwork/Homework: Decide on final project. Post proposal to moodle. 1.
ISC440: Web Programming II Ch14: HTML5 Canvas
Creating Directions for Origami using HTML5 JavaScript or Processing
Context of what we are doing.
Graphics Canvas.
Giuseppe Attardi Università di Pisa
Catchup. Work on project.
Creating User Interfaces
Programming Games Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Show project. Classwork/Homework:
JavaScript – Let’s Draw!
Presentation transcript:

HTML5 Examples drawing on canvas (paths, text, video), mouse events, timed events, objects, semantic elements, etc. Jeanine Meyer Purchase College/SUNY Author: The Essential Guide to HTML5

Overview Background Show and explain 4 examples, focus on o drawing paths (lines & arcs), rectangles & text on canvas o semantic elements o use of CSS for font families, decoration, color of text o translate, scale coordinate system o object oriented programming to produce stub application for dragging of 'objects' using mouse events o change of cursor icon o video elements and drawing video on canvas o timed events o structured way for sequence of drawings Q & A

Background HTML5 is next new thing...still in development o canvas, video, semantic elements, events, etc. Browser support mixed o Firefox, Safari, Chrome, Opera ahead of IE o Firefox NOT always ahead, but it does have Error Console Formal W3C document is not easy to decipher...but/and many on-line sources, including you! My background: early career at IBM Research in robotics and manufacturing, now in academia, teaching math/cs, new media and also general education courses. I like programming!

Examples HTML5 logo, with scaling and use of CSS formatted footer Application stub: drawing rectangles and ovals, drag and drop Bouncing video masked to be a circle Origami

NOTE on these and other HTML5 examples You always can look at the source using the View source option in the browser. Complex examples may have separate and multiple files, especially for CSS and JavaScript. Most people are open to comments. I sometimes write tutorials...

HTML5 logo use beginPath, moveTo, lineTo, fill to draw shield built on other work (they had the x,y positions for the shield, but no HTML) and this motivated a use of translate added slider (new input type) - - use of another coordinate transformation: scale used drawing text on canvas and [regular] text used article and footer (CSS formatting)

Organization of dologo text (HTML) 5 sided orange background right hand, lighter orange part of background light gray, left hand side part of the 5: 2 paths white, right hand side of the 5: 2 paths

Code snippets for logo function changescale(val) { factorvalue = val / 100; dologo(); } function dologo() { var offsety = 80 ; ctx.restore(); ctx.save(); ctx.clearRect(0,0,600,400); ctx.scale(factorvalue,factorvalue); ctx.fillText("HTML", 31,60); ctx.translate(0,offsety);...

dologo, cont. ctx.fillStyle = "#E34C26"; // given in W3C spec ctx.beginPath(); ctx.moveTo(39, 250); ctx.lineTo(17, 0); ctx.lineTo(262, 0); ctx.lineTo(239, 250); ctx.lineTo(139, 278); ctx.closePath(); ctx.fill();....

CSS for footer, article footer {display:block; border-top: 1px solid orange; margin: 10px; font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; font-weight: bold; } article {display:block; font-family: Georgia, "Times New Roman", Times, serif; margin: 5px;} NOTES The border-top puts an orange line before footer. The two font-family directives provide back-up. The display:block directives provide the line breaks.

Building and moving shapes (stub for application) Use object style of programming + display list o Rect and Oval o constructor, draw, move, check-for- collision methods Using mouse events requires access to accurate mouse position Changed cursor icon

init (invoked by onLoad in ) function init() { canvas1 = document.getElementById('canvas'); canvas1.onmousedown = function () { return false; }; canvas1.addEventListener('mousedown',startdragging,false); ctx = canvas1.getContext("2d"); var r1 = new Rect(10,10,100,200,"red"); var s1 = new Rect(30,200, 50,50,"blue"); var oval1 = new Oval(200,350,60,2.0,1.0, "teal"); var cir1 = new Oval(300,200,100,1.0,1.0,"brown"); stuff.push(r1); stuff.push(s1); stuff.push(oval1); stuff.push(cir1); drawstuff(); }

drawstuff function function drawstuff() { ctx.clearRect(0,0,600,500); for (var i=0;i<stuff.length;i++) { stuff[i].draw(); } Code expects that each element of step will have a draw method...

Constructor function for ovals function Oval(x,y,r,hor,ver,c) { this.x = x; this.y = y; this.r = r; this.hor = hor; this.ver = ver; this.move = move; this.draw = drawoval; this.color = c; this.overcheck = checkoval; }

draw method for oval shapes function drawoval() { ctx.save(); ctx.translate(this.x,this.y); ctx.scale(this.hor,this.ver); ctx.fillStyle = this.color; ctx.beginPath(); ctx.arc(0,0,this.r,0,2*Math.PI,true); ctx.closePath(); ctx.fill(); ctx.restore(); }

definition of [what will be] overcheck method function checkoval(mx,my) { //computes positions in translated &scaled coordinate system var x1 = 0; //this is this.x - this.x var y1 = 0; var x2 = (mx-this.x)/this.hor; var y2 = (my-this.y)/this.ver; if (distsq(x1,y1,x2,y2)<=(this.r*this.r) ){ return true } else { return false } }

Video bouncing in a box Current situation for native support of video requires 3 video files for distinct codecs Use setInterval o video captured at different frames drawImage to put video on canvas with a shape (filled in paths) moving in sync to be a mask mask with hole works in Firefox, Opera but need two-paths for Chrome see props

setup including animaiton function init(){ ctx = document.getElementById('canvas').getContext('2d'); v = document.getElementById("vid"); v.addEventListener("ended",restart,false); // because loop doesn't work on FF v.width = v.videoWidth/3; v.height = v.videoHeight/3; videow = v.width; videoh = v.height; maskrad =.4*Math.min(videow,videoh); ctx.lineWidth = ballrad; ctx.strokeStyle ="rgb(200,0,50)"; ctx.fillStyle="white"; v.play(); setInterval(drawscene,50); }

Code/markup for video In body element joshuahomerun.mp4 joshuahomerun.webmvp8.webm Your browser does not accept the video tag. joshuahomerun.theora.ogv In script element, in init function... v = document.getElementById("vid"); In script element, in drawscene, strategy is erase canvas draw video ctx.drawImage(v,ballx+boxx, bally+box, v.width,v.height); draw (white) filled in path to be the mask

ctx.beginPath(); ctx.moveTo(ballx+boxx,bally+boxy); ctx.lineTo(ballx+boxx+v.width,bally+boxy); ctx.lineTo(ballx+boxx+v.width,bally+boxy+.5*v.height); ctx.lineTo(ballx+boxx+.5*v.width+maskrad, bally+boxy+.5*v.height); ctx.arc(ballx+boxx+.5*v.width,bally+boxy+.5*v.height,maskrad,0, Math.PI,true); ctx.lineTo(ballx+boxx,bally+boxy+.5*v.height); ctx.lineTo(ballx+boxx,bally+boxy); ctx.fill(); ctx.moveTo(ballx+boxx,bally+boxy+.5*v.height); ctx.lineTo(ballx+boxx,bally+boxy+v.height); ctx.lineTo(ballx+boxx+v.width,bally+boxy+v.height); ctx.lineTo(ballx+boxx+v.width,bally+boxy+.5*v.height); ctx.lineTo(ballx+boxx+.5*v.width+maskrad,bally+boxy+.5*v.height); ctx.arc(ballx+boxx+.5*v.width,bally+boxy+.5*v.height,maskrad, 0,Math.PI,false); ctx.lineTo(ballx+boxx,bally+boxy+.5*v.height); ctx.fill();

Origami General system for origami directions o mountain fold line o valley fold line o other utility functions Use array to hold steps, a step being a function that draws and a text string Geometry, trig & algebra to determine coordinates Use mainly paths on canvas plus a photograph & videos My hobby but/and great example of mathematics AND programming!

Organize steps Use steps array Each element is itself an array, consisting of the name of a function that produces the drawing (or the photo or the video) and a piece of text. var steps = [ [directions,"Diagram conventions"], [showkami,"Make quarter turn."], [diamond1,"Fold top point to bottom point."], [triangleM,"Divide line into thirds and make valley folds and unfold "], [thirds,"Fold in half to the left."],... I developed these step by step, including going back and inserting new steps demonstration of iterative design.

thirds() function thirds() { triangle(); skinnyline(ex,ey,gx,gy); skinnyline(fx,fy,hx,hy); curvedarrow(cx,cy,ax,ay,0,-20); valley(jx,jy,dx,dy,"orange"); }

The donext (step) function function donext() { if (nextstep>=steps.length) { nextstep=steps.length-1; } v.pause(); v.style.display = "none"; //erases last video played canvas1.height = 480; //restore height ctx.clearRect(0,0,cwidth,cheight); ctx.lineWidth = origwidth; steps[nextstep][0](); //invokes the function ta.innerHTML = steps[nextstep][1]; nextstep++; }

Q & A Discussion For JavaScript, Flash ActionScript, Processing, php, etc.: examples, tutorials, workshop charts, lecture charts & other materials for courses, books & papers, activities (e.g., origami), go to Contact (comments, questions, suggestions, your examples): Thank you!