In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about the html5 canvas canvas how to draw arcs and rotation graphics, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.
Before doing the rotation operation, you must understand one sentence: it is the coordinate system of the canvas that is rotated, not the graphic itself. Well, after understanding this sentence, the next step is very simple.
The code is as follows:
Var cxt=document.getElementById ('demo'). GetContext ("2d")
Cxt.beginPath ()
Cxt.arc / * draw a semicircle with center coordinates 100100; the start Radian is 0.75 and the end Radian is 1.75; the last parameter False = clockwise, true = counterclockwise, of course, this parameter is optional * /
Cxt.fillStyle= "# F00"; / * choose the color to use * /
Cxt.fill (); / * the step of actually drawing a figure on the canvas, drawing the first semicircle * /
/ * draw the second semicircle in the same way * /
Cxt.beginPath ()
Cxt.arc (170pje 100pr 50gm. PIQR 1.25ct Math.PIQR 0.25pr false)
Cxt.fillStyle= "# F00"
Cxt.fill (); / * draw the drawing on the canvas * /
Cxt.beginPath ()
/ * rotate the canvas 45 degrees clockwise, and the parameter of the rotate function is radians, so convert it * /
Cxt.rotate (45*Math.PI/180)
Cxt.fillRect (141.1 fuzz 50100100); / * the start coordinate is 141.1 meme 50, and the width and height are both 100cm /
Cxt.fillStyle= "# F00"
Cxt.fill ()
Cxt.beginPath ()
/ * rotate the canvas to a normal angle * /
Cxt.rotate (- 45*Math.PI/180)
Cxt.font= "60px Microsoft Yahei"
Cxt.strokeStyle= "# f00"
Cxt.strokeText ("I love html5", 0300); / * two parameters, the first is the x-axis coordinate to start drawing the text, and the second is the Y coordinate to start drawing the text * /
Cxt.stroke ()
/ * create a gradient * /
Var grd=cxt.createLinearGradient / * the four parameters are the start point of the gradient x, the end point of the gradient x, and the end point of the gradient x, y
Grd.addColorStop (0, "# FF0000")
Grd.addColorStop (0.25, "# FFFF00")
Grd.addColorStop (0.5, "# 00FF00")
Grd.addColorStop (.75, "# 00FFFF")
Grd.addColorStop (1, "# FFFF00")
Cxt.strokeStyle=grd
Cxt.strokeText ("I love canvas", 0400); / * two parameters, the first is the x-axis coordinate to start drawing the text, and the second is the Y coordinate to start drawing the text * /
Cxt.stroke ()
This is how html5's canvas canvas draws arcs and rotations. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.