http://space.flash8.net/bbs/thread-337869-1-1.html
今天我就来点系统的利用as画图(画圆、画扇形、画椭圆、画立体扇形、画立体饼图),同时我希望闪吧成员们能多发点原创的作品:) 下面的我所发的代码中如果有不足之处请大家包涵,也可以发表自己的观点。:lol 首先利用as画圆: 代码产生效果图: _root.createEmptyMovieClip("circle", 0); MovieClip.prototype.drawCircel = function(x0, y0, r) { this.lineStyle(1, 0x0000ff, 100); this.moveTo(x0+r, y0); pi = Math.PI/180; h = 0; while (h<2*Math.PI) { h += pi; x = x0+r*Math.cos(h); y = y0+r*Math.sin(h); this.lineTo(x, y); } }; _root.circle.drawCircel(0, 0, 100); _root.circle._x = 200; _root.circle._y = 200; |
-
圆.jpg (6.02 KB)
as代码生成扇形图:
_root.createEmptyMovieClip("circle", 0);
MovieClip.prototype.drawCircel = function(x0, y0, r) {
this.lineStyle(1, 0x0000ff, 100);
this.moveTo(x0, y0);
this.lineTo(x0+r, y0);
pi = Math.PI/180;
h = 0;
while (h<2*Math.PI/3) {
h += pi;//循环改变角度
x = x0+r*Math.cos(h);
y = y0-r*Math.sin(h);
this.lineTo(x, y);
}
this.lineTo(x0, y0);
};
_root.circle.drawCircel(0, 0, 100);
_root.circle._x = 200;
_root.circle._y = 200;-
扇形.jpg (4.55 KB)
as生成椭圆效果图:
_root.createEmptyMovieClip("circle", 0);
MovieClip.prototype.drawCircel = function(x0, y0, r) {
lineStyle(1, 0xff0000, 100);
//beginFill(0x2e24f6, 100);
//moveTo(x0, y0);
//lineTo(x0+r, y0);
moveTo(x0+r, y0);
pi = Math.PI/180;
rotate = Math.PI/6;
h = 0;
//trace(2*Math.PI);
while (h<2*Math.PI) {
h += pi;
x = x0+r*Math.cos(h);
y = y0+r*Math.sin(h);
y = y*Math.cos(rotate);
lineTo(x, y);
}
endFill();
};
_root.circle.drawCircel(100, 100, 100);
_root.circle._x = 400;
_root.circle._y = 500;-
椭圆.jpg (5.81 KB)
as生成立体扇形效果图:
_root.createEmptyMovieClip("circle", 0);
MovieClip.prototype.drawCircel = function(x0, y0, r, a, height) {
this.lineStyle(1, 0xec9a0a, 70);
pi = Math.PI/180;
rotate = pi*a;
h = 0;
//trace(2*Math.PI);
for (i=0; i<height; i++) {
h = 0;
this.beginFill(0xfdbc49, 20);
this.moveTo(x0,y0-i)
this.lineTo(x0+r, y0-i);
while ( h<Math.PI/3) {
h += pi;
//trace(h);
x = x0+r*Math.cos(h);
y = y0-r*Math.sin(h);
y = y*Math.cos(rotate);
y = y-i;
this.lineTo(x, y);
}
this.lineTo(x0, y0-i);
this.endFill();
}
};
_root.circle.drawCircel(0, 0, 200, 60, 20);
_root.circle._x = 200;
_root.circle._y = 200;-
立体扇形.jpg (5.08 KB)
-
-
as生成立体圆形效果图:
_root.createEmptyMovieClip("circle", 0);
MovieClip.prototype.drawCircel = function(x0, y0, r, a) {
this.lineStyle(1,0xd76b02, 100);
pi = Math.PI/180;
rotate = pi*a;
h = 0;
//trace(2*Math.PI);
for (i=0; i<20; i++) {
this.beginFill(0xf98a1e, 100);
this.moveTo(x0+r, y0-i);
while (h<2*Math.PI) {
h += pi;
x = x0+r*Math.cos(h);
y = y0-r*Math.sin(h);
y = y*Math.cos(rotate);
y = y-i;
this.lineTo(x, y);
}
h = 0;
this.endFill();
}
};
_root.circle.drawCircel(0, 0, 100, 60);
_root.circle._x = 400;
_root.circle._y = 200;-
立体椭圆.jpg (5.42 KB)
as生成饼状效果图:
_root.createEmptyMovieClip("circle", 0);
var jiaodu:Array = new Array();
jiaodu[0] = 15*Math.PI/180;
jiaodu[1] = 120*Math.PI/180;
jiaodu[2] = 160*Math.PI/180;
jiaodu[3] = 190*Math.PI/180;
jiaodu[4] = 260*Math.PI/180;
jiaodu[5] = 360*Math.PI/180+15*Math.PI/180;
//==============
var percent:Array = new Array();
for (s=0; s<jiaodu.length-1; s++) {
percent[s] = (jiaodu[s+1]-jiaodu[s])/(2*Math.PI)*100/100;
}
//==========
var fillColor:Array = new Array();
fillColor[0] = 0x0ff97d;
fillColor[1] = 0xfdbc49;
fillColor[2] = 0x396da5;
fillColor[3] = 0xfa303e;
fillColor[4] = 0xf4f63d;
var lineColor:Array = new Array();
lineColor[0] = 0x03ad53;
lineColor[1] = 0xec9a0a;
lineColor[2] = 0x013a77;
lineColor[3] = 0xd90514;
lineColor[4] = 0xd7da04;
MovieClip.prototype.drawCircel = function(x0, y0, r, a, height) {
pi = Math.PI/180;
rotate = pi*a;
for (c=0; c<lineColor.length; c++) {
//trace(2*Math.PI);
this.createEmptyMovieClip("shanxing"+c, c);
//计算每个扇形的中间度数,然后让其mc进行相应的位移移动
movie0 = (jiaodu[c+1]-jiaodu[c])/2+jiaodu[c];
this["shanxing"+c].movex = x0+30*Math.cos(movie0);
this["shanxing"+c].movey = (y0-30*Math.sin(movie0))*Math.cos(rotate);
this["shanxing"+c].statu = false;
//表示扇形没有移动,true表示已经移动
//==============================
this["shanxing"+c].lineStyle(1, lineColor[c], 100);
//trace(c);
//this["shanxing"+c].startDS=jiaodu[c]
//==================================================
for (i=0; i<height; i++) {
h = jiaodu[c];
this["shanxing"+c].beginFill(fillColor[c], 100);
this["shanxing"+c].moveTo(x0, y0-i);
this["shanxing"+c].lineTo(x0+r*Math.cos(jiaodu[c]), (y0-r*Math.sin(jiaodu[c]))*Math.cos(rotate)-i);
while (h>=jiaodu[c] and h<jiaodu[c+1]) {
h += pi;
x = x0+r*Math.cos(h);
y = y0-r*Math.sin(h);
y = y*Math.cos(rotate);
y = y-i;
this["shanxing"+c].lineTo(x, y);
}
this["shanxing"+c].lineTo(x0, y0-i);
this["shanxing"+c].endFill();
}
//=======================================================
//从每个扇形的曲边中间画出一条引线
this["shanxing"+c].lineStyle(1, 0x0000ff, 100);
this["shanxing"+c].lax0 = x0+r*Math.cos(movie0);
this["shanxing"+c].lay0 = (y0-r*Math.sin(movie0))*Math.cos(rotate)-height;
this["shanxing"+c].lax1 = x0+(r+50)*Math.cos(movie0);
this["shanxing"+c].lay1 = (y0-(r+50)*Math.sin(movie0))*Math.cos(rotate)-height;
this["shanxing"+c].moveTo(this["shanxing"+c].lax0, this["shanxing"+c].lay0);
this["shanxing"+c].lineTo(this["shanxing"+c].lax1, this["shanxing"+c].lay1);
//======================================================
//创建一个动态的createTextField,显示所占整个圆的比例
var myformat = new TextFormat();
with (myformat) {
font = "Arial";
bold = true;
size = 12;
}
if (Math.PI/2>movie0 and movie0>=0) {
this["shanxing"+c].createTextField("text"+c, this["shanxing"+c].getNextHighestDepth(), this["shanxing"+c].lax1, this["shanxing"+c].lay1-25, 50, 20);
}
if (Math.PI>movie0 and movie0>=Math.PI/2) {
this["shanxing"+c].createTextField("text"+c, this["shanxing"+c].getNextHighestDepth(), this["shanxing"+c].lax1-25, this["shanxing"+c].lay1-25, 50, 20);
}
if (3*Math.PI/2>movie0 and movie0>=Math.PI) {
this["shanxing"+c].createTextField("text"+c, this["shanxing"+c].getNextHighestDepth(), this["shanxing"+c].lax1-25, this["shanxing"+c].lay1, 50, 20);
}
if (2*Math.PI>movie0 and movie0>=3*Math.PI/2) {
this["shanxing"+c].createTextField("text"+c, this["shanxing"+c].getNextHighestDepth(), this["shanxing"+c].lax1, this["shanxing"+c].lay1, 50, 20);
}
this["shanxing"+c]["text"+c].border = false;
this["shanxing"+c]["text"+c].text = Math.round(percent[c]*100)+"%";
this["shanxing"+c]["text"+c].textColor = 0xff0000;
this["shanxing"+c]["text"+c].setTextFormat(myformat);
//=======================================================
}
for (i=0; i<lineColor.length; i++) {
//trace(i)
this.createEmptyMovieClip("example"+i, this.getNextHighestDepth());
this["example"+i].lineStyle(1, lineColor, 100);
this["example"+i].beginFill(fillColor, 100);
this["example"+i].moveTo(0, 0);
this["example"+i].lineTo(0, 30);
this["example"+i].lineTo(30, 30);
this["example"+i].lineTo(30, 0);
this["example"+i].lineTo(0, 0);
this["example"+i].endFill();
this["example"+i]._x=240
this["example"+i]._y=40*i
this["example"+i].createTextField("exm"+i,this["example"+i].getNextHighestDepth(),this["example"+i]._x+50,this["example"+i]._y,30,10)
this["example"+i]["exm"+i].border = true;
//this["example"+i]["exm"+i].text = "aa";
}
};
_root.circle.drawCircel(0, 0, 200, 50, 20);
_root.circle._x = 300;
_root.circle._y = 200;
for (j=0; j<5; j++) {
_root.circle["shanxing"+j].onRelease = function() {
if (this.statu == false) {
this._x += this.movex;
this._y += this.movey;
this.statu = true;
//this._alpha=30
} else {
this._x -= this.movex;
this._y -= this.movey;
this.statu = false;
//this._alpha=100
}
};
}-
饼图.jpg (17.37 KB)
}
};
_root.circle.drawCircel(0, 0, 200, 50, 20);
_root.circle._x = 300;
_root.circle._y = 200;
for (j=0; j<5; j++) {
_root.circle["shanxing"+j].onRelease = function() {
if (this.statu == false) {
this._x += this.movex;
this._y += this.movey;
this.statu = true;
//this._alpha=30
} else {
this._x -= this.movex;
this._y -= this.movey;
this.statu = false;
//this._alpha=100
}
};
}-
饼图.jpg (17.37 KB)
-