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
SMIL adds support for timing and media synchroniz...
Our bank's MGR will be launched at the end of...
In order to prevent non-compliant data from enter...
Table of contents 1. What is an event? 2. How to ...
Document hints using the show-header attribute sh...
question: The commonly used command "ll"...
Docker is an open source engine that makes it eas...
Table of contents Parsing .vue files Extract docu...
This article records the graphic tutorial of MySQ...
1. InnoDB storage engine must be used It has bett...
1. Modify the docker configuration file and open ...
1. Introduction to inode To understand inode, we ...
Table of contents 1. Technology Selection 2. Tech...
x-ua-compatible is used to specify the model for ...
CSS3 implements 2D plane transformation and visua...