实现超酷Flash光带效果

开发 前端
今天看到一个网站上超酷的光带效果,分享给大家看看~ 查看效果:超酷光带效果 (flash载入需要等待一点时间)

查看效果:超酷光带效果 (flash载入需要等待一点时间)

部分代码:

  1. /**  
  2.  
  3.  * Copyright david1 ( http://wonderfl.net/user/david1 )  
  4.  * MIT License ( http://www.opensource.org/licenses/mit-license.php )  
  5.  * Downloaded from: http://wonderfl.net/c/gjQv  
  6.  */  
  7.  
  8. // forked from one_truth's forked from: 光るリボン(Ribbon Light)  
  9. // forked from mousepancyo's 光るリボン(Ribbon Light)  
  10. // forked from nutsu's SketchSample6  
  11. package  {  
  12.     import flash.display.Sprite;  
  13.     import flash.display.BitmapData;  
  14.     import flash.display.Bitmap;  
  15.     import flash.events.Event;  
  16.     import flash.filters.BlurFilter;  
  17.     import flash.geom.Point;  
  18.     import flash.geom.ColorTransform;  
  19.       
  20.     [SWF(width=465,height=465,backgroundColor=0x000000,frameRate=60)]  
  21.       
  22.     public class Main extends Sprite{  
  23.           
  24.         private const WIDTH:Number  = 465;  
  25.         private const HEIGHT:Number = 465;  
  26.           
  27.         private var _sketch:CurveSketch;  
  28.         private var _bmd:BitmapData;  
  29.         private var _bm:Bitmap;  
  30.         private var _container:Sprite = new Sprite();  
  31.  
  32.         public function Main() {  
  33.             graphics.beginFill(0)  
  34.             graphics.drawRect(0, 0, WIDTH, HEIGHT)  
  35.             graphics.endFill()  
  36.             addChild(_container);  
  37.             //  
  38.             _sketch = new CurveSketch();  
  39.             _bmd = new BitmapData(WIDTH, HEIGHT, true, 0);  
  40.             _container.addChild(_sketch);  
  41.             _container.addChild(_bm = new Bitmap(_bmd) as Bitmap);  
  42.             _bm.blendMode = "add";  
  43.             //  
  44.             addEventListener(Event.ENTER_FRAME, update);  
  45.         }  
  46.           
  47.         private function update(e:Event):void{  
  48.             _bmd.draw(_sketch, null, null, "add");  
  49.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(), new BlurFilter(8, 8, 4));  
  50.         }  
  51.     }  
  52. }  
  53.  
  54.  
  55.  
  56. //package {  
  57.     import frocessing.display.F5MovieClip2D;  
  58.     import frocessing.geom.FGradientMatrix;  
  59.     import frocessing.color.ColorHSV  
  60.       
  61.     class CurveSketch extends F5MovieClip2D  
  62.     {  
  63.           
  64.         //加速度運動の変数  
  65.         //位置  
  66.         private var xx:Number;  
  67.         private var yy:Number;  
  68.         //速度  
  69.         private var vx:Number;  
  70.         private var vy:Number;  
  71.         //加速度の係数  
  72.         private var ac:Number;  
  73.         //速度の減衰係数  
  74.         private var de:Number;  
  75.           
  76.         //描画座標  
  77.         private var px0:Array;  
  78.         private var py0:Array;  
  79.         private var px1:Array;  
  80.         private var py1:Array;  
  81.           
  82.         private var t:Number = 0 
  83.           
  84.         //描画グループ  
  85.         private var shapes:Array;  
  86.           
  87.         public function CurveSketch()   
  88.         {  
  89.               
  90.             //初期化  
  91.             vx = vy = 0.0;  
  92.             xx = mouseX;  
  93.             yy = mouseY;  
  94.             ac = 0.06;  
  95.             de = 0.9;  
  96.             px0 = [xx, xx, xx, xx];  
  97.             py0 = [yy, yy, yy, yy];  
  98.             px1 = [xx, xx, xx, xx];  
  99.             py1 = [yy, yy, yy, yy];  
  100.                           
  101.             shapes = [];  
  102.               
  103.             //線と塗りの色指定  
  104.             noStroke();              
  105.         }  
  106.           
  107.         public function draw():void  
  108.         {  
  109.             //加速度運動  
  110.             xx += vx += ( mouseX - xx ) * ac;  
  111.             yy += vy += ( mouseY - yy ) * ac;  
  112.               
  113.             var len:Number = mag( vx, vy );  
  114.               
  115.             //新しい描画座標  
  116.             var x0:Number = xx + 1 + len * 0.1;  
  117.             var y0:Number = yy - 1 - len * 0.1;  
  118.             var x1:Number = xx - 1 - len * 0.1;  
  119.             var y1:Number = yy + 1 + len * 0.1;  
  120.               
  121.             //描画座標  
  122.             px0.shift(); px0.push( x0 );  
  123.             py0.shift(); py0.push( y0 );  
  124.             px1.shift(); px1.push( x1 );  
  125.             py1.shift(); py1.push( y1 );  
  126.               
  127.             var _px0:Array = [px0[0], px0[1], px0[2], px0[3]];  
  128.             var _py0:Array = [py0[0], py0[1], py0[2], py0[3]];  
  129.             var _px1:Array = [px1[0], px1[1], px1[2], px1[3]];  
  130.             var _py1:Array = [py1[0], py1[1], py1[2], py1[3]];  
  131.               
  132.             shapes.push( { px0:_px0, py0:_py0, px1:_px1, py1:_py1, mtx:null} );  
  133.             if (shapes.length >= 50) shapes.shift();  
  134.               
  135.             var shapesshapesLength:int = shapes.length;  
  136.             for (var i:int = shapesLength-1; i >= 0; i--)   
  137.             {  
  138.                 var sh:Object = shapes[i];  
  139.                   
  140.                 var color:ColorHSV = new ColorHSV(t, 0.8, 1, 0.1)  
  141.                 t += 0.05;  
  142.                   
  143.                 beginFill(int(color), 0.2)  
  144.                 beginShape();  
  145.                 curveVertex( sh.px0[0], sh.py0[0] );  
  146.                 curveVertex( sh.px0[1], sh.py0[1] );  
  147.                 curveVertex( sh.px0[2], sh.py0[2] );  
  148.                 curveVertex( sh.px0[3], sh.py0[3] );  
  149.                 vertex( sh.px1[2], sh.py1[2] );  
  150.                 curveVertex( sh.px1[3], sh.py1[3] );  
  151.                 curveVertex( sh.px1[2], sh.py1[2] );  
  152.                 curveVertex( sh.px1[1], sh.py1[1] );  
  153.                 curveVertex( sh.px1[0], sh.py1[0] );  
  154.                 endShape();  
  155.             }  
  156.               
  157.               
  158.             //減衰処理  
  159.             vx *= de;  
  160.             vy *= de;  
  161.         }  
  162.  
  163.     }  
  164. //} 

【编辑推荐】

  1. 技巧:可退回到Flash的HTML 5视频方案
  2. Flash真的适合做网站应用吗?
  3. jQuery实战之仿Flash跳动的按钮效果
  4. 发挥你的想象 HTML 5可以干什么
  5. Dojo1.6新特性:HTML 5进行时
责任编辑:陈贻新 来源: molehill
相关推荐

2011-03-02 13:15:26

HTML 5jQuery

2022-06-27 08:01:55

动画CSS前端

2012-01-10 14:59:42

jQuery

2009-04-03 08:33:59

Symbian诺基亚Photo Brows

2011-05-10 15:05:04

Webhover

2010-09-02 09:26:04

FlashAndroid

2011-06-13 10:44:44

Qt Flash

2012-05-29 10:36:43

jQuery

2011-04-15 09:29:20

jQueryFlash

2011-06-14 18:37:50

Flash

2011-06-13 09:04:39

QT Flash 交互

2011-07-08 10:15:15

IPhone 动画

2017-03-13 13:32:39

LinuxVim技巧

2010-06-11 16:46:06

openSUSE Fl

2015-07-23 15:15:06

动态弹出

2009-10-30 14:45:42

Flash控制VB.N

2022-12-12 11:11:05

2012-04-10 10:31:07

2013-06-27 14:57:58

Eclipse超酷插件移动开发

2012-06-13 14:19:27

点赞
收藏

51CTO技术栈公众号