Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How canvas tag is beneficial in HTML5?

Tags:

html

I am a junior developer I can't understand how canvas tag is beneficial for us? I read lot of articles on that but I can't get the root benefit getting from the canvas tag.

like image 957
Subbu Avatar asked Aug 11 '10 06:08

Subbu


People also ask

What is the use of canvas tag in HTML5?

The <canvas> tag in HTML is used to draw graphics on a web page using JavaScript. It can be used to draw paths, boxes, texts, gradients, and adding images. By default, it does not contain borders and text. Note: The <canvas> tag is new in HTML5.

Why do we use canvas in HTML?

<canvas> is an HTML element which can be used to draw graphics via scripting (usually JavaScript). This can, for instance, be used to draw graphs, combine photos, or create simple animations.

Why do we need to learn HTML5 Canvas?

The canvas element in HTML5 allows you to create amazing dynamic script based drawings and animations directly within your webpages. Bringing your JavaScript to life visually drawing free form graphics on a drawing surface. Canvas is a powerful element with many options.

What are the benefits to working with HTML5 Canvas directly in Animate CC?

A new document type (HTML5 Canvas) has been added to Animate that provides native support for creating rich and interactive HTML5 content. It means that you can use the traditional Animate timeline, workspace, and tools to create content, but produce HTML5 output.


2 Answers

Think of the difference between canvas and svg as the difference betwee Photoshop and Illustrator (or Gimp and Inkscape for you OSS folks). One deals with bitmaps and the other vector art.

With canvas, since you are drawing in bitmap, you can smudge, blur, burn, dodge your images easily. But since it's bitmap you can't easily draw a line and then decide to reposition the line. You need to delete the old line and then draw a new line.

With svg, since you are drawing vectors, you can easily move, scale, rotate, reposition, flip your drawings. But since it's vectors you can't easily blur the edges according to line thickness or seamlessly meld a red circle into a blue square. You need to simulate blurring by drawing intermediate polygons between objects.

Sometimes their use case overlaps. Like a lot of people use canvas to do simple line drawings and keep track of the objects as data structures in javascript. But really, they both serve different purposes. If you try to implement general purpose vector drawing in pure javascript on top of canvas I doubt you'd be faster than using svg which is most likely implemented in C.

like image 133
slebetman Avatar answered Oct 27 '22 12:10

slebetman


Basically, thanks to canvas, we can now draw/render 2D shapes using HTML5 and the canvas API.

As an example of what's possible now with canvas, see this

like image 28
Soufiane Hassou Avatar answered Oct 27 '22 13:10

Soufiane Hassou