Home > Web Front-end > H5 Tutorial > HTML5 canvas - draw simple rectangles and triangles example code_html5 tutorial skills

HTML5 canvas - draw simple rectangles and triangles example code_html5 tutorial skills

WBOY
Release: 2016-05-16 15:49:34
Original
1882 people have browsed it

First, place a canvas element in the html page, where the canvas element should have three attributes: ID, width, and height.

Copy code
The code is as follows:



Get the canvas object and get the context var cxt=document.getElementById('demo').getContext("2d"); The parameter 2d is determined.

Start drawing. There are two forms, one is fill and the other is stroke.

javascript code:

Copy code
The code is as follows:



Rendering:
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template