Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw a circular polygonal pattern using html5

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you how to use html5 to draw circular polygonal patterns, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Let's take a look at the simplest effect:

The code is as follows:

JavaScript Code copies content to the clipboard

Var canvas = document.getElementById ('my'), ctx = canvas.getContext (' 2d'); setInterval (function () {ctx.clearRect (0J0400400); ctx.save (); ctx.translate (200200); var ci = 90, pi = Math.PI / ci, x1 = 100, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0; ctx.beginPath () For (var I = ci * 2; I > 0; iMui -) {ctx.rotate (pi); ctx.moveTo (x1Powery1); y2 = x1 * Math.sin (pi); x2 = x1 * Math.cos (pi); x3 = (x1-x2) / 2 + x2 + 10 + Math.random () * 20 Y3 = y2 / 2; ctx.lineTo (x3); ctx.lineTo (x2);} ctx.stroke (); ctx.restore ();}

On the basis of the above polygons, it is followed by:

The code is as follows:

JavaScript Code copies content to the clipboard

Var canvas = document.getElementById ('my'), ctx = canvas.getContext (' 2d'), r = 10; setInterval (function () {ctx.clearRect (0400400); ctx.save (); ctx.translate (200200); var grad = ctx.createRadialGradient); grad.addColorStop (0.2) Grad.addColorStop; grad.addColorStop; ctx.beginPath (); ctx.fillStyle = grad; ctx.arc; ctx.fill (); var ci = 90, pi = Math.PI / ci, x2 = 0, y2 = 0, x3 = 0, y3 = 0 X1 = 100; y1 = 0; ctx.beginPath (); for (var I = ci * 2; I > 0; Imura -) {ctx.rotate (pi); ctx.moveTo (rmaine 0); y2 = r * Math.sin (pi); x2 = r * Math.cos (pi) X3 = (r-x2) / 2 + x2 + 10 + Math.random () * 20; y3 = y2 / 2; ctx.lineTo (x3 ~ Y3); ctx.lineTo (x ~ 2 ~ ());} ctx.fill (); ctx.restore (); r

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: 282

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report