Showing posts with label html Canvas Element. Show all posts
Showing posts with label html Canvas Element. Show all posts

Thursday, 5 January 2012

HTML5 Canvas


What is Canvas?

The HTML5 Canvas element is an HTML tag similar to the <div><a>, or <table> tag, with the exception that its contents are rendered with JavaScript. In order to leverage the HTML5 Canvas, you’ll need to place the canvas tag somewhere inside your HTML, create an initialize JavaScript function that accesses the canvas tag once the page loads, and then utilize the HTML5 Canvas API to draw your visualizations.


  • The HTML5 canvas element uses JavaScript to draw graphics on a web page.
  • A canvas is a rectangular area, and you control every pixel of it.
  • The canvas element has several methods for drawing paths, boxes, circles, characters, and adding images.

Create a Canvas Element

Add a canvas element to the HTML5 page.

Specify the id, width, and height of the element:

<html>
    <head>
        <script>
 
            window.onload = function(){
                var canvas = document.getElementById("myCanvas");
                var context = canvas.getContext("2d");
 
                // do stuff here
            };
 
        </script>
    </head>
    <body>
        <canvas id="myCanvas" width="578" height="200">
        </canvas>
    </body>
</html>


HTML5 Canvas Element Explanation


The code above will be the base template for all of your future HTML5 Canvas projects. We can define the height and width of the canvas tag using the height and width attributes, just like we would with any other HTML tag. Inside the initializer function we can access the canvas DOM object by its id, and then get a 2-d context using the getContext() method.


1.1 HTML5 Canvas
1.2 Lines
1.3 Curves
1.4 Paths
1.5 Shapes
1.6 Fill Styles
1.7 Images
1.8 Text

New Elements in HTML5


           The internet has changed a lot since HTML 4.01 became a standard in 1999.
Today, some elements in HTML 4.01 are obsolete, never used, or not used the way they were intended to. These elements are deleted or re-written in HTML5.
To better handle today's internet use, HTML5 also includes new elements for better structure, drawing, media content, and better form handling.


New Markup Elements

New elements for better structure:


Tag Description
<article> Specifies independent, self-contained content, could be a news-article, blog post, forum post, or other articles which can be distributed independently from the rest of the site.
<aside> For content aside from the content it is placed in. The aside content should be related to the surrounding content
<bdi> For text that should not be bound to the text-direction of its parent elements
<command> A button, or a radiobutton, or a checkbox
<details> For describing details about a document, or parts of a document
<summary> A caption, or summary, inside the details element
<figure> For grouping a section of stand-alone content, could be a video
<figcaption> The caption of the figure section
<footer> For a footer of a document or section, could include the name of the author, the date of the document, contact information, or copyright information
<header> For an introduction of a document or section, could include navigation
<hgroup> For a section of headings, using <h1> to <h6>, where the largest is the main heading of the section, and the others are sub-headings
<mark> For text that should be highlighted
<meter> For a measurement, used only if the maximum and minimum values are known
<nav> For a section of navigation
<progress> The state of a work in progress
<ruby> For ruby annotation (Chinese notes or characters)
<rt> For explanation of the ruby annotation
<rp> What to show browsers that do not support the ruby element
<section> For a section in a document. Such as chapters, headers, footers, or any other sections of the document
<time> For defining a time or a date, or both
<wbr> Word break. For defining a line-break opportunity.

New Media Elements

HTML5 provides a new standard for media content:


The internet has changed a lot since HTML 4.01 became a standard in 1999.

To better handle today’s internet use, HTML5 also includes new elements for better structure, drawing, media content, and better form handling.
HTML5 provides a new standards for media contents:
TagDescription
<audio>For multimedia content, sounds, music or other audio streams
<video>For video content, such as a movie clip or other video streams
<source>For media resources for media elements, defined inside video or audio elements
<embed>For embedded content, such as a plug-in
<track>For text tracks used in mediaplayers
The Canvas Element
The canvas element uses JavaScript to make drawings on a web page.
TagDescription
<canvas>For making graphics with a script
New Form Elements
HTML5 offers more form elements, with more functionality:
TagDescription
<datalist>A list of options for input values
<keygen>Generate keys to authenticate users
<output>For different types of output, such as output written by a script

New Input Type Attribute Values
Also, the input element’s type attribute has many new values, for better input control before sending it to the server:
TypeDescription
telThe input value is of type telephone number
searchThe input field is a search field
urlThe input value is a URL
emailThe input value is one or more email addresses
datetimeThe input value is a date and/or time
dateThe input value is a date
monthThe input value is a month
weekThe input value is a week
timeThe input value is of type time
datetime-localThe input value is a local date/time
numberThe input value is a number
rangeThe input value is a number in a given range
colorThe input value is a hexadecimal color, like #FF8800
placeholderSpecifies a short hint that describes the expected value of an input field