| 首页 | 新闻 | 网页 | 设计 | 色彩 | 原创 | 视觉 | 素材 | 动漫 | 酷站 | 策划 | 文案 | 访谈 | 运营 | 编程 | 数据库 | 服务器 | 下载 | 图库 | 
您的位置: 幽幽天空 > 网页 > 网页制作 > Flash教程 > ActionScript教程 > 文章正文 用户登录
一个站点要运营成
迅雷联盟:个人站
迅雷联盟,个人站
一个失败者的网站
从名片看到一个小
一个大学生的网页
网络新生领域扫描
一个站长建站经历
一个网络创业者的
广捷居 一个永不言

一个用纯AS写的正态曲线画法           

一个用纯AS写的正态曲线画法

作者:佚名 来源:闪吧 作者: lidax999 更新:2007-1-13 20:49:43 错误报告 我要投稿

点击浏览该文件
点击浏览该文件
我的这段AS写了不少有用的函数,如画按钮函数,画坐标轴函数,画框架函数.这些函数都有很强的移植性,以后都可以直接拿来用;
//================按钮和坐标轴上的文字=====================//
mytxt = ["开始", "暂停", "清除", "全屏", "退出", "继续"];
myNum = ["-30", "-20", "-10", "0", "10", "20", "30", "X", "Y"];
//=====画按钮(type不为0时按钮为凸起状态type=0时按钮为凹下状态)=====//
CommandButton = function (mc, t, type) {
c = 0xffffff;//按钮左和上边框颜色
c1 = 0x000000;//按钮右和下边框颜色
mc.createTextField("txt", 700, 12, 1, 27, 18);
if (!type) {
c = 0x000000;
c1 = 0xffffff; //type=0时左和上与右和下边框颜色交换;
mc.createTextField("txt", 700, 13, 2, 27, 18);//按下时文本框向左下移,使字有凹下感觉
}
with (mc) {
moveTo(0, 20);
lineStyle(1, c, 100);
beginFill(0xD1DEE9);
lineTo(0, 0);
lineTo(50, 0);
lineStyle(1, c1, 100);
lineTo(50, 20);
lineTo(0, 20);
endFill();
txt.text = t;
}
};
//===========画框架=============//
display = function (mc, x, y, w, h, txt, corl) {
with (mc) {
moveTo(x, y);
lineStyle(0.5, 0x00000, 100);
beginFill(corl, 40);
lineTo(x+w, y);
lineTo(x+w, y+h);
lineTo(x, y+h);
lineTo(x, y);
endFill();
createTextField("name", 300, x+2, y-17, 0, 0);
name.autoSize = "left";
name.selectable = false;
name.border = true;
name.background = true;
name.backgroundColor = 0x798DA6;
name.textColor = 0xffffff;
name.text = txt;
}
};
//========画坐标轴上刻度及数字==============//
dial = function (mc, len, corl, txt, type) {
with (mc) {
moveTo(0, 0);
lineStyle(0.25, corl, 100);
if (type) {//type不为0时刻度坚着画,为0时刻度横着画;
lineTo(0, len);
createTextField("num", 600, -7, len+1, 0, 0);
} else {
lineTo(len, 0);
createTextField("num", 600, len+1, -2, 0, 0);
}
num.autoSize = true;
num.selectable = false;
num.text = txt;
}
};
//========画坐标轴============//
coordinate = function (x, y) {
_root.moveTo(x-215, y);
_root.lineStyle(0.25, 0x00000, 100);
_root.lineTo(x+215, y);
_root.lineTo(x+185, y+5);
_root.moveTo(x+215, y);
_root.lineTo(x+185, y-5);
_root.moveTo(x, y+20);
_root.lineTo(x, y-220);
_root.lineTo(x-5, y-190);
_root.moveTo(x, y-220);
_root.lineTo(x+5, y-190);
for (i=0; i<19; i++) {
_root.createEmptyMovieClip("l"+i, 510+i);
if (i<13) {
!(i%2) ? dial(_root["l"+i], 5, 0xff0000, myNum[i/2], 1) : dial(_root["l"+i], 3, 0x000000, "", 1);//刻度隔一个为红色,且有数字
_root["l"+i]._x = x-198+33*i;
_root["l"+i]._y = y;
}
if (i>12) {//同上
!(i%2) ? dial(_root["l"+i], 5, 0xff0000, myNum[i/2-3], 0) : dial(_root["l"+i], 3, 0x000000, "", 0);
_root["l"+i]._x = x;
_root["l"+i]._y = y-33*(i-12);
}
}
_root.createTextField("Xt", 250, x+220, y-3, 18, 18);
_root.createTextField("Yt", 260, x, y-230, 18, 18);
Xt.text = myNum[7];
Xt.selectable = false;
Yt.text = myNum[8];
Yt.selectable = false;
};
inputBoxs = function (x, y) {
var alpha = ["u =", "0", "o =", "1"];
for (i=0; i<4; i++) {
_root.createTextField("v"+i, 800+i, x+i*35, y, 30, 16);
if (i%2) {
_root["v"+i].type = "input";
_root["v"+i].border = true;
_root["v"+i].text = alpha[i];
} else {
_root["v"+i].autoSize = "right";
_root["v"+i].selectable = false;
_root["v"+i].text = alpha[i];
}
}
};
//======写标题========//
headline = function (x, y, txt, dx) {
_root.createTextField("title", 900, x, y, 0, 0);
title.autoSize = true;
title.selectable = false;
title.text = txt;
mytxf = new TextFormat();//创建一个文本格式对象;
mytxf.size = dx;//太小
mytxf.color = 0xff0000;//颜色
mytxf.underline = true;//下划线
title.setTextFormat(mytxf);
};
//=====开始画线函数====//
startDraw = function () {
m = Number(v1.text);
n = Number(v3.text);//把v1,v3文本框中的值给m,n;
x = -200;
_root.createEmptyMovieClip("xian", 300);
xian.moveTo(-200, 100);
xian._x = 275;
xian._y = 193;
_root.onEnterFrame = function() {
a = -(100/(Math.sqrt(2*Math.PI)*25*n))*Math.exp((-(Math.pow((x-100*m), 2)))/ (2*Math.pow(25*n, 2)));//这个为正态曲线公式,根椐这个公式来画线;
with (xian) {
lineStyle(2, 0xE001E0, 100);
lineTo(x, 50*a+100);//画线
if (x<=200) {//画线范围
x += 3;//3为画线速度,建议设小一点,fps设大一点,这样使画出的线更平滑;
}
}
};
_root.btn1.enabled = 1;//暂停按钮可用
_root.btn5.enabled = 1;//继续按钮可用
};
//========继续画线========//
continueDraw = function () {
xian.moveTo(x-3, 50*a+100);//x,a继承上面函数的值,从当前位置画
_root.onEnterFrame = function() {
a = -(100/(Math.sqrt(2*Math.PI)*25*n))*Math.exp((-(Math.pow((x-100*m), 2)))/ (2*Math.pow(25*n, 2)));
with (xian) {
lineStyle(2, 0xE001E0, 100);
lineTo(x, 50*a+100);
if (x<=200) {
x += 3;//同上
}
}
};
};
//========暂停和清除函数==========//
pause_clear = function (k) {//不为0时为暂停,为0时为清除;
_root.onEnterFrame = function() {
x += 0;//x值不增加
};
if (k) {
xian.clear();//清除xian
_root.btn1.enabled = 0;
_root.btn5.enabled = 0;
}
};
_root.onLoad = function() {
headline(230, 20, "正态曲线", 20);
for (i=0; i<3; i++) {
_root.createEmptyMovieClip("frame"+i, 400+i);
}
display(_root.frame0, 40, 55, 470, 270, "显示", 0xE6E1CC);
display(_root.frame1, 40, 350, 160, 40, "变量", 0xDCE6ED);
display(_root.frame2, 220, 350, 290, 40, "操作", 0xDCE6ED);
coordinate(275, 295);
inputBoxs(50, 365);
_root.attachMovie("formula", "formula", 500);
formula.useHandCursor = false;//鼠标不变手形
formula._x = 42;
formula._y = 57;
for (i=0; i<6; i++) {
_root.createEmptyMovieClip("btn"+i, 700+i);
CommandButton(_root["btn"+i], mytxt[i], 1);//用循环来画按钮;
_root["btn"+i]._x = 230+55*i;
_root["btn"+i]._y = 360;
_root.btn5._x = 230+55*1;
_root.btn5._y = 360;
_root.btn5._visible = 0;//设置按钮位置,并把暂停和继续按钮放在一起;且开始时继续不可见
}
_root.btn1.enabled = 0;//开始时暂停不可用
};
_root.onEnterFrame = function() {//以下为按上每个按钮的动作;
_root.btn0.onPress = function() {
CommandButton(_root.btn0, mytxt[0], 0);//按鼠标时按钮凹下;
_root.btn1._visible = 1;//暂停按钮可见
_root.btn5._visible = 0;继续按钮不可见
startDraw();//调用开始画线函数;
};
_root.btn0.onRelease = function() {
CommandButton(_root.btn0, mytxt[0], 1);//松开鼠标时按钮凸起;
};
_root.btn1.onPress = function() {
CommandButton(_root.btn1, mytxt[1], 0);
pause_clear(0);//调用暂停
};
_root.btn1.onRelease = function() {
CommandButton(_root.btn1, mytxt[1], 1);
_root.btn1._visible = 0;
_root.btn5._visible = 1;//按了暂停按钮时,变成继续按钮;
};
_root.btn2.onPress = function() {
CommandButton(_root.btn2, mytxt[2], 0);
pause_clear(1);//调用清除函数;
};
_root.btn2.onRelease = function() {
CommandButton(_root.btn2, mytxt[2], 1);
};
_root.btn3.onPress = function() {
CommandButton(_root.btn3, mytxt[3], 0);
fscommand("fullscreen", true);//全屏
};
_root.btn3.onRelease = function() {
CommandButton(_root.btn3, mytxt[3], 1);
};
_root.btn4.onPress = function() {
CommandButton(_root.btn4, mytxt[4], 0);
fscommand("quit");//退出
};
_root.btn4.onRelease = function() {
CommandButton(_root.btn4, mytxt[4], 1);
};
_root.btn5.onPress = function() {
CommandButton(_root.btn5, mytxt[5], 0);
continueDraw();//调用继续画线函数;
};
_root.btn5.onRelease = function() {
CommandButton(_root.btn5, mytxt[5], 1);
_root.btn5._visible = 0;
_root.btn1._visible = 1;//按继续按钮时,变成暂停按钮;
};
_root.formula.onRollOver = function() {
formula._xscale = formula._yscale=330;//放大尺寸;
};
_root.formula.onRollOut = function() {
formula._xscale = formula._yscale=100;//尺寸还原
};
};
文章录入:skyuu    责任编辑:skyuu 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    发表评论:
    姓名:  评 分: 1分 2分 3分 4分 5分
     
  • 严禁发表危害国家安全、政治、黄色淫秽等内容的评论。
  • 用户需对自己在使用幽幽天空服务过程中的行为承担法律责任。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表机友个人观点,与本网站立场无关。