Use as paint, custom polygons and circles

Source: Internet
Author: User
Tags cos sin

These two days in the study about as drawing problems, after some toss finally came out, (part of the code from programming Macromedia Flash MX)

As:

MovieClip.prototype.drawRegAng = function (x, y, R, num, rotation) {
/* parameter description: x,y: Center coordinate of polygon; R: Polygon radius; num: number of polygon edges; The last one is the rotation angle */
 var tangle = (rotation-90) *math.pi/180;
 var angle = 2*math.pi/num;
 var sin = math.sin;
 var cos = math.cos;
 num++;
 this.moveto (X+r*cos (Tangle), Y+r*sin (tangle));
 while (num--) {
  tangle + = angle;
  This.lineto (X+r*cos (Tangle), Y+r*sin (tangle));
 }
};
This.createemptymovieclip ("loader", 100);
Loader.linestyle (0, 0x000000);
//initialization variable
var r=50,num=5,rota=0;
var x = stage.width/2, y = STAGE.HEIGHT/2;
Loader.drawregang (x, y, R, Num, rota);

Numchange=new Object ();
Numchange.change=function (evt) {
Num=evt.target.value;
}
Rchange=new Object ();
Rchange.change=function (evt) {
R=evt.target.value;
}
Rotachange=new Object ();
Rotachange.change=function (evt) {
Rota=evt.target.value;
}
Bian.addeventlistener ("Change", Numchange);
Jiaodu.addeventlistener ("Change", Rotachange);
Banjing.addeventlistener ("Change", Rchange);
function clicked () {
Loader.clear ();
Loader.linestyle (0, 0x000000);
Loader.drawregang (x, y, R, Num, rota);
}
Rsubmit.addeventlistener ("Click", clicked);

Circular:

As:
Movieclip.prototype.drawoval=function (X,y,rx,ry) {
This.moveto (X+rx,y);
This.curveto (Rx+x,0.4142*ry+y,0.7071*rx+x,0.7071*ry+y);
This.curveto (0.4142*rx+x,ry+y,x,ry+y);
This.curveto ( -0.4142*rx+x,ry+y,-0.7071*rx+x,0.7071*ry+y);
This.curveto (-rx+x,0.4142*ry+y,-rx+x,y);
This.curveto (-rx+x,-0.4142*ry+y,-0.7071*rx+x,-0.7071*ry+y);
This.curveto ( -0.4142*rx+x,-ry+y,x,-ry+y);
This.curveto (0.4142*rx+x,-ry+y,0.7071*rx+x,-0.7071*ry+y);
This.curveto (Rx+x,-0.4142*ry+y,rx+x,y);
}



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.