In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today Xiaobian to share with you how to use Canvas to draw polygons in html5 related knowledge points, detailed content, clear logic, I believe that most people are too aware of this knowledge, so share this article for your reference, I hope you will learn something after reading this article, let's take a look at it.
Preface
Canvas drawing multi-deformation is very simple, as long as understand the Canvas path + simple junior high school mathematics knowledge can be completed.
Analysis
Calculate the position of each point and draw the path by lineTo ().
The core code is parsed as follows (or viewed in CodePen):
Function drawPolygonPath (sideNum, radius, originX, originY, ctx) {ctx.beginPath (); const unitAngle = Math.PI * 2 / sideNum; / / Cell Angle let angle = 0; / / initial Angle let xLength, yLength; / / ctx.moveTo (originX, originY); for (let I = 0; I < sideNum; iTunes +) {/ / traverse the calculation point and lineTo () draws the path xLength = radius * Math.cos (angle); yLength = radius * Math.sin (angle) Ctx.lineTo (originX + xLength, originY-yLength); / / draw the path angle + = unitAngle;} ctx.closePath (); / / close the path, or cycle lineTo () to the starting point again in the for loop. Above is all the content of the article "how to draw polygons with Canvas in html5". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.