1. JavaScript uses canvas in HTML 1. Canvas: A special area on the page for drawing graphics <canvas id="id" width="width" height="height"> </canvas> (2) Get the canvas in JavaScript document.getElementById('id') (3) Prepare the brush: context object (brush), also known as the drawing environment, is used to draw graphics on the canvas getContext('2d') 3. Drawing
E. Line path: No matter how many connection endpoints are added in the same canvas, there is only one path. ontext.strokeStyle = 'red' //stroke color context.moveTo(10,10); //starting position context.lineTo(10,100); //connection endpoint (vertical line) context.lineTo(100,100); //Connection endpoint (horizontal line) context.closePath();//Close the pathcontext.stroke();//Strokecontext.fill(); //Fill (2) Draw a circle: arc(x, y, r, start angle, end angle, direction) var canvas = document.getElementById('cavs'); var context = canvas.getContext('2d'); context.arc(150,80,50,0,2.0*Math.PI) context.stroke() 2. Page Storage Technology Session tracking technology, the HTTP protocol is a stateless protocol, the server must use session tracking technology to determine the client sending the request Example: Drawing a stick figure using canvas <body> <canvas id="cas" width="1000" height="1000"></canvas> </body> </html> <script> var cas = document.getElementById('cas'); var context = cas.getContext('2d'); //Draw the head context.arc(400,100,30,0,2*Math.PI); context.lineWidth='5'; context.stroke(); //Draw the torso context.beginPath(); context.moveTo(400,130); context.lineTo(400,140); context.lineWidth='5'; context.stroke(); context.beginPath(); context.moveTo(400,140); context.lineTo(400,260); context.lineWidth='25'; context.stroke(); //Draw the folder context.beginPath(); context.moveTo(360,200); context.lineTo(440,200); context.lineTo(440,250); context.lineTo(360,250); context.closePath(); context.fillStyle='#fff'; context.fill(); context.lineWidth='2'; context.stroke(); //Draw the arm context.beginPath(); context.moveTo(400,140); context.lineTo(440,200); context.lineTo(400,240); context.lineWidth='10'; context.stroke(); context.beginPath(); context.arc(400,240,10,0,2*Math.PI); context.fillStyle='#000'; context.fill(); //Draw the legs context.beginPath(); context.moveTo(380,400); context.lineTo(400,260); context.lineTo(420,400); context.lineTo(400,240); context.lineWidth='10'; context.stroke(); context.beginPath(); context.arc(365,400,15,0,1*Math.PI,true); context.closePath(); context.lineWidth='5'; context.stroke(); context.beginPath(); context.arc(405,400,15,0,1*Math.PI,true); context.closePath(); context.lineWidth='5'; context.stroke(); </script> The effect is as shown: You can draw various shapes you like by modifying the parameters This is the end of this article about the use of html canvas and page storage technology in JavaScript. For more relevant js html canvas content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: ERROR 1862 (HY000): Your password has expired. To log in you must change it using a .....
>>: Tutorial on deploying multiple servers with WebApi and configuring Nginx load balancing
Table of contents 1 The common rules for creating...
This article example shares the specific code of ...
Table of contents 1. Preparation before developme...
1. Transaction characteristics (ACID) (1) Atomici...
Table of contents 1. Download MySQL msi version 2...
Generate a certificate chain Use the script to ge...
Table of contents Preface analyze Initial Renderi...
First download the latest MySQL 5.7.17 Community ...
Preface In today's increasingly convenient In...
Common points: The DIV tag and SPAN tag treat som...
Nginx logs can be used to analyze user address lo...
1.mysql-5.7.19-winx64.zip (this is the free insta...
I will use three days to complete the static page...
BFC BFC: Block Formatting Context BFC layout rule...
If you don't have a Linux system, please refe...