SlideShare a Scribd company logo
Working with Canvas
It's fun
 
<canvas> is an html tag
It is defined in HTML 5
and is already part of browsers
firefox
safari
chrome
opera
canvas is not in IE
but there are alternatives... canvas is not in IE
alternatives explorercanvas http://code.google.com/p/explorercanvas
alternatives explorercanvas http://code.google.com/p/explorercanvas
simple to use: just need to include a script tag on header of your html header <!--[if IE]><script src=&quot;excanvas.js&quot;></script><![endif]-->
alternatives Chrome Frame http://code.google.com/chrome/chromeframe
alternatives Chrome Frame http://code.google.com/chrome/chromeframe simple use: put meta tag in your html file <meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;chrome=1&quot;>
alternatives Chrome Frame http://code.google.com/chrome/chromeframe simple use: put meta tag in your html file <meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;chrome=1&quot;>
But... it's a plugin...
a little bit of history
<canvas></canvas> First introduced in browsers by Apple
<canvas></canvas> First introduced in browsers by Apple Powerup dashboard and Safari
<canvas></canvas> First introduced in browsers by Apple Powerup dashboard and Safari Later on Gecko 1.8 based browsers
<canvas></canvas> First introduced in browsers by Apple Powerup dashboard and Safari Later on Gecko 1.8 based browsers Firefox 1.5
Canvas HTML Element <canvas></canvas> width attribute
height attribute
all global attributes ex.:
<canvas id=”elm” width=”10” height=”10”></canvas>
Canvas HTMLElement Js interface HTMLCanvasElement : HTMLElement { attribute unsigned long width;
attribute unsigned long height; DOMString toDataURL(in optional DOMString type, in any... args); Object getContext(in DOMString contextId); };
Canvas JavaScript API Starting with
<canvas id=”canvas” width=”200” height=”300”></canvas>
Canvas JavaScript API Getting the Context
Canvas JavaScript API Getting the Context
<script type=”text/javascript”> var elm = document.getElementById(“canvas”);
var context = elm.getContext(“2d”); </script>
Canvas JavaScript API Simple example
Canvas JavaScript API Simple example Creating a gradient background
Canvas JavaScript API Simple example Creating a gradient background
Draw a rectangle over it
Canvas JavaScript API Simple example Creating a gradient background
Draw a rectangle over it
Apply stroke to rectangule
Canvas JavaScript API Simple example Creating a gradient background
Draw a rectangule over it
Stroke the rectangule
Insert Text
Creating a gradient background var gradient =
context.createLinearGradient(0, 0, 200, 200);
Creating a gradient background var gradient =
context.createLinearGradient(0, 0, 200, 200);
gradient.addColorStop(0, &quot;#f00&quot;);
Creating a gradient background var gradient =
context.createLinearGradient(0, 0, 200, 200);
gradient.addColorStop(0, &quot;#f00&quot;);
gradient.addColorStop(1, &quot;#fff&quot;);
Creating a gradient background var gradient =
context.createLinearGradient(0, 0, 200, 200);
gradient.addColorStop(0, &quot;#f00&quot;);
gradient.addColorStop(1, &quot;#fff&quot;);
context.fillStyle = gradient;
Creating a gradient background var gradient =
context.createLinearGradient(0, 0, 200, 200);
gradient.addColorStop(0, &quot;#f00&quot;);
gradient.addColorStop(1, &quot;#fff&quot;);
context.fillStyle = gradient;
context.fillRect(0, 0, 200, 200);
Creating a Rectangle /* Setting fill  */
Creating a Rectangle /* Setting fill  */
context.fillStyle = &quot;#0f0&quot;;
Creating a Rectangle /* Setting fill  */
context.fillStyle = &quot;#0f0&quot;;
context.fillRect(20, 20, 100, 100);
Creating a Rectangle /* Setting fill  */
context.fillStyle = &quot;#0f0&quot;;
context.fillRect(20, 20, 100, 100);
/* Setting stroke */
Creating a Rectangle /* Setting fill  */
context.fillStyle = &quot;#0f0&quot;;
context.fillRect(20, 20, 100, 100);
/* Setting stroke */
context.strokeStyle = &quot;#00f&quot;;
Creating a Rectangle /* Setting fill  */
context.fillStyle = &quot;#0f0&quot;;
context.fillRect(20, 20, 100, 100);
/* Setting stroke */
context.strokeStyle = &quot;#00f&quot;;
context.strokeRect(20, 20, 100, 100);
Show Demo Source file http://dicode.org/2009/codebits.html
Canvas JavaScript API http://html5demos.com/video-canvas
by @rem

More Related Content

PPT
Even Faster Web Sites at The Ajax Experience
PPT
Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009
PPTX
PPT
JavaScript Needn't Hurt!
PDF
Elixir/OTP for PHP developers
PPT
WordPress and Ajax
PDF
Lone StarPHP 2013 - Building Web Apps from a New Angle
PPT
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Even Faster Web Sites at The Ajax Experience
Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009
JavaScript Needn't Hurt!
Elixir/OTP for PHP developers
WordPress and Ajax
Lone StarPHP 2013 - Building Web Apps from a New Angle
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010

What's hot (20)

KEY
Geek Moot '09 -- Smarty 101
PPT
What's new in Rails 2?
ODP
JavaScript APIs In Focus
PPT
Ubiquity
PPT
Javascript tutorial
PPTX
非同期処理の通知処理 with Tatsumaki
PDF
Polymer 1.0
PDF
Ruby on Rails - The Best Track for your Start Up
PDF
Responsive Web Design e a Ubiquidade da Web
PPTX
JavaScript Advanced - Useful methods to power up your code
PPTX
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
PDF
Top 10 php classic traps php serbia
PDF
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
ODP
Perl Dancer, FPW 2010
PDF
Dancing Tutorial
PPT
Changing Template Engine
PDF
Developing for Plone using ArchGenXML / ArgoUML
PPT
JQuery: Introduction
PPT
Prototype js
PDF
Ruby on Rails 3.1: Let's bring the fun back into web programing
Geek Moot '09 -- Smarty 101
What's new in Rails 2?
JavaScript APIs In Focus
Ubiquity
Javascript tutorial
非同期処理の通知処理 with Tatsumaki
Polymer 1.0
Ruby on Rails - The Best Track for your Start Up
Responsive Web Design e a Ubiquidade da Web
JavaScript Advanced - Useful methods to power up your code
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
Top 10 php classic traps php serbia
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Perl Dancer, FPW 2010
Dancing Tutorial
Changing Template Engine
Developing for Plone using ArchGenXML / ArgoUML
JQuery: Introduction
Prototype js
Ruby on Rails 3.1: Let's bring the fun back into web programing
Ad

Viewers also liked (13)

PPTX
Canvas & Charts
PPTX
HTML CANVAS
ODP
Interactive Vector-Graphics in the Browser
 
PPTX
HTML 5_Canvas
PDF
Canvas - HTML 5
PPTX
HTML 5 Canvas & SVG
PDF
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
PDF
【J-SHIS】地震の発生確率と地震動の超過確率
PPTX
Getting Started with HTML5 in Tech Com (STC 2012)
PDF
HTML5 Canvas - The Future of Graphics on the Web
PDF
Rucksack 裝滿神奇 css 的後背包
PDF
從一個超簡單範例開始學習 Canvas
Canvas & Charts
HTML CANVAS
Interactive Vector-Graphics in the Browser
 
HTML 5_Canvas
Canvas - HTML 5
HTML 5 Canvas & SVG
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
【J-SHIS】地震の発生確率と地震動の超過確率
Getting Started with HTML5 in Tech Com (STC 2012)
HTML5 Canvas - The Future of Graphics on the Web
Rucksack 裝滿神奇 css 的後背包
從一個超簡單範例開始學習 Canvas
Ad

Similar to Working With Canvas (20)

PDF
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
PPT
Sxsw 20090314
PPT
Google在Web前端方面的经验
PPT
SXSW: Even Faster Web Sites
PDF
Google's HTML5 Work: what's next?
PPT
Even Faster Web Sites at jQuery Conference '09
PPT
Ruby & Python with Silverlight O RLY? YA RLY!
PPT
Intro to JavaFX & Widget FX
PDF
Web Vector Graphics
ODP
Non Conventional Android Programming En
ODP
Non Conventional Android Programming (English)
PPT
WordPress Development Confoo 2010
PPT
PDF
What you need to know bout html5
PPT
Oscon 20080724
PDF
Accelerated Native Mobile Development with the Ti gem
PPT
Eugene Andruszczenko: jQuery
PPT
jQuery Presentation - Refresh Events
PPTX
hacking with node.JS
PPT
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
Sxsw 20090314
Google在Web前端方面的经验
SXSW: Even Faster Web Sites
Google's HTML5 Work: what's next?
Even Faster Web Sites at jQuery Conference '09
Ruby & Python with Silverlight O RLY? YA RLY!
Intro to JavaFX & Widget FX
Web Vector Graphics
Non Conventional Android Programming En
Non Conventional Android Programming (English)
WordPress Development Confoo 2010
What you need to know bout html5
Oscon 20080724
Accelerated Native Mobile Development with the Ti gem
Eugene Andruszczenko: jQuery
jQuery Presentation - Refresh Events
hacking with node.JS
Jqueryforbeginnersjqueryconference2009 090914063709 Phpapp02

More from Diogo Antunes (6)

PDF
It works on your computer... but does it render fast enough?
PDF
Know your errors
PDF
Pocket Knife JS
PDF
PDF
Making burgers with JavaScript
PDF
Debugging your JavaScript
It works on your computer... but does it render fast enough?
Know your errors
Pocket Knife JS
Making burgers with JavaScript
Debugging your JavaScript

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Understanding_Digital_Forensics_Presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Network Security Unit 5.pdf for BCA BBA.
MIND Revenue Release Quarter 2 2025 Press Release
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Working With Canvas