flash sin~
// x0 y0 起点坐标 | k 垂直幅度 | disX 水平幅度 disY 周期 | i 速度变量
var x0:Number = 100, y0:Number = 200, k:Number = 100, disX:Number = 2, disY:Number = 1, i:Number = 0;
//=== 画水平线背景(完全可以不画),画的目的在于背景有个坐标参考 ====================
drawViewX();
function drawViewX() {
// wh 单元格长与宽
var wh:Number = 10;
this.createEmptyMovieClip("lineX", this.getNextHighestDepth());
onEnterFrame = function () { // 来点动态效果
with (lineX) {
lineStyle(1, 0xCCCCCC, 100);
moveTo(0, wh);
lineTo(Stage.width, wh);
}
if (lineX._width>=Stage.width) {
wh += 10;
}
if (wh>=Stage.height) {
delete onEnterFrame;
drawViewY(); //画完水平线背景后,再执行画垂直线背景函数
}
updateAfterEvent();
};
}
//=== 画垂线背景(完全可以不画),画的目的在于背景有个坐标参考 ========
function drawViewY() {
// wh 单元格长与宽
var wh:Number = 10;
this.createEmptyMovieClip("lineY", this.getNextHighestDepth());
onEnterFrame = function () { // 来点动态效果
with (lineY) {
lineStyle(1, 0xCCCCCC, 100);
moveTo(wh, 0);
lineTo(wh, Stage.height);
}
if (lineX._width>=Stage.height) {
wh += 10;
}
if (wh>=Stage.width) {
delete onEnterFrame;
drawX();//画完垂直线背景后,再执行画垂x坐标线函数
}
updateAfterEvent();
};
}
//======== 画sin主函数 =================================
function drawSin() {
this.createEmptyMovieClip("line", this.getNextHighestDepth());
with (line) {
lineStyle(2, 0x000000, 100);
moveTo(x0, y0);
}
var xx:Number = 0;
var yy:Number = 0;
line.onEnterFrame = function() {
xx = x0+i/disX;
yy = y0-Math.sin(i*Math.PI/180)*k;
ball._x = xx;
ball._y = yy;
line.lineTo(ball._x, ball._y);
i += 5;
if (i>disY*360) {
delete this.onEnterFrame;
ball._visible = false;
//
//==========
_root.createTextField("sxl001", _root.getNextHighestDepth(), 430, 380, 125, 20);
sxl001.background = true;
sxl001.backgroundColor = 0xFFCCFF;
sxl001.autoSize = "left";
sxl001.text = "===== sxl001 =====";
_root.createTextField("txt", _root.getNextHighestDepth(), 200, 360, 150, 20);
txt.text = "方向键控制曲线的移动";
//
Key.addListener(myListener);
}
};
}
//== 画坐标系的X轴 ======================================
var v0:Number = 0;
function drawX() {
this.createEmptyMovieClip("xline", this.getNextHighestDepth());
with (xline) {
lineStyle(1, 0x000000, 100);
moveTo(20, y0);
}
xline.onEnterFrame = function() {
v0 += 20;
this.lineTo(v0, y0);
if (this._width>=Stage.width-40) {
delete this.onEnterFrame;
v0 = 0;
//== 画完x坐标线后,再执行画垂y坐标线函数
drawY();
}
};
}
//== 画坐标系的Y轴 ======================================
function drawY() {
this.createEmptyMovieClip("yline", this.getNextHighestDepth());
with (yline) {
lineStyle(1, 0x000000, 100);
moveTo(x0, 20);
}
yline.onEnterFrame = function() {
v0 += 20;
this.lineTo(x0, 20+v0);
if (this._height>=Stage.height-40) {
delete this.onEnterFrame;
//显示红色小球
ballShow();
}
};
}
//== 红色小球 ==========================================
function ballShow() {
this.createEmptyMovieClip("ball", this.getNextHighestDepth());
with (ball) {
lineStyle(6, 0xFF0000, 100);
moveTo(0, 0);
lineTo(0.5, 0);
//= 画sin曲线
drawSin();
}
}
//== 方向键控制曲线移动 ===================================
var myListener:Object = new Object();
myListener.onKeyDown = function() {
switch (Key.getCode()) {
case Key.LEFT :
line._x -= 5;//sin左移
break;
case Key.RIGHT :
line._x += 5;//sin右移
break;
case Key.UP :
line._y -= 5;//sin上移
break;
case Key.DOWN :
line._y += 5;//sin下移
break;
}
};
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步