这两天在研究关于as画图的问题,经过一番折腾后终于是出来了,(部分代码来源于 programming macromedia flash mx)
AS:
MovieClip.prototype.drawRegAng = function(x, y, r, num, rotation) {
/*参数说明:x,y:多边形的中心坐标;r:多边形半径;num:多边形边数;最后一个是旋转角度*/
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);
//初始化变量
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);
圆形:
[url=http://www.blueidea.com/articleimg/2006/04/3373/circle.swf][/url]
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);
}