SlideShare una empresa de Scribd logo
1 de 48
Descargar para leer sin conexión
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

Más contenido relacionado

Similar a Introduction to HTML5 Canvas

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

Similar a 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
 

Último

Último (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...
 
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
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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
 
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...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Introduction to HTML5 Canvas