html5 canvas point,HTML5 - Canvas

HTML5 - Canvas

Advertisements

HTML5 element gives you an easy and powerful way to draw graphics using JavaScript. It can be used to draw graphs, make photo compositions or do simple (and not so simple) animations.

Here is a simple element which has only two specific attributes width and height plus all the core HTML5 attributes like id, name and class, etc.

You can easily find that element in the DOM using getElementById() method as follows −

var canvas = document.getElementById("mycanvas");

Let us see a simple example on using element in HTML5 document.

#mycanvas{border:1px solid red;}

This will produce the following result −

The Rendering Context

The is initially blank, and to display something, a script first needs to access the rendering context and draw on it.

The canvas element has a DOM method called getContext, used to obtain the rendering context and its drawing functions. This function takes one parameter, the type of context2d.

Following is the code to get required context along with a check if your browser supports element −

var canvas = document.getElementById("mycanvas");

if (canvas.getContext) {

var ctx = canvas.getContext('2d');

// drawing code here

} else {

// canvas-unsupported code here

}

Browser Support

The latest versions of Firefox, Safari, Chrome and Opera all support for HTML5 Canvas but IE8 does not support canvas natively.

You can use ExplorerCanvas to have canvas support through Internet Explorer. You just need to include this JavaScript as follows −

HTML5 Canvas Examples

This tutorial covers the following examples related to HTML5 element.

Sr.No.

Examples & Description

1

Drawing Rectangles

Learn how to draw rectangle using HTML5 element

2

Drawing Paths

Learn how to make shapes using paths in HTML5 element

3

Drawing Lines

Learn how to draw lines using HTML5 element

4

Drawing Bezier

Learn how to draw Bezier curve using HTML5 element

5

Drawing Quadratic

Learn how to draw quadratic curve using HTML5 element

6

Using Images

Learn how to use images with HTML5 element

7

Create Gradients

Learn how to create gradients using HTML5 element

8

Styles and Colors

Learn how to apply styles and colors using HTML5 element

9

Text and Fonts

Learn how to draw amazing text using different fonts and their size.

10

Pattern and Shadow

Learn how to draw different patterns and drop shadows.

11

Canvas States

Learn how to save and restore canvas states while doing complex drawings on a canvas.

12

Canvas Translation

This method is used to move the canvas and its origin to a different point in the grid.

13

Canvas Rotation

This method is used to rotate the canvas around the current origin.

14

Canvas Scaling

This method is used to increase or decrease the units in a canvas grid.

15

Canvas Transform

These methods allow modifications directly to the transformation matrix.

16

Canvas Composition

This method is used to mask off certain areas or clear sections from the canvas.

17

Canvas Animation

Learn how to create basic animation using HTML5 canvas and JavaScript.

Advertisements

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值