SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
Plunge into HTML5 Canvas – Let’s
begin
Before the arrival of HTML5 Canvas API it’s always a tough task to build complex graphs and
2D/3D designs in the website. Developers could only use drawing APIs all the way through
plug-ins like SVG (Scalable Vector Graphics) and VML (vector Markup Language) with some
specific web browsers like Internet Explorer. For example, to draw a simple diagonal line
without a canvas element is easy, but it’s a quite difficult task if you don’t have a simple 2D
drawing API at your clearance.
Canvas is just providing that, and that’s why it’s exceptionally useful feature to have in the
browser.
What is Canvas?
The Concept of Canvas is at first developed by APPLE to be used in Mac OS X WebKit to
create dashboard widgets.
In 2012, first draft of HTML5 is published as a working draft for the candidate
recommendation and Canvas (2D and 3D) is the part of the HTML5 specification. HTML5
Canvas is providing a plug-ins free paradigm for browser. It provides native support for many
features which is only possible with 3rd party plug-ins or JavaScript Hacks.
In 2012, first draft of HTML5 is published as a working draft for the candidate
recommendation and Canvas (2D and 3D) is the part of the HTML5 specification. HTML5
Canvas is providing a plug-ins free paradigm for browser. It provides native support for many
features which is only possible with 3rd party plug-ins or JavaScript Hacks.
Getting Started with HTML5 Canvas
When a canvas tag is added into the web page either statically or dynamically, it creates a
rectangular area in the page or by default rectangular area is 150 pixels high and 300 pixels
wide. User can create custom size of canvas by providing specific size. Unlike SVG, which is
vector base, canvas is pixel based.
Canvas Element
1<canvas id=”canvas1”></canvas>
After adding canvas element in your webpage you can manipulate its base on requirement
using JavaScript. User can add lines, graphics, charts, animated text within it.
If you are working with canvas dynamically/programmatically, then you have to first get its
context and perform some actions on context and finally apply those actions on the context.
Following lines of code required to get context of the canvas using the help of standard
document.getElementById Tag.
1
2
3
4
5
<script type="text/javascript">
windows.onload=function() {
var canvas = document.getElementById('canvas1');
var context = canvas=getContext("2d");};
</script>
If you are using JQuery then your code is like this,
1
2
3
4
5
<script type="text/javascript">
$(document).ready(function () {
var canvas = $('#canvas1');
var context = canvas[0].getContext("2d");
<script>
To locate a canvas object, you need to access its 2D drawing context.
W3C defines 2D drawing context in the following way,
“The 2D context represents a flat Cartesian surface whose origin (0, 0) is at the top left corner, with
the coordinate space having x values increasing when going right, and y values increasing when
going down.”
Canvas Coordinates
Coordinates in a canvas start at x=0, y=0 in the upper-left corner – which we refer as the
origin (0, 0). Using fillRect(x,y, width,height) increases the size horizontally over the x-axis
and vertically over the y-axis.
1
2
3
4
5
6
<script type="text/javascript">
windows.onload=function() {
var canvas = document.getElementById('canvas1');
var context = canvas=getContext("2d");
context.fillRect(20,20,150,100)};
</script>
Canvas – Paths
You can render any shape using HTML5 Canvas API. You can draw shapes, lines, text and
many more using HTML5 Canvas. Following are few functions which will help you to draw
shapes using canvas.
moveTo(x,y) Move the current pointer to a specific destination without drawing
lineTo(x,y) Move the current pointer to a specific destination with drawing a
straight line
stroke() Render a line
1
2
3
4
5
6
7
8
<script type="text/javascript">
windows.onload=function() {
var canvas = document.getElementById('canvas1');
var context = canvas=getContext("2d");
context.moveTo(0,0);
context.lineTo(200,100);
context.stroke();}
</script>
arc(x,y,r,start,stop) Use to render a circle with x & y coordinates, radius, starting and
ending angle.
beginPath() Start/Restart the path
1
2
3
4
5
6
7
8
<script type="text/javascript">
windows.onload=function() {
var canvas = document.getElementById('canvas1');
var context = canvas=getContext("2d");
context.beginPath();
context.arc(95,50,40,0,2*Math.PI);
context.stroke();};
</script>
closePath() Close the current path
1
2
3
4
5
6
7
8
9
10
11
<script type="text/javascript">
windows.onload=function() {
var canvas = document.getElementById('canvas1');
var context = canvas=getContext("2d");
context.beginPath();
context.moveTo(20,20);
context.lineTo(20,100);
context.lineTo(70,100);
context.closePath();
context.stroke();}
</script>
fill() Fill a shape with colour
fillStyle FillStyle is property to fill colour or gradient
1
2
3
4
5
6
7
8
9
<script type="text/javascript">
windows.onload=function() {
var canvas = document.getElementById('canvas1');
var context = canvas=getContext("2d");
context.rect(20,20,150,100);
context.fillStyle="blue";
context.fill();
context.stroke();}
</script&gt>
fillText(text,x,y) Draws a filled text
strokeText(text,x,y) Draws a text
font Property defines the font for text
fillText
1
2
3
4
5
6
7
8
<script type="text/javascript">
windows.onload=function() {
var canvas = document.getElementById('canvas1');
var context = canvas=getContext("2d");
context.font = "30px Arial";
context. fillText ("Plunge into HTML5 Canvas ",10,50);
context.stroke();}
</script>
strokeText
1
2
3
4
5
6
7
8
<script type="text/javascript">
windows.onload=function() {
var canvas = document.getElementById('canvas1');
var context = canvas=getContext("2d");
context.font = "30px Arial";
context.strokeText("Plunge into HTML5 Canvas ",10,50);
context.stroke();}
</script>
Browser Support for HTML5 Canvas
After arrival of Internet Explorer 9, almost every browser vendors are trying to provide full
support for the HTML5 Canvas but majorly available browsers are not providing full support
for HTML5 Canvas. Below is the browsers detail which tells you about that how they are
dealing with HTML5 Canvas.
Browser Description
Internet Explorer IE 8 and earlier versions do not support <canvas>
element
Google Chrome Supports <canvas> element through –webkit–
Firefox Firefox may have support via the moz setting
Safari 6 for Mac Supports <canvas> element through –webkit–
Opera Opera 15 has support of few features
If you are working with the <canvas> element than it’s a good practice to check browser
compatibility and in the case where the client’s browser is not supporting <canvas> element
then you can place other alternate text.
1
2
3
4
5
6
7
8
9
&lt;script type=&quot;text/javascript&quot;&gt;
windows.onload=function() {
try{
document.createElement(&quot;canvas1&quot;).getContext(&quot;2d&quot;);
document.getElementById(&quot;support&quot;).innerHTML =&quot;HTML5
Canvas is supported in your browser.&quot;;
} catch (e) {
document.getElementById(&quot;support&quot;).innerHTML = &quot;HTML5
Canvas is not supported in your browser.&quot;;}
};
&lt;/script&gt;
This article provides you the basic overview about the HTML5 Canvas and its different
property and more. In the upcoming article we will discuss more about HTML5 Canvas like
Background Patterns, Canvas Transforms, Canvas Security, Animation, etc. Stay Tuned!
HTML5 Canvas Let’s Begin

Contenu connexe

En vedette

ANIMALES VERTEBRADOS E INVERTEBRADOS
ANIMALES VERTEBRADOS E INVERTEBRADOSANIMALES VERTEBRADOS E INVERTEBRADOS
ANIMALES VERTEBRADOS E INVERTEBRADOSsjnacimba
 
P2 tajeddine
P2 tajeddineP2 tajeddine
P2 tajeddineAyoub1199
 
2004-10-15 SHAirED: Services for Helping the Air-quality Community use ESE Data
2004-10-15 SHAirED: Services for Helping the Air-quality Community use ESE Data2004-10-15 SHAirED: Services for Helping the Air-quality Community use ESE Data
2004-10-15 SHAirED: Services for Helping the Air-quality Community use ESE DataRudolf Husar
 
рекламный пакет
рекламный пакетрекламный пакет
рекламный пакетMarinarssk
 
гбу ро миац
гбу ро миацгбу ро миац
гбу ро миацMarinarssk
 
Pschology presentation FACTORS AFFECTING EMPLOYEES MOTIVATION ON ORGANIZATION...
Pschology presentation FACTORS AFFECTING EMPLOYEES MOTIVATION ON ORGANIZATION...Pschology presentation FACTORS AFFECTING EMPLOYEES MOTIVATION ON ORGANIZATION...
Pschology presentation FACTORS AFFECTING EMPLOYEES MOTIVATION ON ORGANIZATION...Jamshaid Chudhary
 
6 eboluzioa-sonia
6 eboluzioa-sonia6 eboluzioa-sonia
6 eboluzioa-soniasonri15
 

En vedette (18)

ANIMALES VERTEBRADOS E INVERTEBRADOS
ANIMALES VERTEBRADOS E INVERTEBRADOSANIMALES VERTEBRADOS E INVERTEBRADOS
ANIMALES VERTEBRADOS E INVERTEBRADOS
 
2016 java9-how-make-qus
2016 java9-how-make-qus2016 java9-how-make-qus
2016 java9-how-make-qus
 
Presentation on Pollution
Presentation on PollutionPresentation on Pollution
Presentation on Pollution
 
P2 tajeddine
P2 tajeddineP2 tajeddine
P2 tajeddine
 
2016 java9-how-make-qus
2016 java9-how-make-qus2016 java9-how-make-qus
2016 java9-how-make-qus
 
2004-10-15 SHAirED: Services for Helping the Air-quality Community use ESE Data
2004-10-15 SHAirED: Services for Helping the Air-quality Community use ESE Data2004-10-15 SHAirED: Services for Helping the Air-quality Community use ESE Data
2004-10-15 SHAirED: Services for Helping the Air-quality Community use ESE Data
 
Kevin auto biografia
Kevin auto biografiaKevin auto biografia
Kevin auto biografia
 
отчет
отчетотчет
отчет
 
Eu escolho
Eu escolhoEu escolho
Eu escolho
 
рекламный пакет
рекламный пакетрекламный пакет
рекламный пакет
 
гбу ро миац
гбу ро миацгбу ро миац
гбу ро миац
 
Word
WordWord
Word
 
Работы
РаботыРаботы
Работы
 
Pschology presentation FACTORS AFFECTING EMPLOYEES MOTIVATION ON ORGANIZATION...
Pschology presentation FACTORS AFFECTING EMPLOYEES MOTIVATION ON ORGANIZATION...Pschology presentation FACTORS AFFECTING EMPLOYEES MOTIVATION ON ORGANIZATION...
Pschology presentation FACTORS AFFECTING EMPLOYEES MOTIVATION ON ORGANIZATION...
 
Ucp presentation
Ucp presentationUcp presentation
Ucp presentation
 
Ogum
OgumOgum
Ogum
 
Badô de osoosi
Badô de osoosiBadô de osoosi
Badô de osoosi
 
6 eboluzioa-sonia
6 eboluzioa-sonia6 eboluzioa-sonia
6 eboluzioa-sonia
 

Similaire à HTML5 Canvas Let’s Begin

New Elements & Features in HTML5
New Elements & Features in HTML5New Elements & Features in HTML5
New Elements & Features in HTML5Jamshid Hashimi
 
Academy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphicsAcademy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphicsBinary Studio
 
Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009
Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009
Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009Ramon Durães
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVDFramgia Vietnam
 
Speak the Web 15.02.2010
Speak the Web 15.02.2010Speak the Web 15.02.2010
Speak the Web 15.02.2010Patrick Lauke
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 CanvasHenry Osborne
 
Rich Media Advertising with SVG and JavaScript
Rich Media Advertising with SVG and JavaScriptRich Media Advertising with SVG and JavaScript
Rich Media Advertising with SVG and JavaScriptGjokica Zafirovski
 
Building a game engine with jQuery
Building a game engine with jQueryBuilding a game engine with jQuery
Building a game engine with jQueryPaul Bakaus
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Patrick Chanezon
 
Javascript #10 : canvas
Javascript #10 : canvasJavascript #10 : canvas
Javascript #10 : canvasJean Michel
 

Similaire à HTML5 Canvas Let’s Begin (20)

Canvas in html5
Canvas in html5Canvas in html5
Canvas in html5
 
New Elements & Features in HTML5
New Elements & Features in HTML5New Elements & Features in HTML5
New Elements & Features in HTML5
 
Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
 
Html5
Html5Html5
Html5
 
Html5
Html5Html5
Html5
 
Academy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphicsAcademy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphics
 
Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009
Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009
Introdução ao Microsoft Silverlight 2.0 - Campus Party Brasil 2009
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVD
 
HTML5 canvas
HTML5 canvasHTML5 canvas
HTML5 canvas
 
Html5
Html5Html5
Html5
 
Speak the Web 15.02.2010
Speak the Web 15.02.2010Speak the Web 15.02.2010
Speak the Web 15.02.2010
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
 
Rich Media Advertising with SVG and JavaScript
Rich Media Advertising with SVG and JavaScriptRich Media Advertising with SVG and JavaScript
Rich Media Advertising with SVG and JavaScript
 
Building a game engine with jQuery
Building a game engine with jQueryBuilding a game engine with jQuery
Building a game engine with jQuery
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 
Working With Canvas
Working With CanvasWorking With Canvas
Working With Canvas
 
Html 5
Html 5Html 5
Html 5
 
Javascript #10 : canvas
Javascript #10 : canvasJavascript #10 : canvas
Javascript #10 : canvas
 
Html5
Html5Html5
Html5
 

Plus de Azilen Technologies Pvt. Ltd.

[Step by-step guide] configure document generation functionality in ms dynami...
[Step by-step guide] configure document generation functionality in ms dynami...[Step by-step guide] configure document generation functionality in ms dynami...
[Step by-step guide] configure document generation functionality in ms dynami...Azilen Technologies Pvt. Ltd.
 
How to overcome operational challenges in getting consistent beacon behavior
How to overcome operational challenges in getting consistent beacon behaviorHow to overcome operational challenges in getting consistent beacon behavior
How to overcome operational challenges in getting consistent beacon behaviorAzilen Technologies Pvt. Ltd.
 
Realm mobile platform – explore real time data synchronization capabilities
Realm mobile platform – explore real time data synchronization capabilitiesRealm mobile platform – explore real time data synchronization capabilities
Realm mobile platform – explore real time data synchronization capabilitiesAzilen Technologies Pvt. Ltd.
 
A step by step guide to develop temperature sensor io t application using ibm...
A step by step guide to develop temperature sensor io t application using ibm...A step by step guide to develop temperature sensor io t application using ibm...
A step by step guide to develop temperature sensor io t application using ibm...Azilen Technologies Pvt. Ltd.
 
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...Azilen Technologies Pvt. Ltd.
 
Server driven user interface (sdui) – framework for i os applications!
Server driven user interface (sdui) – framework for i os applications!Server driven user interface (sdui) – framework for i os applications!
Server driven user interface (sdui) – framework for i os applications!Azilen Technologies Pvt. Ltd.
 
How to integrate portlet as widget in liferay to any website application
How to integrate portlet as widget in liferay to any website applicationHow to integrate portlet as widget in liferay to any website application
How to integrate portlet as widget in liferay to any website applicationAzilen Technologies Pvt. Ltd.
 
iPad Application as Return Process Automation Solution for eCommerce Store
iPad Application as Return Process Automation Solution for eCommerce StoreiPad Application as Return Process Automation Solution for eCommerce Store
iPad Application as Return Process Automation Solution for eCommerce StoreAzilen Technologies Pvt. Ltd.
 
[Part 3] automation of home appliances using raspberry pi – all set to automa...
[Part 3] automation of home appliances using raspberry pi – all set to automa...[Part 3] automation of home appliances using raspberry pi – all set to automa...
[Part 3] automation of home appliances using raspberry pi – all set to automa...Azilen Technologies Pvt. Ltd.
 
Rfid systems for asset management — the young technology on its winning path
Rfid systems for asset management — the young technology on its winning pathRfid systems for asset management — the young technology on its winning path
Rfid systems for asset management — the young technology on its winning pathAzilen Technologies Pvt. Ltd.
 
[Part 2] automation of home appliances using raspberry pi – implementation of...
[Part 2] automation of home appliances using raspberry pi – implementation of...[Part 2] automation of home appliances using raspberry pi – implementation of...
[Part 2] automation of home appliances using raspberry pi – implementation of...Azilen Technologies Pvt. Ltd.
 
[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...Azilen Technologies Pvt. Ltd.
 

Plus de Azilen Technologies Pvt. Ltd. (20)

Software Product Development for Startups.pdf
Software Product Development for Startups.pdfSoftware Product Development for Startups.pdf
Software Product Development for Startups.pdf
 
How Chatbots Empower Healthcare Ecosystem?
How Chatbots Empower Healthcare Ecosystem?How Chatbots Empower Healthcare Ecosystem?
How Chatbots Empower Healthcare Ecosystem?
 
[Step by-step guide] configure document generation functionality in ms dynami...
[Step by-step guide] configure document generation functionality in ms dynami...[Step by-step guide] configure document generation functionality in ms dynami...
[Step by-step guide] configure document generation functionality in ms dynami...
 
How to overcome operational challenges in getting consistent beacon behavior
How to overcome operational challenges in getting consistent beacon behaviorHow to overcome operational challenges in getting consistent beacon behavior
How to overcome operational challenges in getting consistent beacon behavior
 
Liferay dxp – the good, the bad and the ugly
Liferay dxp – the good, the bad and the uglyLiferay dxp – the good, the bad and the ugly
Liferay dxp – the good, the bad and the ugly
 
Realm mobile platform – explore real time data synchronization capabilities
Realm mobile platform – explore real time data synchronization capabilitiesRealm mobile platform – explore real time data synchronization capabilities
Realm mobile platform – explore real time data synchronization capabilities
 
A step by step guide to develop temperature sensor io t application using ibm...
A step by step guide to develop temperature sensor io t application using ibm...A step by step guide to develop temperature sensor io t application using ibm...
A step by step guide to develop temperature sensor io t application using ibm...
 
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
 
Register Virtual Device and analyze the device data
Register Virtual Device and analyze the device dataRegister Virtual Device and analyze the device data
Register Virtual Device and analyze the device data
 
Analytics and etl based bi solutions
Analytics and etl based bi solutionsAnalytics and etl based bi solutions
Analytics and etl based bi solutions
 
Advanced risk management &amp; mitigation system
Advanced risk management &amp; mitigation systemAdvanced risk management &amp; mitigation system
Advanced risk management &amp; mitigation system
 
Server driven user interface (sdui) – framework for i os applications!
Server driven user interface (sdui) – framework for i os applications!Server driven user interface (sdui) – framework for i os applications!
Server driven user interface (sdui) – framework for i os applications!
 
How to integrate portlet as widget in liferay to any website application
How to integrate portlet as widget in liferay to any website applicationHow to integrate portlet as widget in liferay to any website application
How to integrate portlet as widget in liferay to any website application
 
A walkthrough of recently held wwdc17
A walkthrough of recently held wwdc17A walkthrough of recently held wwdc17
A walkthrough of recently held wwdc17
 
How wearable devices are changing our lives
How wearable devices are changing our livesHow wearable devices are changing our lives
How wearable devices are changing our lives
 
iPad Application as Return Process Automation Solution for eCommerce Store
iPad Application as Return Process Automation Solution for eCommerce StoreiPad Application as Return Process Automation Solution for eCommerce Store
iPad Application as Return Process Automation Solution for eCommerce Store
 
[Part 3] automation of home appliances using raspberry pi – all set to automa...
[Part 3] automation of home appliances using raspberry pi – all set to automa...[Part 3] automation of home appliances using raspberry pi – all set to automa...
[Part 3] automation of home appliances using raspberry pi – all set to automa...
 
Rfid systems for asset management — the young technology on its winning path
Rfid systems for asset management — the young technology on its winning pathRfid systems for asset management — the young technology on its winning path
Rfid systems for asset management — the young technology on its winning path
 
[Part 2] automation of home appliances using raspberry pi – implementation of...
[Part 2] automation of home appliances using raspberry pi – implementation of...[Part 2] automation of home appliances using raspberry pi – implementation of...
[Part 2] automation of home appliances using raspberry pi – implementation of...
 
[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...
 

Dernier

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 

Dernier (20)

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 

HTML5 Canvas Let’s Begin

  • 1. Plunge into HTML5 Canvas – Let’s begin Before the arrival of HTML5 Canvas API it’s always a tough task to build complex graphs and 2D/3D designs in the website. Developers could only use drawing APIs all the way through plug-ins like SVG (Scalable Vector Graphics) and VML (vector Markup Language) with some specific web browsers like Internet Explorer. For example, to draw a simple diagonal line without a canvas element is easy, but it’s a quite difficult task if you don’t have a simple 2D drawing API at your clearance. Canvas is just providing that, and that’s why it’s exceptionally useful feature to have in the browser. What is Canvas? The Concept of Canvas is at first developed by APPLE to be used in Mac OS X WebKit to create dashboard widgets. In 2012, first draft of HTML5 is published as a working draft for the candidate recommendation and Canvas (2D and 3D) is the part of the HTML5 specification. HTML5 Canvas is providing a plug-ins free paradigm for browser. It provides native support for many features which is only possible with 3rd party plug-ins or JavaScript Hacks.
  • 2. In 2012, first draft of HTML5 is published as a working draft for the candidate recommendation and Canvas (2D and 3D) is the part of the HTML5 specification. HTML5 Canvas is providing a plug-ins free paradigm for browser. It provides native support for many features which is only possible with 3rd party plug-ins or JavaScript Hacks. Getting Started with HTML5 Canvas When a canvas tag is added into the web page either statically or dynamically, it creates a rectangular area in the page or by default rectangular area is 150 pixels high and 300 pixels wide. User can create custom size of canvas by providing specific size. Unlike SVG, which is vector base, canvas is pixel based. Canvas Element 1&lt;canvas id=”canvas1”&gt;&lt;/canvas&gt; After adding canvas element in your webpage you can manipulate its base on requirement using JavaScript. User can add lines, graphics, charts, animated text within it. If you are working with canvas dynamically/programmatically, then you have to first get its context and perform some actions on context and finally apply those actions on the context. Following lines of code required to get context of the canvas using the help of standard document.getElementById Tag. 1 2 3 4 5 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { var canvas = document.getElementById('canvas1'); var context = canvas=getContext(&quot;2d&quot;);}; &lt;/script&gt; If you are using JQuery then your code is like this, 1 2 3 4 5 &lt;script type=&quot;text/javascript&quot;&gt; $(document).ready(function () { var canvas = $('#canvas1'); var context = canvas[0].getContext(&quot;2d&quot;); &lt;script&gt; To locate a canvas object, you need to access its 2D drawing context. W3C defines 2D drawing context in the following way, “The 2D context represents a flat Cartesian surface whose origin (0, 0) is at the top left corner, with the coordinate space having x values increasing when going right, and y values increasing when going down.” Canvas Coordinates
  • 3. Coordinates in a canvas start at x=0, y=0 in the upper-left corner – which we refer as the origin (0, 0). Using fillRect(x,y, width,height) increases the size horizontally over the x-axis and vertically over the y-axis. 1 2 3 4 5 6 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { var canvas = document.getElementById('canvas1'); var context = canvas=getContext(&quot;2d&quot;); context.fillRect(20,20,150,100)}; &lt;/script&gt; Canvas – Paths You can render any shape using HTML5 Canvas API. You can draw shapes, lines, text and many more using HTML5 Canvas. Following are few functions which will help you to draw shapes using canvas. moveTo(x,y) Move the current pointer to a specific destination without drawing lineTo(x,y) Move the current pointer to a specific destination with drawing a straight line stroke() Render a line 1 2 3 4 5 6 7 8 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { var canvas = document.getElementById('canvas1'); var context = canvas=getContext(&quot;2d&quot;); context.moveTo(0,0); context.lineTo(200,100); context.stroke();} &lt;/script&gt; arc(x,y,r,start,stop) Use to render a circle with x & y coordinates, radius, starting and ending angle. beginPath() Start/Restart the path 1 2 3 4 5 6 7 8 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { var canvas = document.getElementById('canvas1'); var context = canvas=getContext(&quot;2d&quot;); context.beginPath(); context.arc(95,50,40,0,2*Math.PI); context.stroke();}; &lt;/script&gt; closePath() Close the current path
  • 4. 1 2 3 4 5 6 7 8 9 10 11 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { var canvas = document.getElementById('canvas1'); var context = canvas=getContext(&quot;2d&quot;); context.beginPath(); context.moveTo(20,20); context.lineTo(20,100); context.lineTo(70,100); context.closePath(); context.stroke();} &lt;/script&gt; fill() Fill a shape with colour fillStyle FillStyle is property to fill colour or gradient 1 2 3 4 5 6 7 8 9 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { var canvas = document.getElementById('canvas1'); var context = canvas=getContext(&quot;2d&quot;); context.rect(20,20,150,100); context.fillStyle=&quot;blue&quot;; context.fill(); context.stroke();} &lt;/script&amp;gt&gt; fillText(text,x,y) Draws a filled text strokeText(text,x,y) Draws a text font Property defines the font for text fillText 1 2 3 4 5 6 7 8 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { var canvas = document.getElementById('canvas1'); var context = canvas=getContext(&quot;2d&quot;); context.font = &quot;30px Arial&quot;; context. fillText (&quot;Plunge into HTML5 Canvas &quot;,10,50); context.stroke();} &lt;/script&gt; strokeText 1 2 3 4 5 6 7 8 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { var canvas = document.getElementById('canvas1'); var context = canvas=getContext(&quot;2d&quot;); context.font = &quot;30px Arial&quot;; context.strokeText(&quot;Plunge into HTML5 Canvas &quot;,10,50); context.stroke();} &lt;/script&gt; Browser Support for HTML5 Canvas After arrival of Internet Explorer 9, almost every browser vendors are trying to provide full support for the HTML5 Canvas but majorly available browsers are not providing full support
  • 5. for HTML5 Canvas. Below is the browsers detail which tells you about that how they are dealing with HTML5 Canvas. Browser Description Internet Explorer IE 8 and earlier versions do not support <canvas> element Google Chrome Supports <canvas> element through –webkit– Firefox Firefox may have support via the moz setting Safari 6 for Mac Supports <canvas> element through –webkit– Opera Opera 15 has support of few features If you are working with the <canvas> element than it’s a good practice to check browser compatibility and in the case where the client’s browser is not supporting <canvas> element then you can place other alternate text. 1 2 3 4 5 6 7 8 9 &lt;script type=&quot;text/javascript&quot;&gt; windows.onload=function() { try{ document.createElement(&quot;canvas1&quot;).getContext(&quot;2d&quot;); document.getElementById(&quot;support&quot;).innerHTML =&quot;HTML5 Canvas is supported in your browser.&quot;; } catch (e) { document.getElementById(&quot;support&quot;).innerHTML = &quot;HTML5 Canvas is not supported in your browser.&quot;;} }; &lt;/script&gt; This article provides you the basic overview about the HTML5 Canvas and its different property and more. In the upcoming article we will discuss more about HTML5 Canvas like Background Patterns, Canvas Transforms, Canvas Security, Animation, etc. Stay Tuned!