{"id":2468,"date":"2015-02-19T18:15:58","date_gmt":"2015-02-19T16:15:58","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=2468"},"modified":"2018-06-20T12:38:12","modified_gmt":"2018-06-20T09:38:12","slug":"html-graphics-animation-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/","title":{"rendered":"HTML5 Graphics and Animation Example"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Animation is the visualization of change, having reference points for the start and end states for comparison. Before HTML 5, it was limited to usage of Adobe Flash, CSS and JavaScript mostly. In this tutorial we will introduce the HTML <code>canvas<\/code> element and the <code>requestAnimationFrame<\/code> function in JavaScript to help us create simple animations.<\/p>\n<p>[ulp id=&#8217;tgm4cmEWcKUikZNn&#8217;]<\/p>\n<p>The HTML <code>canvas<\/code> element (introduced in HTML5) is a <strong>container<\/strong> for canvas graphics and defined as a resolution-dependent bitmap canvas which can be used for rendering graphs, game graphics, or other visual images on the fly. It is a rectangular area inside a HTML page with no content or border of its own.<\/p>\n<p>JavaScript can be used to draw anything you want on the canvas. It has several methods for drawing paths, boxes, circles, text, and graphic images.You can have more than one <code>canvas<\/code> element on the same page. Each canvas will show up in the DOM, and each canvas maintains its own state. If you give each canvas an id attribute, you can access them just like any other element.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;canvas id =&quot;a&quot; width=&quot;300&quot; height=&quot;225&quot;&gt;&lt;\/canvas&gt;\r\n<\/pre>\n<p>Now you can easily find that <code>canvas<\/code> element in the DOM with JavaScript, create a context, and then utilize the Canvas API in HTML 5 to draw visualizations<\/p>\n<p>The <code>requestAnimationFrame<\/code> function requests the browser to call the animation loop at the time of redrawing the screen. Previously, developing animation with Javascript was a bit clunky as compared to ones created with CSS as you had to work with <code>setInterval<\/code> and <code>setTimeOut<\/code> to power your animation loop. There were problems in repainting the screen. With this new function, those problems are all gone and we are able to produce polished animation using the HTML 5 and javascript alone.<\/p>\n<p>The canvas element is supported in the following browser versions or above.<\/p>\n<ul>\n<li>Google Chrome 4.0<\/li>\n<li>IE 9.0<\/li>\n<li>Firefox 2.0<\/li>\n<li>Safari 3.1<\/li>\n<li>Opera 9.0<\/li>\n<\/ul>\n<p>The <code>requestAnimationFrame<\/code> is supported by the following browsers versions or above.<\/p>\n<ul>\n<li>Google Chrome 10.0<\/li>\n<li>IE 10<\/li>\n<li>Firefox 4.0<\/li>\n<li>Safari 6.0<\/li>\n<li>Opera 15.0<\/li>\n<\/ul>\n<h2>Canvas element and context<\/h2>\n<p>We need to understand the difference between Canvas element and Canvas context. While the element is a node in DOM, the context is the object with properties and methods that you can use to represent graphics inside canvas element. The context can be <code>2d<\/code> or <code>webgl<\/code> (3d). You need to use the <code>getContext<\/code> method to return a reference to a Context object<\/p>\n<p>In the following sections we will use various Canvas properties and methods. Here is a screenshot of what we will be developing today.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_2515\" aria-describedby=\"caption-attachment-2515\" style=\"width: 690px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/02\/HtmlCanvas-e1424091525866.jpeg\"><img decoding=\"async\" class=\"size-full wp-image-2515\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/02\/HtmlCanvas-e1424091525866.jpeg\" alt=\"HTML Graphics\" width=\"690\" height=\"427\" \/><\/a><figcaption id=\"caption-attachment-2515\" class=\"wp-caption-text\">HTML Graphics<\/figcaption><\/figure>\n<h2>Draw a Graph<\/h2>\n<p>We will draw a graph paper use the combination of horizontal and vertical lines. First define a HTML canvas element with a id as shown below<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n&lt;canvas id=&quot;GraphCanvas&quot; width=&quot;550&quot; height=&quot;190&quot;&gt;&lt;\/canvas&gt;\r\n\r\n<\/pre>\n<p>Now in your javascript, grab a handle to reference the canvas, and get a reference to the context object, before we draw the lines.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\nvar canvas = document.getElementById('GraphCanvas');\r\nvar context = canvas.getContext('2d');\r\n\r\n<\/pre>\n<p>Inside a loop draw the lines as shown below. The <code>moveTo()<\/code> and <code>lineTo()<\/code> method moves and draws line to the specific start-point and endpoint respectively.<\/p>\n<p>Draw the horizontal line<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfor (var x = 0.5; x &lt; 500; x += 10) {\r\n          context.moveTo(x, 0);\r\n          context.lineTo(x, 375);\r\n        }\r\n<\/pre>\n<p>Draw the vertical line.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfor (var y = 0.5; y &lt; 375; y += 10) {\r\n          context.moveTo(0, y);\r\n          context.lineTo(500, y);\r\n        }\r\n<\/pre>\n<p>The reason we set the x and y set at 0.5 is because we want to draw a line that is only one pixel wide; therefore we need to shift the coordinates by 0.5 perpendicular to the line&#8217;s direction.<\/p>\n<p>Now we need to actually draw it on the canvas using the <code>stroke()<\/code> method. The <code>strokestyle<\/code> property allows us to specify the color code.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\ncontext.strokeStyle = &quot;#0B1907&quot;;\r\ncontext.stroke();\r\n\r\n<\/pre>\n<h2>Draw a Line<\/h2>\n<p>To draw a line, you use the following compulsory methods in sequence:<\/p>\n<ol>\n<li>Use the <code>beginPath<\/code> method to declare that we are about to draw a new path<\/li>\n<li>Use the <code>moveTo(x, y)<\/code> moves the drawing cursor to the specified starting point.<\/li>\n<li><code>lineTo(x, y)<\/code> draws a line from the starting position to a new position.<\/li>\n<li>In order to make the line visible, we apply a stroke to the line using <code>stroke<\/code> function<\/li>\n<\/ol>\n<p>By default the stroke color is defaulted to black. You can use the the <code>strokeStyle<\/code> property of the canvas context to set a different color of an HTML5 Canvas line<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\n     context.beginPath();\r\n     context.moveTo(200, canvas.height \/ 2 - 50);\r\n     context.lineTo(canvas.width - 200, canvas.height \/ 2 - 50);\r\n     context.lineWidth = 20;\r\n     context.strokeStyle = '#DF013A';\r\n     context.lineCap = 'butt';\r\n     context.stroke();\r\n\r\n<\/pre>\n<p>The <code>lineCap<\/code> property defines the three possible cap style butt, round or square. In order to define the width of an Canvas line, we can use the <code>lineWidth<\/code> property of the canvas context. Both these properties must be set before calling the <code>stroke()<\/code> method.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ncontext.lineWidth = 15;\r\n<\/pre>\n<h2>Draw Arc<\/h2>\n<p>The <code>arc()<\/code> method creates an arc\/curve (used to create circles, or parts of circles). It is defined by a center point, a radius, a starting angle, an ending angle, and the drawing direction (either clockwise or anticlockwise). Arcs can be styled with the <code>lineWidth<\/code>, <code>strokeStyle<\/code>, and <code>lineCap<\/code> properties. The arc method as defined below accepts the following parameters.<\/p>\n<p>x and y coordinates of the center of the circle, r the raidus of the circle, sAngle is the start angle expressed in radians , eAngle is the end angle and last one is weather it would clockwise or counterclockwise.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">context.arc(x,y,r,sAngle,eAngle,clockwise);\r\n<\/pre>\n<p>The 0 for the starting angle is at the 3 o&#8217;clock position of the arc&#8217;s circle. Arcs can be styled with the <code>lineWidth<\/code>, <code>strokeStyle<\/code>, and <code>lineCap<\/code> properties as highlighted below.<\/p>\n<pre class=\"brush: jscript; highlight: [6,7,8,10,11,12,13]; title: ; notranslate\" title=\"\">\r\nvar canvas = document.getElementById('myCanvas');\r\nvar context = canvas.getContext('2d');\r\nvar x = canvas.width \/ 2;\r\nvar y = canvas.height \/ 2;\r\nvar radius = 75;\r\nvar sAngle = 1.1 * Math.PI;\r\nvar eAngle = 1.9 * Math.PI;\r\nvar counterClockwise = false;\r\ncontext.beginPath();\r\ncontext.arc(x, y, radius, sAngle, eAngle, counterClockwise);\r\ncontext.lineWidth = 15;\r\ncontext.strokeStyle = 'black';\r\ncontext.stroke(); \r\n<\/pre>\n<h2>Draw some more stuff<\/h2>\n<p>Similar to the arc, we can draw 2 types of curves namely quadratic and Bezier curve. If a path does not exist, use the <code>beginPath()<\/code> and <code>moveTo()<\/code> methods to define a context point. Both the curves can be styled with the <em>lineWidth<\/em>, <em>strokeStyle<\/em>, and <em>lineCap<\/em> properties.<\/p>\n<p>To draw a quadratic curve, define a control point that dictates the curvature of your quadratic curve by creating two imaginary tangential lines which are connected to the context point and the ending point. The distance of control point from the context point and end point determines the how broad your curve is. Longer the distance , sharper is your curve. Play around with the co-ordinates as shown below to form a better idea on the curve. Here is the syntax<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ncontext.quadraticCurveTo(Cp1X,Cp1Y,EpX,EpY);\r\n<\/pre>\n<p>where Cp1X and Cp1Y indicates the x and y co-ordinates of Control point while EpX and EpY are the x and y co-ordinates of the end point.<\/p>\n<pre class=\"brush: jscript; highlight: [3]; title: ; notranslate\" title=\"\">\r\n\r\ncontext.beginPath();\r\ncontext.moveTo(140, 120);\/\/define the context point\r\ncontext.quadraticCurveTo(288, 0, 388, 150);\r\ncontext.lineWidth = 8;\r\ncontext.strokeStyle = 'brown';\r\ncontext.stroke();\r\n\r\n<\/pre>\n<p>To create a Bezier curve with HTML5 Canvas, we use the <code>bezierCurveTo()<\/code> method.Unlike quadratic curves, Bezier curves are defined with two control points instead of one, allowing us to create more complex curvatures than quadraticCurve . You begin by using the <code>moveTo()<\/code> to create the context point<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\ncontext.moveTo(200, 250);\/\/create context point\r\n\r\n<\/pre>\n<p>Now you can call the <code>bezierCurveTo(Cp1X,Cp1Y, Cp2X,Cp2yY,EpX, EpY)<\/code>. Cp1X,Cp1Y, Cp2X and Cp2Y represent the x and y co-ordinates of the 2 control points. EpX and EpY are the x and y co-ordinates of the endpoints. Conceptually, the first part of the curve is tangential to the imaginary line that is defined by the context point and the first control point. The imaginary line that is defined by the second control point and the ending point defines the tangential curve of the second part.<\/p>\n<pre class=\"brush: jscript; highlight: [2,3]; title: ; notranslate\" title=\"\">\r\ncontext.beginPath();\r\ncontext.moveTo(200, 250);\/\/create context point\r\ncontext.bezierCurveTo(150, 15, 388, 10, 388, 170);\r\ncontext.lineWidth = 8;\r\ncontext.strokeStyle = 'green';\r\ncontext.stroke();\r\n<\/pre>\n<p>Drawing a shape like rectangle on a canvas is quite easy as well. Call the <code>context.rect()<\/code> method which accepts x and y position co-ordinates along with the width and height.<\/p>\n<pre class=\"brush: jscript; highlight: [2]; title: ; notranslate\" title=\"\">\r\ncontext.beginPath();\r\ncontext.rect(180, 50, 200, 100);\r\ncontext.fillStyle = 'green';\r\ncontext.fill();\r\ncontext.lineWidth = 7;\r\ncontext.strokeStyle = 'black';\r\ncontext.stroke();\r\n\r\n<\/pre>\n<h2>Introducing requestAnimationFrame<\/h2>\n<p>Since the advent of <code>requestAnimationFrame<\/code> (sometimes referred as rAF method), developing animations using JavaScript has never been easier. This rAF method allows the browser to handle some of the complicated animation tasks for you, such as managing the frame rate. The inherent problem of using <code>setTimeout<\/code> and <code>setInterval<\/code> was the browser painting the frames quicker than the screen can display then (most computer screens have a refresh rate of 60 frames per second or <em>FPS<\/em>) resulting unnecessary computation.<\/p>\n<p>Due to the fact that <code>setTimeout<\/code> and <code>setInterval<\/code> based animation will continue to run even if the page is not visible to user, which means that it&#8217;s not battery friendly animation especially for mobile devices . Using rAF gives the browser the ability to optimize your animations to make them smoother and more resource efficient by eliminating the possibility of unnecessary draws and combining multiple animations into a single re-flow and repaint cycle.<\/p>\n<p>Let&#8217;s build our first animation with rAF. We start off by defining a <code>div<\/code> element inside html for container.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n\r\n&lt;div id=&quot;AnimationContainer&quot;&gt;\r\n\r\n&lt;h1 id=&quot;symbol&quot;&gt;*&lt;\/h1&gt;\r\n\r\n&lt;\/div&gt;\r\n\r\n\r\n<\/pre>\n<p>As rAF is fairly new, we need to check the vendor specific variant of the function in your javaScript. There are four vendor prefixes that you have to deal with:<\/p>\n<ul>\n<li><strong>moz<\/strong> for Mozilla Firefox<\/li>\n<li><strong>webkit<\/strong> for Google Chrome, Apple Safari and other webkit-based browsers<\/li>\n<li><strong>o<\/strong> for Opera<\/li>\n<li><strong>ms<\/strong> for Microsoft Internet Explorer<\/li>\n<\/ul>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\nvar requestAnimationFrame= window.requestAnimationFrame||\r\nwindow.webkitRequestAnimationFrame||\r\nwindow.mozRequestAnimationFrame||\r\nwindow.oRequestAnimationFrame||\r\nwindow.msRequestAnimationFrame;\r\n\r\n<\/pre>\n<p>As long as the variable evaluates to true to any one of the expressions, we will call <code>requestAnimationFrame<\/code> with the callback function that is responsible to redraw the screen. In our example we first evaluate the <code>div<\/code> element for display.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar symbols = document.querySelector(&quot;#symbol&quot;);\r\n<\/pre>\n<p>Then we assign a variable the characters we want to display an animate. Note how we used the <code>Math<\/code> DOM object for random selection and assignment to the <code>div<\/code><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar l = displayCHARS&#x5B;Math.floor(Math.random()*displayCHARS.length)];\r\nsymbols.textContent = l;\r\nrequestAnimationFrame(animate);\r\n<\/pre>\n<p>Typically the frame rate is 60 frames per second(FPS). You can consider using <code>setTimeout<\/code> to delay when the next <code>requestAnimationFrame<\/code> call gets made.<\/p>\n<pre class=\"brush: jscript; highlight: [1]; title: ; notranslate\" title=\"\">\r\nsetTimeout(function(){\r\n        requestAnimationFrame(animate);    \r\n    },1000\/10);\r\n<\/pre>\n<p>If you need to stop your animation loop,you can consider using <code>cancelAnimationFrame<\/code>.Just like rAF, obtain a vendor specific handle<br \/>\nfor the function to start with.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar cancelRAF = window.cancelAnimationFrame||\r\n        window.webkitCancelAnimationFrame||\r\n        window.mozCancelAnimationFrame||\r\n        window.msCancelAnimationFrame ;\r\n<\/pre>\n<p>Store the request specific rAF id to be passed to your cancelRAF function.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar requestID;     \/\/store the requestAnimationFrame requestID value\r\nrequestID = requestAnimationFrame(animate);\r\ncancelRAF(requestID);\r\n<\/pre>\n<p>Finally let&#8217;s use the <code>requestAnimationFrame<\/code> on a canvas element to have a little animation of our own. Here is what we will develop today.<\/p>\n<figure id=\"attachment_2513\" aria-describedby=\"caption-attachment-2513\" style=\"width: 663px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/02\/HtmlAnimation.jpeg\"><img decoding=\"async\" class=\"size-full wp-image-2513\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/02\/HtmlAnimation.jpeg\" alt=\"HTML Animation\" width=\"663\" height=\"452\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/02\/HtmlAnimation.jpeg 663w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/02\/HtmlAnimation-300x205.jpeg 300w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/a><figcaption id=\"caption-attachment-2513\" class=\"wp-caption-text\">HTML Animation<\/figcaption><\/figure>\n<p>We will use <code>clearRect<\/code> function of the context to clear the specified pixels within a given rectangle.Then use the <code>fillStyle<\/code> to color the background and <code>fillRect()<\/code> to draws a &#8220;filled&#8221; rectangle.<\/p>\n<pre class=\"brush: jscript; highlight: [1,2,3]; title: ; notranslate\" title=\"\">\r\n            mainContext.clearRect(0, 0, canvasWidth, canvasHeight);\r\n            \/\/ color in the background\r\n            mainContext.fillStyle = &quot;grey&quot;;\r\n            mainContext.fillRect(0, 0, canvasWidth, canvasHeight);\r\n<\/pre>\n<p>Now draw the circle and color it.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nmainContext.beginPath();\r\nvar radius = 25 + 150 * Math.abs(Math.cos(angle));\r\nmainContext.arc(225, 225, radius, 0, Math.PI * 2, false);\r\nmainContext.closePath();\r\n\/\/ color in the circle\r\nmainContext.fillStyle = &quot;red&quot;;\r\nmainContext.fill();\r\n<\/pre>\n<h2>Download the source code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/02\/HTMLCanvas.zip\"><strong>HTMLCanvas<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Animation is the visualization of change, having reference points for the start and end states for comparison. Before HTML 5, it was limited to usage of Adobe Flash, CSS and JavaScript mostly. In this tutorial we will introduce the HTML canvas element and the requestAnimationFrame function in JavaScript to help us create simple animations. &hellip;<\/p>\n","protected":false},"author":47,"featured_media":914,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[102],"class_list":["post-2468","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html5","tag-animations"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HTML5 Graphics and Animation Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn about graphics &amp; animation? Check our Example where we&#039;ll introduce the HTML canvas element and the requestAnimationFrame function in JS\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HTML5 Graphics and Animation Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about graphics &amp; animation? Check our Example where we&#039;ll introduce the HTML canvas element and the requestAnimationFrame function in JS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-02-19T16:15:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-20T09:38:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Arindam Chattopadhya\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Arindam Chattopadhya\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/\"},\"author\":{\"name\":\"Arindam Chattopadhya\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/78b9675665f8627e97ed2dd1fd8cdf00\"},\"headline\":\"HTML5 Graphics and Animation Example\",\"datePublished\":\"2015-02-19T16:15:58+00:00\",\"dateModified\":\"2018-06-20T09:38:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/\"},\"wordCount\":1957,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"keywords\":[\"Animations\"],\"articleSection\":[\"HTML5\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/\",\"name\":\"HTML5 Graphics and Animation Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"datePublished\":\"2015-02-19T16:15:58+00:00\",\"dateModified\":\"2018-06-20T09:38:12+00:00\",\"description\":\"Interested to learn about graphics & animation? Check our Example where we'll introduce the HTML canvas element and the requestAnimationFrame function in JS\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML5\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/html5\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"HTML5 Graphics and Animation Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/78b9675665f8627e97ed2dd1fd8cdf00\",\"name\":\"Arindam Chattopadhya\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4c54fbd5748a5a51f90f73ca68fe86ae6bf8e416966a283b2c05bf15c86c4dd3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4c54fbd5748a5a51f90f73ca68fe86ae6bf8e416966a283b2c05bf15c86c4dd3?s=96&d=mm&r=g\",\"caption\":\"Arindam Chattopadhya\"},\"description\":\"Arindam has completed Masters in Information Technology. His expertise includes enterprise applications architecture, application integration, legacy connectivity, user interface engineering, systems analysis and distributed systems architecture and design. He has hand-on expertise on Java EE , web technology and mobile application development.\",\"sameAs\":[\"http:\/\/www.webcodegeeks.com\/\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/arindam-chattopadhya\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML5 Graphics and Animation Example - Web Code Geeks - 2026","description":"Interested to learn about graphics & animation? Check our Example where we'll introduce the HTML canvas element and the requestAnimationFrame function in JS","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/","og_locale":"en_US","og_type":"article","og_title":"HTML5 Graphics and Animation Example - Web Code Geeks - 2026","og_description":"Interested to learn about graphics & animation? Check our Example where we'll introduce the HTML canvas element and the requestAnimationFrame function in JS","og_url":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2015-02-19T16:15:58+00:00","article_modified_time":"2018-06-20T09:38:12+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","type":"image\/jpeg"}],"author":"Arindam Chattopadhya","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Arindam Chattopadhya","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/"},"author":{"name":"Arindam Chattopadhya","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/78b9675665f8627e97ed2dd1fd8cdf00"},"headline":"HTML5 Graphics and Animation Example","datePublished":"2015-02-19T16:15:58+00:00","dateModified":"2018-06-20T09:38:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/"},"wordCount":1957,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","keywords":["Animations"],"articleSection":["HTML5"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/","url":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/","name":"HTML5 Graphics and Animation Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","datePublished":"2015-02-19T16:15:58+00:00","dateModified":"2018-06-20T09:38:12+00:00","description":"Interested to learn about graphics & animation? Check our Example where we'll introduce the HTML canvas element and the requestAnimationFrame function in JS","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/html5\/html-graphics-animation-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"HTML5","item":"https:\/\/www.webcodegeeks.com\/category\/html5\/"},{"@type":"ListItem","position":3,"name":"HTML5 Graphics and Animation Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/78b9675665f8627e97ed2dd1fd8cdf00","name":"Arindam Chattopadhya","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4c54fbd5748a5a51f90f73ca68fe86ae6bf8e416966a283b2c05bf15c86c4dd3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4c54fbd5748a5a51f90f73ca68fe86ae6bf8e416966a283b2c05bf15c86c4dd3?s=96&d=mm&r=g","caption":"Arindam Chattopadhya"},"description":"Arindam has completed Masters in Information Technology. His expertise includes enterprise applications architecture, application integration, legacy connectivity, user interface engineering, systems analysis and distributed systems architecture and design. He has hand-on expertise on Java EE , web technology and mobile application development.","sameAs":["http:\/\/www.webcodegeeks.com\/"],"url":"https:\/\/www.webcodegeeks.com\/author\/arindam-chattopadhya\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/2468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/47"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=2468"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/2468\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/914"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=2468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=2468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=2468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}