Introduction to HTML5 Canvas
-
Upload
mark-morris -
Category
Technology
-
view
1.373 -
download
1
description
Transcript of Introduction to HTML5 Canvas
![Page 1: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/1.jpg)
CANVASintroduction to:
Tuesday, September 3, 13
![Page 2: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/2.jpg)
Mark J. Morris @blurredbits
presented by:
September 3, 2013
Tuesday, September 3, 13
![Page 3: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/3.jpg)
“Added in HTML5, the HTML <canvas> element is an element which can be used to draw graphics via scripting (usually Javascript).”
Tuesday, September 3, 13
![Page 4: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/4.jpg)
Chrome 25+
Firefox 20+
Safari 5+
IE 9.0+
Opera 9.0+
Tuesday, September 3, 13
![Page 5: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/5.jpg)
index.html
<!DOCTYPE html><html><head><title>Canvas Intro</title><link rel=”stylesheet” href=”css/style.css”>
</head><body>
<script src=”js/canvas.js”></script></body>
</html>
Tuesday, September 3, 13
![Page 6: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/6.jpg)
index.html
<!DOCTYPE html><html><head><title>Canvas Intro</title><link rel=”stylesheet” href=”css/style.css”>
</head><body>
<script src=”js/canvas.js”></script></body>
</html>
<canvas id=”intro” width=300 height=150>
</canvas>
Tuesday, September 3, 13
![Page 7: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/7.jpg)
index.html
<!DOCTYPE html><html><head><title>Canvas Intro</title><link rel=”stylesheet” href=”css/style.css”>
</head><body>
<script src=”js/canvas.js”></script></body>
</html>
<canvas id=”intro” width=300 height=150>
</canvas><p>Oh noes! No canvas support!</p>
Tuesday, September 3, 13
![Page 8: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/8.jpg)
Tuesday, September 3, 13
![Page 9: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/9.jpg)
Tuesday, September 3, 13
![Page 10: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/10.jpg)
Tuesday, September 3, 13
![Page 11: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/11.jpg)
basic canvas method
fillRect(float x, float y, float width, float height)
Tuesday, September 3, 13
![Page 12: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/12.jpg)
Tuesday, September 3, 13
![Page 13: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/13.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
theCanvas.fillStyle = "rgb(160, 160, 160)";theCanvas.fillRect(0, 0, 50, 50);
Tuesday, September 3, 13
![Page 14: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/14.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
theCanvas.fillStyle = "rgb(160, 160, 160)";theCanvas.fillRect(0, 0, 50, 50);
Tuesday, September 3, 13
![Page 15: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/15.jpg)
theCanvas.fillStyle = “orange”;
theCanvas.fillStyle = “#FFA500”;
theCanvas.fillStyle = “rgb(255,165,0)”;
theCanvas.fillStyle = “rgba(255,165,0,1)”;
Tuesday, September 3, 13
![Page 16: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/16.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
theCanvas.fillStyle = "rgb(160, 160, 160)";theCanvas.fillRect(0, 0, 50, 50);
Tuesday, September 3, 13
![Page 17: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/17.jpg)
Tuesday, September 3, 13
![Page 18: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/18.jpg)
Text Methods
Tuesday, September 3, 13
![Page 19: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/19.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!
! theCanvas.fillStyle = "blue";! theCanvas.font = "30px Arial";! theCanvas.textBaseline = "top";! theCanvas.fillText("Fort Collins", 0, 0);! theCanvas.fillStyle = "red";! theCanvas.fillText("Internet", 0, 50);! theCanvas.fillStyle = "blue";! theCanvas.fillText("Pros",0,100);
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 20: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/20.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!
! theCanvas.fillStyle = "blue";! theCanvas.font = "30px Arial";! theCanvas.textBaseline = "top";! theCanvas.fillText("Fort Collins", 0, 0);! theCanvas.fillStyle = "red";! theCanvas.fillText("Internet", 0, 50);! theCanvas.fillStyle = "blue";! theCanvas.fillText("Pros",0,100);
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 21: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/21.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!
! theCanvas.fillStyle = "blue";! theCanvas.font = "30px Arial";! theCanvas.textBaseline = "top";! theCanvas.fillText("Fort Collins", 0, 0);! theCanvas.fillStyle = "red";! theCanvas.fillText("Internet", 0, 50);! theCanvas.fillStyle = "blue";! theCanvas.fillText("Pros",0,100);
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 22: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/22.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!
! theCanvas.fillStyle = "blue";! theCanvas.font = "30px Arial";! theCanvas.textBaseline = "top";! theCanvas.fillText("Fort Collins", 0, 0);! theCanvas.fillStyle = "red";! theCanvas.fillText("Internet", 0, 50);! theCanvas.fillStyle = "blue";! theCanvas.fillText("Pros",0,100);
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 23: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/23.jpg)
Tuesday, September 3, 13
![Page 24: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/24.jpg)
Line Methods
Tuesday, September 3, 13
![Page 25: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/25.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!! theCanvas.beginPath();! theCanvas.moveTo(50, 25);! theCanvas.lineTo(50, 125);! theCanvas.lineTo(150, 125);! theCanvas.closePath();! theCanvas.stroke();
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 26: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/26.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!! theCanvas.beginPath();! theCanvas.moveTo(50, 25);! theCanvas.lineTo(50, 125);! theCanvas.lineTo(150, 125);! theCanvas.closePath();! theCanvas.stroke();
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 27: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/27.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!! theCanvas.beginPath();! theCanvas.moveTo(50, 25);! theCanvas.lineTo(50, 125);! theCanvas.lineTo(150, 125);! theCanvas.closePath();! theCanvas.stroke();
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 28: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/28.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!! theCanvas.beginPath();! theCanvas.moveTo(50, 25);! theCanvas.lineTo(50, 125);! theCanvas.lineTo(150, 125);! theCanvas.closePath();! theCanvas.stroke();
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 29: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/29.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!! theCanvas.beginPath();! theCanvas.moveTo(50, 25);! theCanvas.lineTo(50, 125);! theCanvas.lineTo(150, 125);! theCanvas.closePath();! theCanvas.stroke();
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 30: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/30.jpg)
Tuesday, September 3, 13
![Page 31: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/31.jpg)
(2,1)
(2,4)
Tuesday, September 3, 13
![Page 32: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/32.jpg)
(1.5,1)
(1.5,4)
Tuesday, September 3, 13
![Page 33: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/33.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
!! theCanvas.beginPath();! theCanvas.moveTo(50.5, 25.5);! theCanvas.lineTo(50.5, 125.5);! theCanvas.lineTo(150.5, 125.5);! theCanvas.closePath();! theCanvas.stroke();
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 34: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/34.jpg)
Tuesday, September 3, 13
![Page 35: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/35.jpg)
arcsarc(x, y, radius, startAngle, endAngle, anticlockwise)
bezierbezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
quadraticquadraticCurveTo(cp1x, cp1y, x, y)
Tuesday, September 3, 13
![Page 36: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/36.jpg)
Image Methods
Tuesday, September 3, 13
![Page 37: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/37.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
! var img = new Image(); img.src = 'https://mdn.mozillademos.org/files/5397/rhino.jpg';! img.onload = function(){! ! theCanvas.drawImage(img,0,0);!! };
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 38: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/38.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
! var img = new Image(); img.src = 'https://mdn.mozillademos.org/files/5397/rhino.jpg';! img.onload = function(){! ! theCanvas.drawImage(img,0,0);!! };
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 39: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/39.jpg)
js/canvas.js
window.onload = canvasApp();
function canvasApp () {
}
! var img = new Image(); img.src = 'https://mdn.mozillademos.org/files/5397/rhino.jpg';! img.onload = function(){! ! theCanvas.drawImage(img,0,0);!! };
var theCanvas = document.getElementById(‘intro’).getContext(‘2d’);
Tuesday, September 3, 13
![Page 40: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/40.jpg)
Tuesday, September 3, 13
![Page 41: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/41.jpg)
scalingdrawImage(image, x, y, width, height)
slicingdrawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
Tuesday, September 3, 13
![Page 42: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/42.jpg)
GradientsAnimationsPatternsShadowsTransformationsCompositingVideoAudio
Tuesday, September 3, 13
![Page 43: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/43.jpg)
Additional Resources
Tuesday, September 3, 13
![Page 44: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/44.jpg)
Tuesday, September 3, 13
![Page 45: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/45.jpg)
Tuesday, September 3, 13
![Page 46: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/46.jpg)
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial
Tuesday, September 3, 13
![Page 47: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/47.jpg)
Thursday 9/56:00pm
Crooked Cup
Tuesday, September 3, 13
![Page 48: Introduction to HTML5 Canvas](https://reader031.fdocuments.us/reader031/viewer/2022020115/554f406ab4c90572088b52a5/html5/thumbnails/48.jpg)
Mark J. Morris @blurredbits
Thanks!
Tuesday, September 3, 13