站内搜索:     
站点首页破釜学院网页制作Flash特殊效果 → 仿屏保的折线 曲线运动效果
正在加载相关信息.....
Web 站内搜索
仿屏保的折线 曲线运动效果
】【打印】【加入收藏】【关闭收藏到新浪ViVi】【收藏到365KEY】 浏览字号:
日期:2006-07-17 人气: 出处:闪吧 作者: 独自行走
 新建一MC元件,在MC的时间轴上写入下面的代码:
this._x = this._y = 0; 
total = 5; 
myColor = random(0xffffff); 
speed = 5; 
for (i = 0; i < total; i++) { 
 createEmptyMovieClip("mc" + i, i); 
 this["mc" + i]._y = random(Stage.height); 
 this["mc" + i]._x = random(Stage.width); 
 this["mc" + i].xsp = random(speed) + 5; 
 this["mc" + i].ysp = random(speed) + 5; 

onEnterFrame = function () { 
 r = Math.floor(random(5)); 
 g = Math.floor(random(10)); 
 b = Math.floor(random(20)); 
 //myColor += r << 32 + g << 16 + b; 
 //myColor &= 0xffffff; 
 for (i = 0; i < total; i++) { 
  with (this["mc" + i]) { 
   _x = _x + xsp; 
   _y = _y + ysp; 
   if (_x > Stage.width || _x < 0) { 
    xsp = -xsp; 
    myColor += r << 32 + g << 16 + b; 
    myColor &= 0xffffff; 
   } 
   if (_y > Stage.height || _y < 0) { 
    ysp = -ysp; 
    myColor += r << 32 + g << 16 + b; 
    myColor &= 0xffffff; 
   } 
  } 
 } 
 createEmptyMovieClip("xian", 100); 
 with (xian) { 
  lineStyle(2, myColor, 100); 
  start_pt_x = (mc0._x + this["mc" + (total - 1)]._x) / 2; 
  start_pt_y = (mc0._y + this["mc" + (total - 1)]._y) / 2; 
  moveTo(start_pt_x, start_pt_y); 
  for (i = 0; i < total - 1; i++) { 
   ctl_pt_x = this["mc" + i]._x; 
   ctl_pt_y = this["mc" + i]._y; 
   end_pt_x = (this["mc" + (i + 1)]._x + this["mc" + i]._x) / 2; 
   end_pt_y = (this["mc" + (i + 1)]._y + this["mc" + i]._y) / 2; 
   curveTo(ctl_pt_x, ctl_pt_y, end_pt_x, end_pt_y); 
  } 
  ctl_pt_x = this["mc" + (total - 1)]._x; 
  ctl_pt_y = this["mc" + (total - 1)]._y; 
  end_pt_x = (this["mc0"]._x + this["mc" + (total - 1)]._x) / 2; 
  end_pt_y = (this["mc0"]._y + this["mc" + (total - 1)]._y) / 2; 
  curveTo(ctl_pt_x, ctl_pt_y, end_pt_x, end_pt_y); 
 } 
}; 
在主场景中拖入三个该元件,效果如下:
/Upload/2006-07/3_131.swf
绘制折线的代码如下:
this._x = this._y = 0; 
total = 6; 
myColor = random(0xffffff); 
speed = 5; 
for (i = 0; i < total; i++) { 
 createEmptyMovieClip("mc" + i, i); 
 this["mc" + i]._y = random(Stage.height); 
 this["mc" + i]._x = random(Stage.width); 
 this["mc" + i].xsp = random(speed) + 5; 
 this["mc" + i].ysp = random(speed) + 5; 

onEnterFrame = function () { 
 r = Math.floor(random(5)); 
 g = Math.floor(random(10)); 
 b = Math.floor(random(20)); 
 //myColor += r << 32 + g << 16 + b; 
 //myColor &= 0xffffff; 
 for (i = 0; i < total; i++) { 
  with (this["mc" + i]) { 
   _x = _x + xsp; 
   _y = _y + ysp; 
   if (_x > Stage.width || _x < 0) { 
    xsp = -xsp; 
    myColor += r << 32 + g << 16 + b; 
    myColor &= 0xffffff; 
   } 
   if (_y > Stage.height || _y < 0) { 
    ysp = -ysp; 
    myColor += r << 32 + g << 16 + b; 
    myColor &= 0xffffff; 
   } 
  } 
 } 
 createEmptyMovieClip("xian", 100); 
 with (xian) { 
  lineStyle(2, myColor, 100); 
  moveTo(mc0._x, mc0._y); 
  for (i = 0; i < total -1 ; i++) { 
   lineTo(this["mc" + i]._x, this["mc" + i]._y); 
  } 
  lineTo(mc0._x, mc0._y); 
 } 
}; 

效果如下:

upload/2006-07/3_621.swf

欢迎访问我的博客 http://dzxz.blog.5d.cn

 


>>>> 进入论坛交流 <<<<