SlideShare a Scribd company logo
1 of 48
Download to read offline
CANVAS
introduction to:
Tuesday, September 3, 13
Mark J. Morris
@blurredbits
presented by:
September 3, 2013
Tuesday, September 3, 13
“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
Chrome 25+
Firefox 20+
Safari 5+
IE 9.0+
Opera 9.0+
Tuesday, September 3, 13
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
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
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
Tuesday, September 3, 13
Tuesday, September 3, 13
Tuesday, September 3, 13
basic canvas method
fillRect(float x, float y, float width, float height)
Tuesday, September 3, 13
Tuesday, September 3, 13
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
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
theCanvas.fillStyle = “orange”;
theCanvas.fillStyle = “#FFA500”;
theCanvas.fillStyle = “rgb(255,165,0)”;
theCanvas.fillStyle = “rgba(255,165,0,1)”;
Tuesday, September 3, 13
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
Tuesday, September 3, 13
Text Methods
Tuesday, September 3, 13
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
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
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
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
Tuesday, September 3, 13
Line Methods
Tuesday, September 3, 13
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
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
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
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
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
Tuesday, September 3, 13
(2,1)
(2,4)
Tuesday, September 3, 13
(1.5,1)
(1.5,4)
Tuesday, September 3, 13
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
Tuesday, September 3, 13
arcs
arc(x, y, radius, startAngle, endAngle, anticlockwise)
bezier
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
quadratic
quadraticCurveTo(cp1x, cp1y, x, y)
Tuesday, September 3, 13
Image Methods
Tuesday, September 3, 13
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
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
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
Tuesday, September 3, 13
scaling
drawImage(image, x, y, width, height)
slicing
drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
Tuesday, September 3, 13
Gradients
Animations
Patterns
Shadows
Transformations
Compositing
Video
Audio
Tuesday, September 3, 13
Additional Resources
Tuesday, September 3, 13
Tuesday, September 3, 13
Tuesday, September 3, 13
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial
Tuesday, September 3, 13
Thursday 9/5
6:00pm
Crooked Cup
Tuesday, September 3, 13
Mark J. Morris
@blurredbits
Thanks!
Tuesday, September 3, 13

More Related Content

Similar to Introduction to HTML5 Canvas

Web accessibility
Web accessibilityWeb accessibility
Web accessibility
Eb Styles
 
Auto tools
Auto toolsAuto tools
Auto tools
祺 周
 

Similar to Introduction to HTML5 Canvas (20)

CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the Backend
 
The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014
 
Sencha Touch
Sencha TouchSencha Touch
Sencha Touch
 
Theming and Sass
Theming and SassTheming and Sass
Theming and Sass
 
Ext js saas&compass
Ext js saas&compassExt js saas&compass
Ext js saas&compass
 
Theming Ext JS 4
Theming Ext JS 4Theming Ext JS 4
Theming Ext JS 4
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
Web Frontend development: tools and good practices to (re)organize the chaos
Web Frontend development: tools and good practices to (re)organize the chaosWeb Frontend development: tools and good practices to (re)organize the chaos
Web Frontend development: tools and good practices to (re)organize the chaos
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricks
 
Web accessibility
Web accessibilityWeb accessibility
Web accessibility
 
Empezando con Twig
Empezando con TwigEmpezando con Twig
Empezando con Twig
 
Canvas
CanvasCanvas
Canvas
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
Yes, browsers can do that! Hybrid and future web meetup at Jayway
Yes, browsers can do that! Hybrid and future web meetup at JaywayYes, browsers can do that! Hybrid and future web meetup at Jayway
Yes, browsers can do that! Hybrid and future web meetup at Jayway
 
Auto tools
Auto toolsAuto tools
Auto tools
 
Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!
 
Next-level CSS
Next-level CSSNext-level CSS
Next-level CSS
 
GOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for that
 
CSS3 vs jQuery
CSS3 vs jQueryCSS3 vs jQuery
CSS3 vs jQuery
 
Events Lecture Notes
Events Lecture NotesEvents Lecture Notes
Events Lecture Notes
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Introduction to HTML5 Canvas