Draw a circular circle picture with canvas

Source: Internet
Author: User

The effect is automatically drawn without pausing

The code is as follows

  varCanvas = document.getElementById (' MyCanvas '), width = Canvas.width,height =Canvas.height; varstep,startangle,endangle,add=math.pi*2/100; Counterclockwise =false; varIsdrawover=true; varX1=math.floor (200+100);//Set Default Center x axis         varY1=math.floor (20+100);//Set the default center Y axis         varXvary; varradius1= Math.floor (10+50);//Set the default circle radius         varradius; varAnimation_interval = 20,n = 100; varVarName; functionSetctxcanvas () {CTX= Canvas.getcontext (' 2d '); Ctx.shadowoffsetx= 0;//Set Horizontal Displacementctx.shadowoffsety = 0;//Set Vertical DisplacementCtx.shadowblur = 10;//setting the degree of ambiguityCtx.linewidth = 1.0; }         functionActiondo () {if(isdrawover) {Isdrawover=false;                 Setctxcanvas (); Step=1; StartAngle=0; Ctx.strokestyle= ' # ' + (' 00000 ' + (Math.random () *0x1000000<<0). ToString ()). Slice (-6);//Circle ColorCtx.shadowcolor = ' # ' + (' 00000 ' + (Math.random () *0x1000000<<0). ToString (+)). Slice (-6);//Set Shadow color                 //Center Position                 if(x==undefined&&y==undefined&&radius==undefined) {x=X1; Y=Y1; Radius=Radius1; }                 Else if(x1==x&&y1==y&&radius1==radius) {x=X1; Y=y1-Radius1; Radius= RADIUS1/2;                 }                 Else if(x==x1&&y<y1) {x=x1+Radius1; Y=Y1; Radius= RADIUS1/2;                 }                 Else if(y==y1&&x>x1) {x=X1; Y=y1+Radius1; Radius= RADIUS1/2;                 }                 Else if(x==x1&&y>y1) {x=x1-Radius1; Y=Y1; Radius= RADIUS1/2;                 }                 Else if(x<x1&&y==y1) {x=X1; Y=Y1; Radius=Radius1; }                //var htmldiv= ' <div>x= ' +x+ ', y= ' +y+ ', radius= ' +radius+ ', x1= ' +x1+ ', y1= ' +y1+ ', radius1= ' +radius1+ ' </div > ';              //$ (' #ddd '). Append (Htmldiv); Varname=setinterval (animation, animation_interval); }         } varAnimation =function () {       if(Step <=N) {endangle= StartAngle +add;                  DrawArc (StartAngle, Endangle); StartAngle=Endangle; Step++; } Else{clearinterval (varName); Isdrawover=true;     Actiondo (); }            }; functionDrawArc (S, e) {Ctx.beginpath ();           Ctx.arc (x, y, radius, S, e, counterclockwise); Ctx.linewidth= 1.0;   Ctx.stroke (); }  
The code runs directly as follows

<canvas id= "MyCanvas" width= "" "height=" "style=" border:0px solid #333; ></canvas>

The HTML code is all right.

Draw a circular circle picture with canvas

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.