偶尔搜索论坛,看到zjs35老师的这个库,转过来,慢慢研究~~
// 该库增加了FlashMX中MovieClip对象所未提供的数个常用绘图函数。
// 绘图状态设置函数:
// MovieClip.lineStyle(thickness, rgb, alpha)
// MovieClip.getLineStyle()
// 相对坐标绘图函数:
// MovieClip.setRelOrigin(x, y)
// MovieClip.moveRel(dx, dy)
// MovieClip.lineRel(dx, dy)
// MovieClip.curveRel(dxControl, dyControl, dx, dy)
// 基本扩展绘图函数:
// MovieClip.line(x1, y1, x2, y2, thickness, rgb, alpha)
// MovieClip.rect(left, top, right, bottom)
// MovieClip.rect2(x, y, width, height)
// MovieClip.box(left, top, right, bottom, thickness, rgb, alpha)
// MovieClip.box2(x, y, width, height, thickness, rgb, alpha)
// MovieClip.bar(left, top, right, bottom, rgb, alpha)
// MovieClip.bar2(x, y, width, height, rgb, alpha)
// MovieClip.polygen(points)
// MovieClip.polyLine(points, thickness, rgb, alpha)
// MovieClip.polyFill(points, rgb, alpha)
// MovieClip.ellipse(x, y, xradius, yradius)
// MovieClip.ellipseLine(x, y, xradius, yradius, thickness, rgb, alpha)
// MovieClip.ellipseFill(x, y, xradius, yradius, rgb, alpha)
// MovieClip.arc(x, y, xradius, yradius, stangle, endangle)
// MovieClip.sector(x, y, xradius, yradius, stangle, endangle)
// MovieClip.sectorLine(x, y, xradius, yradius, stangle, endangle, thickness, rgb, alpha)
// MovieClip.sectorFill(x, y, xradius, yradius, stangle, endangle, rgb, alpha)
// MovieClip.npolygen(x, y, radius, snum, offangle)
// MovieClip.npolyLine(x, y, radius, snum, offangle, thickness, rgb, alpha)
// MovieClip.npolyFill(x, y, radius, snum, offangle, rgb, alpha)
// 数学图象绘图函数:
// MovieClip.parabola(x, y, k, x1, x2)
// MovieClip.wave(x, y, kx, ky, x1, x2)
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// ◎ 绘图状态设置函数 ◎
//-------------------------------------------------------------------
// 设置线型(参数未指明或者值为null或undefined则该参数使用默认值)
// thickness: 线条粗细(0~255,默认为0),0表示极细线
// rgb: 线条颜色(0x000000~0xffffff,默认为0x000000)
// alpha: 线条透明度(1~100,默认为100)
MovieClip.prototype.mLineStyle = MovieClip.prototype.lineStyle;
MovieClip.prototype.lineStyle = function(thickness, rgb, alpha) {
this.m_thickness = thickness == null ? 0 : Number(thickness);
this.m_rgb = rgb == null ? 0x000000 : int(rgb);
this.m_alpha = alpha == null ? 100 : int(alpha);
with (this) {
m_thickness = m_thickness > 255 ? 255
: m_thickness >= 0 ? m_thickness
: 0;
m_rgb = m_rgb > 0xffffff ? 0xffffff
: m_rgb >= 0x000000 ? m_rgb
: 0x000000;
m_alpha = m_alpha > 100 ? 100
: m_alpha >= 0 ? m_alpha
: 0;
mLineStyle(m_thickness, m_rgb, m_alpha);
}
};
//-------------------------------------------------------------------
// 获取当前线型
// 返回值: {thickness, rgb, alpha}
MovieClip.prototype.getLineStyle = function() {
return {
thickness : m_thickness,
rgb : m_rgb,
alpha : m_alpha
};
};
//-------------------------------------------------------------------
// ◎ 相对坐标绘图函数 ◎
//-------------------------------------------------------------------
// 设置相对坐标原点,并将当前绘图坐标移动到该位置
// x, y: 原点坐标
MovieClip.prototype.setRelOrigin = function(x, y) {
this.m_relOrigX = x;
this.m_relOrigY = y;
this.moveTo(this.m_relOrigX, this.m_relOrigY);
};
//-------------------------------------------------------------------
// 按相对坐标移动当前绘图位置,并将新的位置作为相对坐标原点
// dx, dy: 相对坐标
MovieClip.prototype.moveRel = function(dx, dy) {
this.m_relOrigX += dx;
this.m_relOrigY += dy;
this.moveTo(this.m_relOrigX, this.m_relOrigY);
};
//-------------------------------------------------------------------
// 按相对坐标绘制直线,并将新的位置作为相对坐标原点
// dx, dy: 相对坐标
MovieClip.prototype.lineRel = function(dx, dy) {
this.m_relOrigX += dx;
this.m_relOrigY += dy;
this.lineTo(this.m_relOrigX, this.m_relOrigY);
};
//-------------------------------------------------------------------
// 按相对坐标绘制曲线,并将新的位置作为相对坐标原点
// dxControl, dyControl: 控制点相对坐标
// dx, dy: 终点相对坐标
MovieClip.prototype.curveRel = function(dxControl, dyControl, dx, dy) {
this.curveTo(this.m_relOrigX + dxControl, this.m_relOrigY + dyControl,
this.m_relOrigX + dx, this.m_relOrigY + dy);
this.m_relOrigX += dx;
this.m_relOrigY += dy;
};
//-------------------------------------------------------------------
◎ 基本扩展绘图函数 ◎
//-------------------------------------------------------------------
// 绘制一条直线
// x1, y1: 起点坐标
// x2, y2: 终点坐标
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.line = function (x1, y1, x2, y2, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.moveTo(x1, y1);
this.lineTo(x2, y2);
};
//-------------------------------------------------------------------
// 绘制矩形,使用当前线型和填充模式
// left, top, right, bottom: 坐标范围
// x, y, width, height: 位置和大小
MovieClip.prototype.rect = function(left, top, right, bottom) {
this.moveTo(left, top);
this.lineTo(right, top);
this.lineTo(right, bottom);
this.lineTo(left, bottom);
this.lineTo(left, top);
};
MovieClip.prototype.rect2 = function(x, y, width, height) {
this.rect(x, y, x + width, y + height);
};
//-------------------------------------------------------------------
// 绘制矩形线框,无填充
// left, top, right, bottom: 坐标范围
// x, y, width, height: 位置和大小
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.box = function(left, top, right, bottom, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.rect(left, top, right, bottom);
};
MovieClip.prototype.box2 = function(x, y, width, height, thickness, rgb, alpha) {
this.box(x, y, x + width, y + height, thickness, rgb, alpha);
};
//-------------------------------------------------------------------
// 绘制矩形色块,无边框
// left, top, right, bottom: 坐标范围
// x, y, width, height: 位置和大小
// rgb, alpha: 填充颜色(未指定或者值为null或undefined则使用默认值)
MovieClip.prototype.bar = function(left, top, right, bottom, rgb, alpha) {
this.lineStyle();
this.beginFill(
rgb == null ? 0 : rgb,
alpha == null ? 100 : alpha
);
this.rect(left, top, right, bottom);
this.endFill();
};
MovieClip.prototype.bar2 = function(x, y, width, height, rgb, alpha) {
this.bar(x, y, x + width, y + height, rgb, alpha);
};
// 绘制多边形,使用当前线型和填充模式
// points: 顶点坐标数组,数组元素形式为{x, y},如果线框需要闭合,则最后一个点必须与第一个点重合
MovieClip.prototype.polygen = function(points) {
if (points.length >= 2) {
this.moveTo(points[0].x, points[0].y);
for (var i = 1; i < points.length; i++) {
this.lineTo(points[i].x, points[i].y);
}
}
};
//-------------------------------------------------------------------
// 绘制多边形线框,无填充
// points: 顶点坐标数组,数组元素形式为{x, y},如果需要闭合,则最后一个点必须与第一个点重合
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.polyLine = function(points, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.polygen(points);
};
//-------------------------------------------------------------------
// 绘制多边形色块,无边框
// points: 顶点坐标数组,数组元素形式为{x, y}
// rgb, alpha: 填充颜色(未指定或者值为null或undefined则使用默认值)
MovieClip.prototype.polyFill = function(points, rgb, alpha) {
this.lineStyle();
this.beginFill(
rgb == null ? 0 : rgb,
alpha == null ? 100 : alpha
);
this.polygen(points);
this.endFill();
};
//----------------------------
// 绘制椭圆(圆)形,使用当前线型和填充模式
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
MovieClip.prototype.ellipse = function(x, y, xradius, yradius) {
if (yradius == null) yradius = xradius;
var controlx = xradius * (Math.SQRT2 - 1);
var controly = yradius * (Math.SQRT2 - 1);
var anchorx = xradius * Math.SQRT1_2;
var anchory = yradius * Math.SQRT1_2;
this.moveTo(x + xradius, y);
this.curveTo(x + xradius, y + controly, x + anchorx, y + anchory);
this.curveTo(x + controlx, y + yradius, x, y + yradius);
this.curveTo(x - controlx, y + yradius, x - anchorx, y + anchory);
this.curveTo(x - xradius, y + controly, x - xradius, y);
this.curveTo(x - xradius, y - controly, x - anchorx, y - anchory);
this.curveTo(x - controlx, y - yradius, x, y - yradius);
this.curveTo(x + controlx, y - yradius, x + anchorx, y - anchory);
this.curveTo(x + xradius, y - controly, x + xradius, y);
};
//-------------------------------------------------------------------
// 绘制椭圆(圆)形线框,无填充
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.ellipseLine = function(x, y, xradius, yradius, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.ellipse(x, y, xradius, yradius);
};
//-------------------------------------------------------------------
// 绘制椭圆(圆)形色块,无边框
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// rgb, alpha: 填充颜色(未指定或者值为null或undefined则使用默认值)
MovieClip.prototype.ellipseFill = function(x, y, xradius, yradius, rgb, alpha) {
this.lineStyle();
this.beginFill(
rgb == null ? 0 : rgb,
alpha == null ? 100 : alpha
);
this.ellipse(x, y, xradius, yradius);
this.endFill();
};
//-------------------------------------------------------------------
// 绘制椭圆(圆)弧,使用当前线型和填充模式
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// stangle, endangle: 起止角度
MovieClip.prototype.arc = function(x, y, xradius, yradius, stangle, endangle) {
if (endangle == stangle) return;
if (Math.abs(endangle - stangle) >= 360) {
this.ellipse(x, y, xradius, yradius);
return;
}
if (yradius == null) yradius = xradius;
var curAngle = stangle;
var nextAngle = stangle < endangle ? (Math.floor(stangle / 45) + 1) * 45 :
(Math.ceil(stangle / 45) - 1) * 45;
var midcos, midAngle, controlx, controly, anchorx, anchory;
this.moveTo(x + Math.cos(stangle * Math.PI / 180) * xradius,
y + Math.sin(stangle * Math.PI / 180) * yradius);
while (true) {
if (stangle < endangle && nextAngle > endangle ||
stangle > endangle && nextAngle < endangle) nextAngle = endangle;
midcos = Math.cos((nextAngle - curAngle) / 2 * Math.PI / 180);
midAngle = (nextAngle + curAngle) / 2 * Math.PI / 180;
controlx = x + Math.cos(midAngle) / midcos * xradius;
controly = y + Math.sin(midAngle) / midcos * yradius;
anchorx = x + Math.cos(nextAngle * Math.PI / 180) * xradius;
anchory = y + Math.sin(nextAngle * Math.PI / 180) * yradius;
this.curveTo(controlx, controly, anchorx, anchory);
if (nextAngle == endangle) break;
curAngle = nextAngle;
nextAngle += stangle < endangle ? 45 : -45;
}
};
//-------------------------------------------------------------------
// 绘制扇形,使用当前线型和填充模式
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// stangle, endangle: 起止角度
MovieClip.prototype.sector = function(x, y, xradius, yradius, stangle, endangle) {
this.arc(x, y, xradius, yradius, stangle, endangle);
if (Math.abs(stangle - endangle) > 0 && Math.abs(stangle - endangle) < 360) {
this.lineTo(x, y);
this.lineTo(x + Math.cos(stangle * Math.PI / 180) * xradius,
y + Math.sin(stangle * Math.PI / 180) * yradius);
}
};
//-------------------------------------------------------------------
// 绘制扇形线框,无填充
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// stangle, endangle: 起止角度
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.sectorLine = function(x, y, xradius, yradius, stangle, endangle, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.sector(x, y, xradius, yradius, stangle, endangle);
};
//-------------------------------------------------------------------
// 绘制扇形色块,无边框
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// stangle, endangle: 起止角度
// rgb, alpha: 填充颜色(未指定或者值为null或undefined则使用默认值)
MovieClip.prototype.sectorFill = function(x, y, xradius, yradius, stangle, endangle, rgb, alpha) {
this.lineStyle();
this.beginFill(
rgb == null ? 0 : rgb,
alpha == null ? 100 : alpha
);
this.sector(x, y, xradius, yradius, stangle, endangle);
this.endFill();
};
//---------------------------------------------------------------
◎ 数学图象绘图函数 ◎
//-------------------------------------------------------------------
// 绘制抛物线
// x, y: 顶点坐标
// k: 比例系数
// x1, x2: 抛物线起止x坐标
MovieClip.prototype.parabola = function(x, y, k, x1, x2) {
this.moveTo(x1, y + k * (x1 - x) * (x1 - x));
this.curveTo((x1 + x2) / 2, y + k * (x1 - x) * (x2 - x), x2, y + k * (x2 - x) * (x2 - x));
};
//-------------------------------------------------------------------
// 绘制波形线(正弦曲线)
// x, y: 中心点坐标
// kx, ky: x轴及y轴的缩放比例
// x1, x2: 波形线起止x坐标
MovieClip.prototype.wave = function(x, y, kx, ky, x1, x2) {
if (x1 == x2 || kx == 0) return;
var pi_6 = Math.PI / 6;
var i = 1;
var beginx = (x1 - x) / kx;
var endx = (x2 - x) / kx;
var curx = beginx;
var nextx = beginx < endx ? (Math.floor(curx / pi_6) + 1) * pi_6 :
(Math.ceil(curx / pi_6) - 1) * pi_6;
var coscx = Math.cos(curx);
var cccsc = coscx * curx - Math.sin(curx);
var cosnx, cnnsn, controlx, controly, anchorx, anchory;
this.moveTo(x1, y + ky * Math.sin(curx));
while (true) {
if (beginx < endx && nextx > endx || beginx > endx && nextx < endx) nextx = endx;
cosnx = Math.cos(nextx);
cnnsn = cosnx * nextx - Math.sin(nextx);
controlx = x + kx * (cccsc - cnnsn) / (coscx - cosnx);
controly = y + ky * (cccsc * cosnx - cnnsn * coscx) / (coscx - cosnx);
anchorx = x + kx * nextx;
anchory = y + ky * Math.sin(nextx);
this.curveTo(controlx, controly, anchorx, anchory);
if (Math.abs(nextx - endx) < 1e-10) break;
beginx < endx ? i++ : i--;
curx = nextx;
coscx = cosnx;
cccsc = cnnsn;
nextx = beginx + i * pi_6;
}
};
//-------------------------------------------------------------------
// 该库增加了FlashMX中MovieClip对象所未提供的数个常用绘图函数。
// 绘图状态设置函数:
// MovieClip.lineStyle(thickness, rgb, alpha)
// MovieClip.getLineStyle()
// 相对坐标绘图函数:
// MovieClip.setRelOrigin(x, y)
// MovieClip.moveRel(dx, dy)
// MovieClip.lineRel(dx, dy)
// MovieClip.curveRel(dxControl, dyControl, dx, dy)
// 基本扩展绘图函数:
// MovieClip.line(x1, y1, x2, y2, thickness, rgb, alpha)
// MovieClip.rect(left, top, right, bottom)
// MovieClip.rect2(x, y, width, height)
// MovieClip.box(left, top, right, bottom, thickness, rgb, alpha)
// MovieClip.box2(x, y, width, height, thickness, rgb, alpha)
// MovieClip.bar(left, top, right, bottom, rgb, alpha)
// MovieClip.bar2(x, y, width, height, rgb, alpha)
// MovieClip.polygen(points)
// MovieClip.polyLine(points, thickness, rgb, alpha)
// MovieClip.polyFill(points, rgb, alpha)
// MovieClip.ellipse(x, y, xradius, yradius)
// MovieClip.ellipseLine(x, y, xradius, yradius, thickness, rgb, alpha)
// MovieClip.ellipseFill(x, y, xradius, yradius, rgb, alpha)
// MovieClip.arc(x, y, xradius, yradius, stangle, endangle)
// MovieClip.sector(x, y, xradius, yradius, stangle, endangle)
// MovieClip.sectorLine(x, y, xradius, yradius, stangle, endangle, thickness, rgb, alpha)
// MovieClip.sectorFill(x, y, xradius, yradius, stangle, endangle, rgb, alpha)
// MovieClip.npolygen(x, y, radius, snum, offangle)
// MovieClip.npolyLine(x, y, radius, snum, offangle, thickness, rgb, alpha)
// MovieClip.npolyFill(x, y, radius, snum, offangle, rgb, alpha)
// 数学图象绘图函数:
// MovieClip.parabola(x, y, k, x1, x2)
// MovieClip.wave(x, y, kx, ky, x1, x2)
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// ◎ 绘图状态设置函数 ◎
//-------------------------------------------------------------------
// 设置线型(参数未指明或者值为null或undefined则该参数使用默认值)
// thickness: 线条粗细(0~255,默认为0),0表示极细线
// rgb: 线条颜色(0x000000~0xffffff,默认为0x000000)
// alpha: 线条透明度(1~100,默认为100)
MovieClip.prototype.mLineStyle = MovieClip.prototype.lineStyle;
MovieClip.prototype.lineStyle = function(thickness, rgb, alpha) {
this.m_thickness = thickness == null ? 0 : Number(thickness);
this.m_rgb = rgb == null ? 0x000000 : int(rgb);
this.m_alpha = alpha == null ? 100 : int(alpha);
with (this) {
m_thickness = m_thickness > 255 ? 255
: m_thickness >= 0 ? m_thickness
: 0;
m_rgb = m_rgb > 0xffffff ? 0xffffff
: m_rgb >= 0x000000 ? m_rgb
: 0x000000;
m_alpha = m_alpha > 100 ? 100
: m_alpha >= 0 ? m_alpha
: 0;
mLineStyle(m_thickness, m_rgb, m_alpha);
}
};
//-------------------------------------------------------------------
// 获取当前线型
// 返回值: {thickness, rgb, alpha}
MovieClip.prototype.getLineStyle = function() {
return {
thickness : m_thickness,
rgb : m_rgb,
alpha : m_alpha
};
};
//-------------------------------------------------------------------
// ◎ 相对坐标绘图函数 ◎
//-------------------------------------------------------------------
// 设置相对坐标原点,并将当前绘图坐标移动到该位置
// x, y: 原点坐标
MovieClip.prototype.setRelOrigin = function(x, y) {
this.m_relOrigX = x;
this.m_relOrigY = y;
this.moveTo(this.m_relOrigX, this.m_relOrigY);
};
//-------------------------------------------------------------------
// 按相对坐标移动当前绘图位置,并将新的位置作为相对坐标原点
// dx, dy: 相对坐标
MovieClip.prototype.moveRel = function(dx, dy) {
this.m_relOrigX += dx;
this.m_relOrigY += dy;
this.moveTo(this.m_relOrigX, this.m_relOrigY);
};
//-------------------------------------------------------------------
// 按相对坐标绘制直线,并将新的位置作为相对坐标原点
// dx, dy: 相对坐标
MovieClip.prototype.lineRel = function(dx, dy) {
this.m_relOrigX += dx;
this.m_relOrigY += dy;
this.lineTo(this.m_relOrigX, this.m_relOrigY);
};
//-------------------------------------------------------------------
// 按相对坐标绘制曲线,并将新的位置作为相对坐标原点
// dxControl, dyControl: 控制点相对坐标
// dx, dy: 终点相对坐标
MovieClip.prototype.curveRel = function(dxControl, dyControl, dx, dy) {
this.curveTo(this.m_relOrigX + dxControl, this.m_relOrigY + dyControl,
this.m_relOrigX + dx, this.m_relOrigY + dy);
this.m_relOrigX += dx;
this.m_relOrigY += dy;
};
//-------------------------------------------------------------------
◎ 基本扩展绘图函数 ◎
//-------------------------------------------------------------------
// 绘制一条直线
// x1, y1: 起点坐标
// x2, y2: 终点坐标
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.line = function (x1, y1, x2, y2, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.moveTo(x1, y1);
this.lineTo(x2, y2);
};
//-------------------------------------------------------------------
// 绘制矩形,使用当前线型和填充模式
// left, top, right, bottom: 坐标范围
// x, y, width, height: 位置和大小
MovieClip.prototype.rect = function(left, top, right, bottom) {
this.moveTo(left, top);
this.lineTo(right, top);
this.lineTo(right, bottom);
this.lineTo(left, bottom);
this.lineTo(left, top);
};
MovieClip.prototype.rect2 = function(x, y, width, height) {
this.rect(x, y, x + width, y + height);
};
//-------------------------------------------------------------------
// 绘制矩形线框,无填充
// left, top, right, bottom: 坐标范围
// x, y, width, height: 位置和大小
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.box = function(left, top, right, bottom, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.rect(left, top, right, bottom);
};
MovieClip.prototype.box2 = function(x, y, width, height, thickness, rgb, alpha) {
this.box(x, y, x + width, y + height, thickness, rgb, alpha);
};
//-------------------------------------------------------------------
// 绘制矩形色块,无边框
// left, top, right, bottom: 坐标范围
// x, y, width, height: 位置和大小
// rgb, alpha: 填充颜色(未指定或者值为null或undefined则使用默认值)
MovieClip.prototype.bar = function(left, top, right, bottom, rgb, alpha) {
this.lineStyle();
this.beginFill(
rgb == null ? 0 : rgb,
alpha == null ? 100 : alpha
);
this.rect(left, top, right, bottom);
this.endFill();
};
MovieClip.prototype.bar2 = function(x, y, width, height, rgb, alpha) {
this.bar(x, y, x + width, y + height, rgb, alpha);
};
// 绘制多边形,使用当前线型和填充模式
// points: 顶点坐标数组,数组元素形式为{x, y},如果线框需要闭合,则最后一个点必须与第一个点重合
MovieClip.prototype.polygen = function(points) {
if (points.length >= 2) {
this.moveTo(points[0].x, points[0].y);
for (var i = 1; i < points.length; i++) {
this.lineTo(points[i].x, points[i].y);
}
}
};
//-------------------------------------------------------------------
// 绘制多边形线框,无填充
// points: 顶点坐标数组,数组元素形式为{x, y},如果需要闭合,则最后一个点必须与第一个点重合
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.polyLine = function(points, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.polygen(points);
};
//-------------------------------------------------------------------
// 绘制多边形色块,无边框
// points: 顶点坐标数组,数组元素形式为{x, y}
// rgb, alpha: 填充颜色(未指定或者值为null或undefined则使用默认值)
MovieClip.prototype.polyFill = function(points, rgb, alpha) {
this.lineStyle();
this.beginFill(
rgb == null ? 0 : rgb,
alpha == null ? 100 : alpha
);
this.polygen(points);
this.endFill();
};
//----------------------------
// 绘制椭圆(圆)形,使用当前线型和填充模式
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
MovieClip.prototype.ellipse = function(x, y, xradius, yradius) {
if (yradius == null) yradius = xradius;
var controlx = xradius * (Math.SQRT2 - 1);
var controly = yradius * (Math.SQRT2 - 1);
var anchorx = xradius * Math.SQRT1_2;
var anchory = yradius * Math.SQRT1_2;
this.moveTo(x + xradius, y);
this.curveTo(x + xradius, y + controly, x + anchorx, y + anchory);
this.curveTo(x + controlx, y + yradius, x, y + yradius);
this.curveTo(x - controlx, y + yradius, x - anchorx, y + anchory);
this.curveTo(x - xradius, y + controly, x - xradius, y);
this.curveTo(x - xradius, y - controly, x - anchorx, y - anchory);
this.curveTo(x - controlx, y - yradius, x, y - yradius);
this.curveTo(x + controlx, y - yradius, x + anchorx, y - anchory);
this.curveTo(x + xradius, y - controly, x + xradius, y);
};
//-------------------------------------------------------------------
// 绘制椭圆(圆)形线框,无填充
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.ellipseLine = function(x, y, xradius, yradius, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.ellipse(x, y, xradius, yradius);
};
//-------------------------------------------------------------------
// 绘制椭圆(圆)形色块,无边框
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// rgb, alpha: 填充颜色(未指定或者值为null或undefined则使用默认值)
MovieClip.prototype.ellipseFill = function(x, y, xradius, yradius, rgb, alpha) {
this.lineStyle();
this.beginFill(
rgb == null ? 0 : rgb,
alpha == null ? 100 : alpha
);
this.ellipse(x, y, xradius, yradius);
this.endFill();
};
//-------------------------------------------------------------------
// 绘制椭圆(圆)弧,使用当前线型和填充模式
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// stangle, endangle: 起止角度
MovieClip.prototype.arc = function(x, y, xradius, yradius, stangle, endangle) {
if (endangle == stangle) return;
if (Math.abs(endangle - stangle) >= 360) {
this.ellipse(x, y, xradius, yradius);
return;
}
if (yradius == null) yradius = xradius;
var curAngle = stangle;
var nextAngle = stangle < endangle ? (Math.floor(stangle / 45) + 1) * 45 :
(Math.ceil(stangle / 45) - 1) * 45;
var midcos, midAngle, controlx, controly, anchorx, anchory;
this.moveTo(x + Math.cos(stangle * Math.PI / 180) * xradius,
y + Math.sin(stangle * Math.PI / 180) * yradius);
while (true) {
if (stangle < endangle && nextAngle > endangle ||
stangle > endangle && nextAngle < endangle) nextAngle = endangle;
midcos = Math.cos((nextAngle - curAngle) / 2 * Math.PI / 180);
midAngle = (nextAngle + curAngle) / 2 * Math.PI / 180;
controlx = x + Math.cos(midAngle) / midcos * xradius;
controly = y + Math.sin(midAngle) / midcos * yradius;
anchorx = x + Math.cos(nextAngle * Math.PI / 180) * xradius;
anchory = y + Math.sin(nextAngle * Math.PI / 180) * yradius;
this.curveTo(controlx, controly, anchorx, anchory);
if (nextAngle == endangle) break;
curAngle = nextAngle;
nextAngle += stangle < endangle ? 45 : -45;
}
};
//-------------------------------------------------------------------
// 绘制扇形,使用当前线型和填充模式
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// stangle, endangle: 起止角度
MovieClip.prototype.sector = function(x, y, xradius, yradius, stangle, endangle) {
this.arc(x, y, xradius, yradius, stangle, endangle);
if (Math.abs(stangle - endangle) > 0 && Math.abs(stangle - endangle) < 360) {
this.lineTo(x, y);
this.lineTo(x + Math.cos(stangle * Math.PI / 180) * xradius,
y + Math.sin(stangle * Math.PI / 180) * yradius);
}
};
//-------------------------------------------------------------------
// 绘制扇形线框,无填充
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// stangle, endangle: 起止角度
// thickness, rgb, alpha: 所用线型(未指定或者值为null或undefined则该参数保持原值)
MovieClip.prototype.sectorLine = function(x, y, xradius, yradius, stangle, endangle, thickness, rgb, alpha) {
this.lineStyle(
thickness == null ? this.m_thickness : thickness,
rgb == null ? this.m_rgb : rgb,
alpha == null ? this.m_alpha : alpha
);
this.endFill();
this.sector(x, y, xradius, yradius, stangle, endangle);
};
//-------------------------------------------------------------------
// 绘制扇形色块,无边框
// x, y: 中心坐标
// xradius: x轴半径
// yradius: y轴半径(未指定或者值为null或undefined则取xradius的值)
// stangle, endangle: 起止角度
// rgb, alpha: 填充颜色(未指定或者值为null或undefined则使用默认值)
MovieClip.prototype.sectorFill = function(x, y, xradius, yradius, stangle, endangle, rgb, alpha) {
this.lineStyle();
this.beginFill(
rgb == null ? 0 : rgb,
alpha == null ? 100 : alpha
);
this.sector(x, y, xradius, yradius, stangle, endangle);
this.endFill();
};
//---------------------------------------------------------------
◎ 数学图象绘图函数 ◎
//-------------------------------------------------------------------
// 绘制抛物线
// x, y: 顶点坐标
// k: 比例系数
// x1, x2: 抛物线起止x坐标
MovieClip.prototype.parabola = function(x, y, k, x1, x2) {
this.moveTo(x1, y + k * (x1 - x) * (x1 - x));
this.curveTo((x1 + x2) / 2, y + k * (x1 - x) * (x2 - x), x2, y + k * (x2 - x) * (x2 - x));
};
//-------------------------------------------------------------------
// 绘制波形线(正弦曲线)
// x, y: 中心点坐标
// kx, ky: x轴及y轴的缩放比例
// x1, x2: 波形线起止x坐标
MovieClip.prototype.wave = function(x, y, kx, ky, x1, x2) {
if (x1 == x2 || kx == 0) return;
var pi_6 = Math.PI / 6;
var i = 1;
var beginx = (x1 - x) / kx;
var endx = (x2 - x) / kx;
var curx = beginx;
var nextx = beginx < endx ? (Math.floor(curx / pi_6) + 1) * pi_6 :
(Math.ceil(curx / pi_6) - 1) * pi_6;
var coscx = Math.cos(curx);
var cccsc = coscx * curx - Math.sin(curx);
var cosnx, cnnsn, controlx, controly, anchorx, anchory;
this.moveTo(x1, y + ky * Math.sin(curx));
while (true) {
if (beginx < endx && nextx > endx || beginx > endx && nextx < endx) nextx = endx;
cosnx = Math.cos(nextx);
cnnsn = cosnx * nextx - Math.sin(nextx);
controlx = x + kx * (cccsc - cnnsn) / (coscx - cosnx);
controly = y + ky * (cccsc * cosnx - cnnsn * coscx) / (coscx - cosnx);
anchorx = x + kx * nextx;
anchory = y + ky * Math.sin(nextx);
this.curveTo(controlx, controly, anchorx, anchory);
if (Math.abs(nextx - endx) < 1e-10) break;
beginx < endx ? i++ : i--;
curx = nextx;
coscx = cosnx;
cccsc = cnnsn;
nextx = beginx + i * pi_6;
}
};
//-------------------------------------------------------------------
回复Comments
作者:
{commentrecontent}