Home Web Front-end H5 Tutorial html5-Canvas can draw various graphics in the web_html5 tutorial skills

html5-Canvas can draw various graphics in the web_html5 tutorial skills

May 16, 2016 pm 03:50 PM
canvas Drawing

I think the most important thing in HTML5 is the introduction of Canvas, which allows us to draw various graphics on the web. It feels like this alone is a bit blurry between our web and desktop programs. There are also xml-based drawings in the web outside HTML5, such as VML and SVG. Canvas is pixel-based drawing. Canvas is an html node equivalent to a drawing board. We must use js to operate drawing.
As follows:
Your browser does not support the definition yet.
We can get the canvas object as var c=document.getElementById("myCanvas"); its js attribute methods are listed below:
1: Draw the rendering object , c.getContext(" 2d"), to get the 2d drawing object, the object obtained will be the same object no matter how many times we call it.
2: Drawing method :
clecrRect(left,top,width,height) clears the specified rectangular area,
fillRect(left,top,width,height) draws the rectangle, and fillStyle fill.
fillText(text,x,y) draws text;
strokeRect(left,top,width,height) draws a rectangle and draws the border with strokeStyle.
beginPath(): Start the drawing of the path and reset the path to the initial state;
closePath(): The drawing of the path ends. It will draw a closed interval and add a closed curve from the starting position to the current coordinates. ;
moveTo(x, y): Set the actual coordinates of the drawing.
lineTo(x, y); Draw a straight line from the current actual position to x, y.
fill(), stroke(), clip(): After completing the final fill and border outline of the drawing, clip the area.
arc(): draw an arc, center position, starting radian, and ending radian to specify the position and size of the arc;
rect(): rectangular path;
drawImage (Imag img): draw an image;
quadraticCurveTo(): ​​Quadratic spline path, parameter two control points;
bezierCurveTo(): ​​Bezier curve, parameter three control points;
createImageData, getImageData, putImageData: Canvas Medium pixel data. ImageData records width, height, and data data, where data is the record of our pigment as
argb, so the array size length is width*height*4, and the order is rgba. getImageData is to get the pixels of the rectangular area, and putImageData is to set the pixels of the rectangular area;
… and so on!
3: Coordinate transformation :
translate (x, y): translation transformation, the origin moves to coordinates (x, y);
rotate (a): rotation transformation, rotate a degree angle;
scale (x, y): scaling transformation;
save(), restore(): provide and a stack to save and restore the drawing state, save pushes the current drawing state into the stack, restore pops the stack , restore the drawing state;
… and so on!
Okay, it’s too late. Attached is my test code:

Copy code
The code is as follows:

< html>



Your browsing The browser does not support it yet



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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

A quick guide to learning Python drawing: code example for drawing ice cubes A quick guide to learning Python drawing: code example for drawing ice cubes Jan 13, 2024 pm 02:00 PM

Quickly get started with Python drawing: code example for drawing Bingdundun Python is an easy-to-learn and powerful programming language. By using Python's drawing library, we can easily realize various drawing needs. In this article, we will use Python's drawing library matplotlib to draw a simple graph of ice. Bingdundun is a cute panda who is very popular among children. First, we need to install the matplotlib library. You can do this by running in the terminal

What are the details of the canvas clock? What are the details of the canvas clock? Aug 21, 2023 pm 05:07 PM

The details of the canvas clock include clock appearance, tick marks, digital clock, hour, minute and second hands, center point, animation effects, other styles, etc. Detailed introduction: 1. Clock appearance, you can use Canvas to draw a circular dial as the appearance of the clock, and you can set the size, color, border and other styles of the dial; 2. Scale lines, draw scale lines on the dial to represent hours or minutes. Position; 3. Digital clock, you can draw a digital clock on the dial to indicate the current hour and minute; 4. Hour hand, minute hand, second hand, etc.

What versions of html2canvas are there? What versions of html2canvas are there? Aug 22, 2023 pm 05:58 PM

The versions of html2canvas include html2canvas v0.x, html2canvas v1.x, etc. Detailed introduction: 1. html2canvas v0.x, which is an early version of html2canvas. The latest stable version is v0.5.0-alpha1. It is a mature version that has been widely used and verified in many projects; 2. html2canvas v1.x, this is a new version of html2canvas.

Learn the canvas framework and explain the commonly used canvas framework in detail Learn the canvas framework and explain the commonly used canvas framework in detail Jan 17, 2024 am 11:03 AM

Explore the Canvas framework: To understand what are the commonly used Canvas frameworks, specific code examples are required. Introduction: Canvas is a drawing API provided in HTML5, through which we can achieve rich graphics and animation effects. In order to improve the efficiency and convenience of drawing, many developers have developed different Canvas frameworks. This article will introduce some commonly used Canvas frameworks and provide specific code examples to help readers gain a deeper understanding of how to use these frameworks. 1. EaselJS framework Ea

uniapp implements how to use canvas to draw charts and animation effects uniapp implements how to use canvas to draw charts and animation effects Oct 18, 2023 am 10:42 AM

How to use canvas to draw charts and animation effects in uniapp requires specific code examples 1. Introduction With the popularity of mobile devices, more and more applications need to display various charts and animation effects on the mobile terminal. As a cross-platform development framework based on Vue.js, uniapp provides the ability to use canvas to draw charts and animation effects. This article will introduce how uniapp uses canvas to achieve chart and animation effects, and give specific code examples. 2. canvas

Learn how to use word drawing in 1 minute! Learn how to use word drawing in 1 minute! Mar 20, 2024 pm 09:10 PM

Usually, we not only edit text in Word software, but also insert some patterns and shapes; Word software is an indispensable software for us in the office; it is so powerful, of course it can also be used for drawing! So, how do we complete word drawing? Where are the word drawing tools? How to use it? Here is a brief introduction to you for your reference. I hope it will be helpful. The steps are as follows: 1. First, we open the Word software on the computer; then, we create a new blank word document; at this time, we can edit text here, or draw patterns, just click on the text. 2. Next, we select the [Insert] button in the [Navigation Bar] above; then, we select [Shape

What properties does tkinter canvas have? What properties does tkinter canvas have? Aug 21, 2023 pm 05:46 PM

The tkinter canvas attributes include bg, bd, relief, width, height, cursor, highlightbackground, highlightcolor, highlightthickness, insertbackground, insertwidth, selectbackground, selectforeground, xscrollcommand attributes, etc. Detailed introduction

Demystifying the Canvas API: everything from simple drawing to advanced special effects Demystifying the Canvas API: everything from simple drawing to advanced special effects Jan 17, 2024 am 09:44 AM

CanvasAPI is a powerful drawing tool provided by HTML5, which can implement various functions from basic drawing to advanced special effects. This article will give you an in-depth understanding of how to use CanvasAPI and provide specific code examples. Basic drawing The most basic part of Canvas API is to draw simple graphics, such as rectangles, circles, straight lines, etc. Here is a code example that creates a rectangle and fills it with color: constcanvas=document.getElementB

See all articles