动态网站制作指南
[  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
电脑书籍下载:程序设计书籍 | 数据库教程书籍 | 平面与多媒体书籍 | 网络通讯书籍 | 系统管理书籍 | 网络安全书籍 | 认证考试书籍
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 图形图象 > FLASH教程
图形图象:Photoshop,Fireworks,CorelDraw,Flash,3Dmax,AutoCad,Maya,Director,Authorware,Illustrator,相关软件
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ FLASH教程 ]的信息

本月文章推荐
.Flash AS代码简单实现动态文本包.
.精简Flash文件体积七法.
.Flash绘中秋贺卡:快乐月饼大游行.
.Flash AS代码制作鼠标触发图片缓.
.谈Flash脚本与时间轴动作的执行顺.
.Flash MX 2004 Media组件实现多首.
.创建一个Flash站点的十大技巧.
.Flash Web结构之背景层浅析.
.用Flash AS行代码画一棵漂亮的树.
.方便的Flash文字特效制作工具—S.
.将swf文件转成可自动播放的exe文.
.Adobe Flash 2006发展趋势预测.
.Flash动态解析Web应用程序服务器.
.Flash片头加载loading的基础讨论.
.用Flash MX软件制作遥控小汽车.
.Flash动态缓冲图片导航制作详解.
.三分钟理解Flash中的level层级关.
.Flash绘精致矢量图—逼真土豆.
.网页中插入透明Flash的方法和技巧.
.Flash AS动画实例:风吹云飘草动.

Flash AS动画实例:风吹云飘草动

文章类别:FLASH教程 | 发表日期:2007-10-26 |


  我们可以直接用Flash的ASAS代码生成风吹云飘,风吹着青草左右摇摆的动画。因为AS的运算会拖慢机器,所以这里就不提供效果演示了,给大家截个图。

Flash AS 实现好看的清晰的飘动云和风吹草动画

  制作方法如下。

  首先建立两个空的影片剪辑cloud和grass。

  先建立云的影片剪辑(里面什么都不画)

Flash AS 实现好看清晰的飘动云和风吹草动画

  选择该元件的第一帧,添加如下代码。

//Number of clouds
clouds=6;
//These are just general boundaries.
//To use exact boundaries, create a mask in the parent level of the size desired
//Height of the sky
skyheight=Stage.height;
//Width of the sky
skywidth=Stage.width;
//Max size of a cloud
cloudsize=300;
//Amount of blur applied to the shapes to make them cloud-like
blursize=40;
//Clouds move at a random speed. this is the minimum speed
cloudminspeed=.5;
//Variance in speed from cloud to cloud
cloudspeedvariance=1;
//Create the clouds
for(c=1;c<=clouds;c++){
//create an empty movie clip to hold the cloud
 this.createEmptyMovieClip("cloud"+c,this.getNextHighestDepth());
//generate a cloud. Pass in the instance name of the newly created cloud
 shapecloud("cloud"+c);
//Set the x position to a random position within the boundaries
 eval("cloud"+c)._x=Math.random()*skywidth-eval("cloud"+c)._x/2;
//Set the y position to a random position within the boundaries
 eval("cloud"+c)._y=Math.random()*(skyheight)-eval("cloud"+c)._height;
}
//Run at the start of each frame
onEnterFrame=function(){
//Run for each cloud
 for(c=1;c<=clouds;c++){
//Move the cloud to the left according to its speed
  eval("cloud"+c)._x-=eval("cloud"+c).cloudspeed;
//If the cloud is past the stage to the left, reset it to the right. Create a new shape and color  
  if(eval("cloud"+c)._x+(eval("cloud"+c)._width/2)+cloudsize<0){
//Reset the x position
   eval("cloud"+c)._x=skywidth;
//Reshape and recolor the cloud
   shapecloud("cloud"+c);
  }
 }
}
//This function creates the shape and color of a cloud
function shapecloud(cloudid){
//Clear the current contents of the cloud
 eval(cloudid).clear();
//Set the new shade between 224 and 255. This number is used for the red, green, and blue, to create a grayscale color
 cloudcolor=Math.round(Math.random()*31)+224;
//Use no line
 eval(cloudid).lineStyle(undefined, (cloudcolor+cloudcolor*0x100+cloudcolor*0x10000), 100, false, "none", "none", "none", 1);
//Set the fill color. cloudcolor is used 3 times, for red, green, and blue
 eval(cloudid).beginFill((cloudcolor+cloudcolor*0x100+cloudcolor*0x10000));
//Set a starting coordinate for the cloud 
 eval(cloudid).moveTo(Math.random()*cloudsize,Math.random()*cloudsize);
//Draw an invisible line to another point the combined lines form shapes, which are the clouds.
//They don't look much like clouds until the blur is applied
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
 eval(cloudid).lineTo(Math.random()*cloudsize,Math.random()*cloudsize);
//Apply a blur to the shape
 eval(cloudid).filters = [new flash.filters.BlurFilter(blursize,blursize,2)];
//Set a new cloud speed
 eval(cloudid).cloudspeed=Math.random()*cloudspeedvariance+cloudminspeed; 
}

  同样办法再新建立一个草的影片剪辑

Flash AS 实现好看的清晰的飘动云和风吹草动画

  选择第一帧添加如下代码。

//Height of each blade of grass
grassheight=35;
//Average space in between each blade of grass
grassspacing=5;
//Maximum sway of each blade of grass
maxsway=20;
//Number of blades of grass along the x axis
xplots=30;
//Number of blades of grass along the y axis
yplots=20;
//The wind has an x position and the grass is attracted to the position
windxpos=0;
//Velocity of the wind left and right
windspeed=0;
//Gives the grass a bent effect. The grass bends 1/4 of the way up
grasscontrol=grassheight/4;
//Array containing the info for each blade of grass
grasscoords=[];
//These loops go through the field, planting each blade of grass
for (xpos=0; xpos for (ypos=0; ypos  //x position, y position, sway, and color
  grasscoords.push([xpos*grassspacing+Math.random()*grassspacing,ypos*grassspacing+Math.random()*grassspacing,0,Math.round(Math.random()*128)*65536+Math.round(Math.random()*76+146)*256]);
 }
}
//Run on each frame
onEnterFrame=function(){
//Clear all of the grass so it can be redrawn with different sway
 this.clear();
//Change the speed of the wind
 windspeed=Math.max(-50,Math.min(50,windspeed+Math.random()*40-20));
//Move the position the blades are attracted according to the windxpos
 windxpos+=windspeed;
//If the windxpos moves too far to the left, reverse its speed
 if(windxpos<-100){
  windxpos=-100;
  windspeed*=-1;
 }
//If the windxpos moves too far to the right, reverse its speed
 else if(windxpos>grassspacing*xplots+100){
  windxpos=grassspacing*xplots+100;
  windspeed*=-1;
 }
//handle the redraw for each blade of grass
 for(coord=0;coord//Set the line style. 0 means use hairline width and grasscoords[coord][3] is the color   
  this.lineStyle(0, grasscoords[coord][3], 100, false, "normal", "none", "none", 1);
//Adjust the sway according to the grass's current sway and the windxpos
  grasscoords[coord][2]=Math.max(-maxsway,Math.min(maxsway,grasscoords[coord][2]+Math.max(-maxsway,Math.min(maxsway,(windxpos-grasscoords[coord][0])/100))))+(Math.random()*3-1.5);
//Move to the base of the blade of grass
  this.moveTo(grasscoords[coord][0],grasscoords[coord][1]);
//Draw a curved line to the new top of the blade of grass
  this.curveTo(grasscoords[coord][0],grasscoords[coord][1]-grasscontrol,grasscoords[coord][0]+grasscoords[coord][2],grasscoords[coord][1]-grassheight+Math.abs(grasscoords[coord][2]/2));
 }
}

  然后回到主场景中,建立两个图层,下面的为云的图层,上面的为草的图层,这里我绘制了一个放草的框框。

Flash AS 实现好看的清晰的飘动云和风吹草动画

  按Ctrl+L打开库分别把草元件和云元件放到相应的图层。给草命名实例grass。

Flash AS 实现好看的清晰的飘动云和风吹草动画

  最后可以测试影片了!但是好象机器运行速度在减慢啊!祝你好运!


上一篇:Flash AS代码制作鼠标触发图片缓冲放缩 人气:3025
下一篇:用Flash AS行代码画一棵漂亮的树 人气:2777
点击此处浏览全部Flash AS的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-5-11 东旭网络问卷调查系统 v2.4 Beta2
2008-5-11 非零坊『留言本』 v3.3.1
2008-5-11 e新时代企业网站管理系统 v6.0 S
2008-5-11 依悠广告管理系统 v2.1
2008-5-11 Gxjss留言本 v1.0
2008-5-11 深圳公交车线路查询系统 v1.0
2008-5-11 麦群网整站程序 (080510版)
2008-5-11 杰奇小说连载系统 v1.1
2008-5-11 小型FLASH+ASP+XML的新闻发布系统
2008-5-7 Windows XP SP3 官方英文版
2008-5-7 Windows XP SP3 官方香港中文版
2008-5-7 Windows XP SP3 官方繁体中文版
2008-5-7 Windows XP SP3 官方简体中文版
2008-4-30 Multiple Unzip Wizard 1.02
2008-4-30 Multiple Unrar Wizard 1.0.0
2008-4-30 WinZip Install/Try/Uninstall a
2008-4-30 ZIP压缩文件修复器WzipFix 2.0
2008-4-30 Pentazip 6.01 Build 189 For Wi
  发表评论
姓 名: 验证码: [ 全部贴吧 ] [ 浏览评论 ]
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報