|
功能说明:
设置图形的颜色,粗细和透明度;
画直线 drawLine;
画曲线 drawCurve;
画矩形 drawRect;
填充矩形 fillRect;
画圆形 drawCircle;
填充圆形 fillCircle;
画椭圆 drawOval;
填充椭圆 fillOval;
程序代码
以下是Graphics.as类代码段:
/*
* Name:Graphics.as
* Author:Kinglong
* Email:qiankinglong@hotmail.com
* Date:2004-11-4
* Ver:0.60
*/
class com.klstudio.Graphics extends MovieClip {
private var __clr:Number;
private var __mc:MovieClip;
private var __thick:Number;
function Graphics(_mc:MovieClip) {
if (_mc == undefined || _mc == null) {
this.__mc = _root;
} else {
this.__mc = _mc;
}
this.setColor(0x000000);
this.setThick(1);
}
//设置线框色;
public function setColor(_color:Number):Void {
this.__clr = _color;
}
//设置线框宽度;
public function setThick(_thick:Number):Void {
this.__thick = _thick;
}
//画直线;
public function drawLine(_x1:Number, _y1:Number, _x2:Number, _y2:Number, _a:Number):Void {
if (arguments.length<4) {
trace("※错误※"+newline+"参数不足!");
} else {
if (_a == undefined || _a == null) {
_a = 100;
}
this.__mc.lineStyle(this.__thick, this.__clr, _a);
this.__mc.moveTo(_x1, _y1);
this.__mc.lineTo(_x2, _y2);
}
}
//画矩形;
public function drawRect(_x0:Number, _y0:Number, _w:Number, _h:Number, _a:Number):Void {
if (arguments.length<4) {
trace("※错误※"+newline+"参数不足!");
} else {
if (_a == undefined || _a == null) {
_a = 100;
}
this.__mc.lineStyle(this.__thick, this.__clr, _a);
this.__mc.moveTo(_x0, _y0);
this.__mc.lineTo(_x0+_w, _y0);
this.__mc.lineTo(_x0+_w, _y0+_h);
this.__mc.lineTo(_x0, _y0+_h);
this.__mc.lineTo(_x0, _y0);
}
}
//填充矩形;
public function fillRect(_x0:Number, _y0:Number, _w:Number, _h:Number, _a:Number):Void {
if (arguments.length<4) {
trace("※错误※"+newline+"参数不足!");
} else {
if (_a == undefined || _a == null) {
_a = 100;
}
this.__mc.lineStyle();
this.__mc.moveTo(_x0, _y0);
this.__mc.beginFill(this.__clr, _a);
this.__mc.lineTo(_x0+_w, _y0);
this.__mc.lineTo(_x0+_w, _y0+_h);
this.__mc.lineTo(_x0, _y0+_h);
this.__mc.lineTo(_x0, _y0);
this.__mc.endFill();
}
}
//画曲线;
public function drawCurve(_sx:Number, _sy:Number, _cx:Number, _cy:Number, _ex:Number, _ey:Number, _a:Number):Void {
if (arguments.length<6) {
trace("※错误※"+newline+"参数不足!");
} else {
if (_a == undefined || _a == null) {
_a = 100;
}
this.__mc.lineStyle(this.__thick, this.__clr, _a);
this.__mc.moveTo(_sx, _sy);
this.__mc.curveTo(_cx, _cy, _ex, _ey);
}
}
//画椭圆;
function drawOval(_x0:Number, _y0:Number, _w:Number, _h:Number, _a:Number):Void {
if (arguments.length<4) {
trace("※错误※"+newline+"参数不足!");
} else {
if (_a == undefined || _a == null) {
_a = 100;
}
var j:Number = _w*0.70711;
var n:Number = _h*0.70711;
var i:Number = j-(_h-n)*_w/_h;
var m:Number = n-(_w-j)*_h/_w;
this.__mc.lineStyle(this.__thick, this.__clr, _a);
this.__mc.moveTo(_x0+_w, _y0);
this.__mc.curveTo(_x0+_w, _y0-m, _x0+j, _y0-n);
this.__mc.curveTo(_x0+i, _y0-_h, _x0, _y0-_h);
this.__mc.curveTo(_x0-i, _y0-_h, _x0-j, _y0-n);
this.__mc.curveTo(_x0-_w, _y0-m, _x0-_w, _y0);
this.__mc.curveTo(_x0-_w, _y0+m, _x0-j, _y0+n);
this.__mc.curveTo(_x0-i, _y0+_h, _x0, _y0+_h);
this.__mc.curveTo(_x0+i, _y0+_h, _x0+j, _y0+n);
this.__mc.curveTo(_x0+_w, _y0+m, _x0+_w, _y0);
}
}
//填充椭圆;
function fillOval(_x0:Number, _y0:Number, _w:Number, _h:Number, _a:Number):Void {
if (arguments.length<4) {
trace("※错误※"+newline+"参数不足!");
} else {
if (_a == undefined || _a == null) {
_a = 100;
}
var j:Number = _w*0.70711;
var n:Number = _h*0.70711;
var i:Number = j-(_h-n)*_w/_h;
var m:Number = n-(_w-j)*_h/_w;
this.__mc.lineStyle();
this.__mc.moveTo(_x0+_w, _y0);
this.__mc.beginFill(this.__clr, _a);
this.__mc.curveTo(_x0+_w, _y0-m, _x0+j, _y0-n);
this.__mc.curveTo(_x0+i, _y0-_h, _x0, _y0-_h);
this.__mc.curveTo(_x0-i, _y0-_h, _x0-j, _y0-n);
this.__mc.curveTo(_x0-_w, _y0-m, _x0-_w, _y0);
this.__mc.curveTo(_x0-_w, _y0+m, _x0-j, _y0+n);
this.__mc.curveTo(_x0-i, _y0+_h, _x0, _y0+_h);
this.__mc.curveTo(_x0+i, _y0+_h, _x0+j, _y0+n);
this.__mc.curveTo(_x0+_w, _y0+m, _x0+_w, _y0);
this.__mc.endFill();
}
}
//画圆形;
function drawCircle(_r:Number, _x0:Number, _y0:Number, _a:Number):Void {
if (arguments.length<3) {
trace("※错误※"+newline+"参数不足!");
} else {
if (_a == undefined || _a == null) {
_a = 100;
}
this.__mc.lineStyle(this.__thick, this.__clr, _a);
this.__mc.moveTo(_x0+_r, _y0);
var _s:Number = Math.tan(22.5*Math.PI/180);
for (var angle = 45; angle<=360; angle += 45) {
var endX:Number = _r*Math.cos(angle*Math.PI/180);
var endY:Number = _r*Math.sin(angle*Math.PI/180);
var cX:Number = endX+_r*_s*Math.cos((angle-90)*Math.PI/180);
var cY:Number = endY+_r*_s*Math.sin((angle-90)*Math.PI/180);
this.__mc.curveTo(cX+_x0, cY+_y0, endX+_x0, endY+_y0);
}
}
}
//填充圆形;
function fillCircle(_r:Number, _x0:Number, _y0:Number, _a:Number):Void {
if (arguments.length<3) {
trace("※错误※"+newline+"参数不足!");
} else {
if (_a == undefined || _a == null) {
_a = 100;
}
this.__mc.lineStyle();
this.__mc.moveTo(_x0+_r, _y0);
var _s:Number = Math.tan(22.5*Math.PI/180);
this.__mc.beginFill(this.__clr, _a);
for (var angle = 45; angle<=360; angle += 45) {
var endX:Number = _r*Math.cos(angle*Math.PI/180);
var endY:Number = _r*Math.sin(angle*Math.PI/180);
var cX:Number = endX+_r*_s*Math.cos((angle-90)*Math.PI/180);
var cY:Number = endY+_r*_s*Math.sin((angle-90)*Math.PI/180);
this.__mc.curveTo(cX+_x0, cY+_y0, endX+_x0, endY+_y0);
}
this.__mc.endFill();
}
}
} |
|