Draw a circular multi-angle Pattern Based on html5, and draw a multi-angle Pattern Based on html5
Let's take a look at the simplest:
The Code is as follows:
Copy the content to the clipboard using JavaScript Code
- Var canvas = document. getElementById ('My), ctx = canvas. getContext ('2d ');
- SetInterval (function (){
- Ctx. clearRect (0, 0, 400,400 );
- Ctx. save ();
- Ctx. translate (200,200 );
- 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; I --){
- Ctx. rotate (pi );
- Ctx. moveTo (x1, y1 );
- 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, y3 );
- Ctx. lineTo (x2, y2 );
- }
- Ctx. stroke ();
- Ctx. restore ();
- },100 );
On the basis of the polygon above, we will go further:
The Code is as follows:
Copy the content to the clipboard using JavaScript Code
- Var canvas = document. getElementById ('My), ctx = canvas. getContext ('2d '), r = 10;
- SetInterval (function (){
- Ctx. clearRect (0, 0, 400,400 );
- Ctx. save ();
- Ctx. translate (200,200 );
- Var grad = ctx. createRadialGradient (0, 0, 0, 0, r + 20 );
- Grad. addColorStop (0.2, 'white ');
- Grad. addColorStop (0.7, 'yellow ');
- Grad. addColorStop (0.8, 'Orange ');
- Ctx. beginPath ();
- Ctx. fillStyle = grad;
- Ctx. arc (0, 0, r, 0, Math. PI * 2, true );
- 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; I --){
- Ctx. rotate (pi );
- Ctx. moveTo (r, 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 (x2, y2 );
- }
- Ctx. fill ();
- Ctx. restore ();
- R <= 100 & (r + = 2 );
- },100 );
The above is all the content of this article, hoping to help you learn.