HTML5 Canvas: initial Canvas, html5 initial canvas

Source: Internet
Author: User

HTML5 Canvas: initial Canvas, html5 initial canvas

Canvas and HTML 5 can be used to do many things, such as drawing, animation, and game development.

 

Canvas Element

Canvas.

 

<Canvas id = "yourCanvasId" width = "300" height = "150"/>

In addition to common attributes, the Canvas Element has only two additional attributes: width and height. They all have no unit. In fact, the unit is px, but cannot be written. If these two attributes are not specified, the default value is width 300 and height 150.

As we all know, html element styles can be specified using css styles. Canvas is no exception.

The expected result is as follows:

 

 

The actual execution result is as follows:

 

The execution result shows that it is indeed a magnified hello. Why?

 

In fact, I think it can be understood in this way. It is a projection cloth, because the real drawing is not on it, but on a drawing board. After the drawing is completed, it is projected onto the projection cloth. This is similar to the slide projector we used in middle school. We write exercises on a glass board (drawing board) and project the slides to a canvas or a white wall ).

Therefore, when we think about it, we will understand that when the width and height attribute values in the css style are different from the width and height attribute values of the canvas element, the content on the drawing board is automatically scaled to the canvas.

Currently, the Canvas Element has three methods:

 

 

 

 

The CanvasRenderingContext2D object can be obtained through getContext ("2d"); then the context object can be used as a 2d graph.

With getContext ("3d"), you can perform 3d plotting. The bottom layer of 3d plotting is WebGL.

 

In the subsequent articles, you will learn the necessary knowledge of using Canvas to draw images.

CanvasRenderingContext2D API details:

Http://www.w3school.com.cn/jsref/dom_obj_canvasrenderingcontext2d.asp

Https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.