How to draw a circular polygonal pattern using html5
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