*两点间画直线
*画螺旋线
*画正方形、圆、椭圆
*抛物线
*正弦、余弦线
使用方法:加到帧中就可
// 画直线
// / x1, y1: 起点坐标
// x2, y2: 终点坐标
// k是层次
Movieclip.prototype.drawline = function(x1, y1, x2, y2, k) {
this.linestyle(1);
this.moveTo(x1, y1);
this.lineTo(x2, y2);
};
// 从(0,0)到(100,100)画一条线
_root.createEmptyMovieClip("mc", 10);
mc.drawline(0, 0, 100, 100);
// 画螺旋线
// w、h为宽和高
// f控制线的长短,用弧度表示
Movieclip.prototype.drawhelix = function(w, h, f) {
for (var i = 0; i<f; i += 0.05) {
this.lineTo(x=Math.sin(i)*i*w, y=Math.cos(i)*i*h);
this.linestyle(1);
}
};
// 以(100,100)为中心画螺旋线
_root.createEmptyMovieClip("luo", 1);
with (luo) {
drawhelix(5, 5, 13);
_x += 100;
_y += 100;
}
// 多功能函数,可画圆,椭圆,正多边形等
// n为边数
Movieclip.prototype.drawmany = function(w, h, n) {
f = 2*Math.PI;
for (var i = 0; i<=f/n*(n+1); i += f/n) {
this.lineTo(x=Math.sin(i)*w, y=Math.cos(i)*h);
this.linestyle(1);
}
};
// 画一正五边形
_root.createEmptyMovieClip("duobian", 2);
with (duobian) {
drawmany(50, 50, 5);
_x += 250;
_y += 100;
// 5为多边形的边数,6.3为2pai
}
// 画一椭圆
_root.createEmptyMovieClip("tuo", 3);
with (tuo) {
drawmany(25, 50, 100);
_x += 400;
_y += 100;
}
// 圆
_root.createEmptyMovieClip("yuan", 4);
with (yuan) {
drawmany(50, 50, 100);
_x += 400;
_y += 300;
}
// 抛物线
Movieclip.prototype.drawparabola = function(l, r, k) {
for (var i = -l; i<=r; i += 1) {
this.lineTo(x=i, y=k*i*i);
this.linestyle(1);
}
};
// 调用
_root.createEmptyMovieClip("parabola", 100);
with (parabola) {
drawparabola(50, 50, 0.05);
_x += 200;
_y += 200;
// 顶点坐标
}
// 正弦线,余弦类似
Movieclip.prototype.drawsin = function(n, k) {
for (var i = 0; i<=90*n; i += 1) {
this.lineTo(x=i, y=k*Math.sin(i*Math.PI/180));
this.linestyle(1);
}
};
_root.createEmptyMovieClip("sin", 101);
with (sin) {
drawsin(4, 50);
_x += 200;
_y += 200;
// 顶点坐标
}
Movieclip.prototype.drawwave = function(w, h) {
for (var i = 0; i<=6.3; i += 0.01) {
this.lineTo(x=w/Math.cos(i), y=h*Math.sin(i)/Math.cos(i));
this.linestyle(1);
}
};
_root.createEmptyMovieClip("wave", 105);
with (wave) {
drawwave(100, 100);
_x += 200;
_y += 200;
// 顶点坐标
}