SlideShare a Scribd company logo
1 of 15
A. A. Datti 2018
HTML5 Canvas
Introduction
Drawing
Coordinate System
Gradients
Text
Images
2
The HTML <canvas> element is used to draw graphics, on
the fly, via scripting (usually JavaScript).
The <canvas> element is only a container for graphics.
You must use a script to actually draw the graphics.
Canvas has several methods for drawing paths, boxes,
circles, text, and adding images.
 Canvas can draw colorful text, with or without animation
 Canvas has great features for graphical data presentation with an imagery
of graphs and charts.
 Canvas objects can move. Everything is possible: from simple bouncing
balls to complex animations.
 Canvas can respond to JavaScript events.
 Canvas can respond to any user action (key clicks, mouse clicks, button
clicks, finger movement).
 Canvas' methods for animations, offer a lot of possibilities for HTML
gaming applications.
 In HTML, a <canvas> element looks like this:
<canvas id="myCanvas" width="200" height="100"></canvas>
 The <canvas> element must have an id attribute so it can be referred to by JavaScript.
 The width and height attribute is necessary to define the size of the canvas.
 Tip: You can have multiple <canvas> elements on one HTML page.
 By default, the <canvas> element has no border and no content.
 To add a border, use a style attribute:
<canvas id="myCanvas" width="200" height="100“ style="border:1px solid#000000;"></canvas>
 All drawing on the HTML canvas must be done with JavaScript:
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);
</script>
 Step 1: Find the Canvas Element
 First of all, you must find the <canvas> element.
 This is done by using the HTML DOM method getElementById():
var canvas = document.getElementById("myCanvas");
 Step 2: Create a Drawing Object
 Secondly, you need a drawing object for the canvas.
 The getContext() is a built-in HTML object, with properties and methods for drawing:
var ctx = canvas.getContext("2d");
 Step 3: Draw on the Canvas
 Finally, you can draw on the canvas.
 Set the fill style of the drawing object to the color red:
ctx.fillStyle = "#FF0000";
 The fillStyle property can be a CSS color, a gradient, or a pattern. The default fillStyle is
black.
 The fillRect(x,y,width,height) method draws a rectangle, filled with the fill style, on the
canvas:
ctx.fillRect(0,0,150,75);
 The HTML canvas is a two-dimensional grid.
 The upper-left corner of the canvas has the coordinates (0,0)
 In the previous chapter, you saw this method used: fillRect(0,0,150,75).
 This means: Start at the upper-left corner (0,0) and draw a 150x75 pixels
rectangle.
 Draw a Line
 To draw a straight line on a canvas, use the following methods:
 moveTo(x,y) - defines the starting point of the line
 lineTo(x,y) - defines the ending point of the line
 To actually draw the line, you must use one of the "ink" methods, like stroke().
 Define a starting point in position (0,0), and an ending point in position (200,100). Then
use the stroke() method to actually draw the line:
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.moveTo(0,0);
ctx.lineTo(200,100);
ctx.stroke();
 Draw a Circle
 To draw a circle on a canvas, use the following methods:
 beginPath() - begins a path
 arc(x,y,r,startangle,endangle) - creates an arc/curve. To create a circle with arc(): Set
start angle to 0 and end angle to 2*Math.PI. The x and y parameters define the x- and
y-coordinates of the center of the circle. The r parameter defines the radius of the
circle.
 Define a circle with the arc() method. Then use the stroke() method to actually draw
the circle:
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();
 Gradients can be used to fill rectangles, circles, lines, text, etc. Shapes on the
canvas are not limited to solid colors.
 There are two different types of gradients:
 createLinearGradient(x,y,x1,y1) - creates a linear gradient
 createRadialGradient(x,y,r,x1,y1,r1) - creates a radial/circular gradient
 Once we have a gradient object, we must add two or more color stops.
 The addColorStop() method specifies the color stops, and its position along the
gradient. Gradient positions can be anywhere between 0 to 1.
 To use the gradient, set the fillStyle or strokeStyle property to the gradient, then
draw the shape (rectangle, text, or a line).
 Using createLinearGradient()
 Create a linear gradient. Fill rectangle with the gradient:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
// Create gradient
var grd=ctx.createLinearGradient(0,0,200,0);
grd.addColorStop(0,"red");
grd.addColorStop(1,"white");
// Fill with gradient
ctx.fillStyle=grd;
ctx.fillRect(10,10,150,80);
 Using createRadialGradient():
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
// Create gradient
var grd=ctx.createRadialGradient(75,50,5,90,60,100);
grd.addColorStop(0,"red");
grd.addColorStop(1,"white");
// Fill with gradient
ctx.fillStyle = grd;
ctx.fillRect(10,10,150,80);
 To draw text on a canvas, the most important property and methods are:
 font - defines the font properties for the text
 fillText(text,x,y) - draws "filled" text on the canvas
 strokeText(text,x,y) - draws text on the canvas (no fill)
 Using fillText()
 Set font to 30px "Arial" and write a filled text on the canvas:
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText("Hello World",10,50);
 Add Color and Center Text
 Set font to 30px "Comic Sans MS" and write a filled red text in the center of the
canvas:
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Comic Sans MS";
ctx.fillStyle = "red";
ctx.textAlign = "center";
ctx.fillText("Hello World", canvas.width/2, canvas.height/2);

More Related Content

What's hot

Responsive Web Design with HTML5 and CSS3
Responsive Web Design with HTML5 and CSS3Responsive Web Design with HTML5 and CSS3
Responsive Web Design with HTML5 and CSS3
Kannika Kong
 

What's hot (20)

JAVASCRIPT PPT [Autosaved].pptx
JAVASCRIPT PPT [Autosaved].pptxJAVASCRIPT PPT [Autosaved].pptx
JAVASCRIPT PPT [Autosaved].pptx
 
Bootstrap Part - 1
Bootstrap Part - 1Bootstrap Part - 1
Bootstrap Part - 1
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by Mukesh
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
 
Introduction to React Native Workshop
Introduction to React Native WorkshopIntroduction to React Native Workshop
Introduction to React Native Workshop
 
Javascript
JavascriptJavascript
Javascript
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
CSS
CSS CSS
CSS
 
Top 11 Mobile App Development Frameworks
Top 11 Mobile App Development FrameworksTop 11 Mobile App Development Frameworks
Top 11 Mobile App Development Frameworks
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Responsive Web Design with HTML5 and CSS3
Responsive Web Design with HTML5 and CSS3Responsive Web Design with HTML5 and CSS3
Responsive Web Design with HTML5 and CSS3
 
Css
CssCss
Css
 
screen output and keyboard input in js
screen output and keyboard input in jsscreen output and keyboard input in js
screen output and keyboard input in js
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
 
Javascript
JavascriptJavascript
Javascript
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Web Standards
Web StandardsWeb Standards
Web Standards
 

Similar to HTML5 Canvas - Basics.pptx

Html5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationHtml5 Canvas Drawing and Animation
Html5 Canvas Drawing and Animation
Mindfire Solutions
 
On the tomcat drive in folder cosc210 you will find file named Paint.docx
On the tomcat drive in folder cosc210 you will find file named Paint.docxOn the tomcat drive in folder cosc210 you will find file named Paint.docx
On the tomcat drive in folder cosc210 you will find file named Paint.docx
dunhamadell
 
Chapter 02 sprite and texture
Chapter 02 sprite and textureChapter 02 sprite and texture
Chapter 02 sprite and texture
boybuon205
 

Similar to HTML5 Canvas - Basics.pptx (20)

canvas.pptx
canvas.pptxcanvas.pptx
canvas.pptx
 
canvas_1.pptx
canvas_1.pptxcanvas_1.pptx
canvas_1.pptx
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
 
HTML CANVAS
HTML CANVASHTML CANVAS
HTML CANVAS
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
Scmad Chapter06
Scmad Chapter06Scmad Chapter06
Scmad Chapter06
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 
Javascript Canvas API
Javascript Canvas APIJavascript Canvas API
Javascript Canvas API
 
Intro to HTML5 Canvas
Intro to HTML5 CanvasIntro to HTML5 Canvas
Intro to HTML5 Canvas
 
Advanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tagAdvanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tag
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Html5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationHtml5 Canvas Drawing and Animation
Html5 Canvas Drawing and Animation
 
Html canvas
Html canvasHtml canvas
Html canvas
 
On the tomcat drive in folder cosc210 you will find file named Paint.docx
On the tomcat drive in folder cosc210 you will find file named Paint.docxOn the tomcat drive in folder cosc210 you will find file named Paint.docx
On the tomcat drive in folder cosc210 you will find file named Paint.docx
 
Chapter 02 sprite and texture
Chapter 02 sprite and textureChapter 02 sprite and texture
Chapter 02 sprite and texture
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the Web
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
 

More from AhmadAbba6 (6)

Transmission Medium.pptx
Transmission Medium.pptxTransmission Medium.pptx
Transmission Medium.pptx
 
Network Models.pptx
Network  Models.pptxNetwork  Models.pptx
Network Models.pptx
 
Basic Concepts of Networking.pptx
Basic Concepts of Networking.pptxBasic Concepts of Networking.pptx
Basic Concepts of Networking.pptx
 
Introduction to Computer Graphics.pptx
Introduction to Computer Graphics.pptxIntroduction to Computer Graphics.pptx
Introduction to Computer Graphics.pptx
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
 

Recently uploaded

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
 
+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@
 
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
 

Recently uploaded (20)

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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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...
 
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
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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
 
+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...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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
 

HTML5 Canvas - Basics.pptx

  • 1. A. A. Datti 2018
  • 3. The HTML <canvas> element is used to draw graphics, on the fly, via scripting (usually JavaScript). The <canvas> element is only a container for graphics. You must use a script to actually draw the graphics. Canvas has several methods for drawing paths, boxes, circles, text, and adding images.
  • 4.  Canvas can draw colorful text, with or without animation  Canvas has great features for graphical data presentation with an imagery of graphs and charts.  Canvas objects can move. Everything is possible: from simple bouncing balls to complex animations.  Canvas can respond to JavaScript events.  Canvas can respond to any user action (key clicks, mouse clicks, button clicks, finger movement).  Canvas' methods for animations, offer a lot of possibilities for HTML gaming applications.
  • 5.  In HTML, a <canvas> element looks like this: <canvas id="myCanvas" width="200" height="100"></canvas>  The <canvas> element must have an id attribute so it can be referred to by JavaScript.  The width and height attribute is necessary to define the size of the canvas.  Tip: You can have multiple <canvas> elements on one HTML page.  By default, the <canvas> element has no border and no content.  To add a border, use a style attribute: <canvas id="myCanvas" width="200" height="100“ style="border:1px solid#000000;"></canvas>
  • 6.  All drawing on the HTML canvas must be done with JavaScript: <script> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.fillStyle = "#FF0000"; ctx.fillRect(0,0,150,75); </script>  Step 1: Find the Canvas Element  First of all, you must find the <canvas> element.  This is done by using the HTML DOM method getElementById(): var canvas = document.getElementById("myCanvas");
  • 7.  Step 2: Create a Drawing Object  Secondly, you need a drawing object for the canvas.  The getContext() is a built-in HTML object, with properties and methods for drawing: var ctx = canvas.getContext("2d");  Step 3: Draw on the Canvas  Finally, you can draw on the canvas.  Set the fill style of the drawing object to the color red: ctx.fillStyle = "#FF0000";  The fillStyle property can be a CSS color, a gradient, or a pattern. The default fillStyle is black.  The fillRect(x,y,width,height) method draws a rectangle, filled with the fill style, on the canvas: ctx.fillRect(0,0,150,75);
  • 8.  The HTML canvas is a two-dimensional grid.  The upper-left corner of the canvas has the coordinates (0,0)  In the previous chapter, you saw this method used: fillRect(0,0,150,75).  This means: Start at the upper-left corner (0,0) and draw a 150x75 pixels rectangle.
  • 9.  Draw a Line  To draw a straight line on a canvas, use the following methods:  moveTo(x,y) - defines the starting point of the line  lineTo(x,y) - defines the ending point of the line  To actually draw the line, you must use one of the "ink" methods, like stroke().  Define a starting point in position (0,0), and an ending point in position (200,100). Then use the stroke() method to actually draw the line: var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.moveTo(0,0); ctx.lineTo(200,100); ctx.stroke();
  • 10.  Draw a Circle  To draw a circle on a canvas, use the following methods:  beginPath() - begins a path  arc(x,y,r,startangle,endangle) - creates an arc/curve. To create a circle with arc(): Set start angle to 0 and end angle to 2*Math.PI. The x and y parameters define the x- and y-coordinates of the center of the circle. The r parameter defines the radius of the circle.  Define a circle with the arc() method. Then use the stroke() method to actually draw the circle: var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.arc(95,50,40,0,2*Math.PI); ctx.stroke();
  • 11.  Gradients can be used to fill rectangles, circles, lines, text, etc. Shapes on the canvas are not limited to solid colors.  There are two different types of gradients:  createLinearGradient(x,y,x1,y1) - creates a linear gradient  createRadialGradient(x,y,r,x1,y1,r1) - creates a radial/circular gradient  Once we have a gradient object, we must add two or more color stops.  The addColorStop() method specifies the color stops, and its position along the gradient. Gradient positions can be anywhere between 0 to 1.  To use the gradient, set the fillStyle or strokeStyle property to the gradient, then draw the shape (rectangle, text, or a line).
  • 12.  Using createLinearGradient()  Create a linear gradient. Fill rectangle with the gradient: var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); // Create gradient var grd=ctx.createLinearGradient(0,0,200,0); grd.addColorStop(0,"red"); grd.addColorStop(1,"white"); // Fill with gradient ctx.fillStyle=grd; ctx.fillRect(10,10,150,80);
  • 13.  Using createRadialGradient(): var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); // Create gradient var grd=ctx.createRadialGradient(75,50,5,90,60,100); grd.addColorStop(0,"red"); grd.addColorStop(1,"white"); // Fill with gradient ctx.fillStyle = grd; ctx.fillRect(10,10,150,80);
  • 14.  To draw text on a canvas, the most important property and methods are:  font - defines the font properties for the text  fillText(text,x,y) - draws "filled" text on the canvas  strokeText(text,x,y) - draws text on the canvas (no fill)  Using fillText()  Set font to 30px "Arial" and write a filled text on the canvas: var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.font = "30px Arial"; ctx.fillText("Hello World",10,50);
  • 15.  Add Color and Center Text  Set font to 30px "Comic Sans MS" and write a filled red text in the center of the canvas: var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.font = "30px Comic Sans MS"; ctx.fillStyle = "red"; ctx.textAlign = "center"; ctx.fillText("Hello World", canvas.width/2, canvas.height/2);