SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie Introduction to HTML5 Canvas

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

Ähnlich wie 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
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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
 
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
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Introduction to HTML5 Canvas