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
OBS studio is cool, but JavaScript is cooler. Now...
The steps for configuring Tomcat in IDEA 2020 are...
Table of contents Overview Promise Race Method Re...
1: Installation command pip install docker-compos...
Phenomenon Start the Docker container docker run ...
CSS issues about background gradient and automati...
This article mainly introduces the sql serial num...
Install MySQL database a) Download the MySQL sour...
To view the version and tag of the image, you nee...
1. Requirements description Display the delete ic...
Nexus provides RestApi, but some APIs still need ...
Before introducing the new CSS property contain, ...
/****************** * Kernel debugging technology...
1. Download, I take 8.0 as an example Download ad...
Table of contents 【Effect】 【Implementation method...