Archive for May, 2008

Back to the line drawing I started in this post.

I wanted to get a snake-like line and I had a try with Papervision3D. It made me able to handle the vertices and then delete the end of the lines.

Draw 1 (demo)

I started from an excellent work from Xero (the.fontvir.us) on the Papervision3D mailing list but instead of using a Lorenz attractor, I used the Tweener Bezier property as I did on the 2D versions.

I set a number of vertices, that is giving me the length of the line. Here is the code:

Actionscript:
  1. /*
  2. * Lines3D1
  3. *
  4. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  5. * Actionscript: built for actionscript 3.0
  6. * 05-2008
  7. *
  8. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  9. * @version    1.0
  10. * @usage       
  11. *
  12. */
  13.  
  14. package {
  15.    
  16.     import org.papervision3d.core.geom.renderables.*;
  17.     import org.papervision3d.materials.special.*;
  18.     import org.papervision3d.core.geom.*;
  19.     import org.papervision3d.objects.*;
  20.     import org.papervision3d.cameras.*;
  21.     import caurina.transitions.Tweener;
  22.     import caurina.transitions.properties.CurveModifiers;
  23.     import flash.events.*;
  24.  
  25.     public class Lines3D1 extends BaseP3D {
  26.        
  27.         //------------------------------------
  28.         // private properties
  29.         //------------------------------------
  30.        
  31.         private var sight:DisplayObject3D;
  32.         private var lineMaterial:LineMaterial;
  33.         private var arrLines:Array = [];
  34.         private var _objArray:Array = [];
  35.         private var _linesNum:int = 5;
  36.         private var _maxRadius:int = 200;
  37.         private var _pointNum:uint = 80;
  38.         private var _verticesNum:uint = 50;
  39.         
  40.         //------------------------------------
  41.         // public properties
  42.         //------------------------------------
  43.        
  44.         //------------------------------------
  45.         // constructor
  46.         //------------------------------------
  47.         
  48.         public function Lines3D1() {
  49.             stage.frameRate = 81;
  50.             CurveModifiers.init();
  51.             super(600, 600);
  52.             b.addEventListener(MouseEvent.CLICK, reload);
  53.             addChild(b);
  54.         }
  55.        
  56.         //
  57.         // PRIVATE, PROTECTED
  58.         //________________________________________________________________________________________________
  59.        
  60.         override protected function init2D():void {
  61.             for (var u:int=0; u<_linesNum; u++) {
  62.                 var obj:Object = {};
  63.                 var newPos:Object = getRandomPos();
  64.                 obj['prevX'] = obj['x'] = newPos['x'];
  65.                 obj['prevY'] = obj['y'] = newPos['y'];
  66.                 obj['prevZ'] = obj['z'] = newPos['z'];
  67.                 obj['color'] = Math.random() * 0xFFFFFF;
  68.                 _objArray.push(obj);
  69.                 randomTween(getRandomData(obj));
  70.             }
  71.         }
  72.  
  73.         override protected function init3D():void {
  74.             camera.zoom = 5;
  75.             camera.z = -200;
  76.             sight = new DisplayObject3D();
  77.             camera.target = sight;
  78.             lineMaterial = new LineMaterial(Math.random()* 0xFFFFFF);
  79.             for (var f:int=0; f<_linesNum; f++) {
  80.                 var line:Lines3D = new Lines3D(lineMaterial, "line");
  81.                 arrLines.push(line);
  82.                 scene.addChild(line, "line");
  83.             }
  84.         }
  85.        
  86.         override protected function processFrame():void {
  87.             for (var h:int=0; h<_linesNum; h++) {
  88.                 arrLines[h].addLine(new Line3D(arrLines[h], new LineMaterial(_objArray[h]['color'], 1), 3, new Vertex3D(_objArray[h]['prevX'],_objArray[h]['prevY'],_objArray[h]['prevZ']), new Vertex3D(_objArray[h]['x'],_objArray[h]['y'],_objArray[h]['z'])));
  89.                 _objArray[h]['prevX'] = _objArray[h]['x'];
  90.                 _objArray[h]['prevY'] = _objArray[h]['y'];
  91.                 _objArray[h]['prevZ'] = _objArray[h]['z'];
  92.                 if (arrLines[h].lines.length> _verticesNum) arrLines[h].lines.shift();
  93.                 camera.x += (((mouseX -(stage.stageWidth*.5))*3)-camera.x)*.01;
  94.                 camera.y += (((mouseY-(stage.stageHeight*.5))*3)-camera.y)*.01;
  95.             }
  96.         }
  97.        
  98.         private function randomTween(o:Object):void {
  99.             Tweener.addTween(o, {x:o['x1'], y:o['y1'], z:o['z1'], _bezier:o['bezier'], time :o ['time'], transition:"linear", onComplete:
  100.                 function():void {
  101.                     randomTween(getRandomData(o));
  102.                 }
  103.             });
  104.         }
  105.        
  106.         private function getRandomData(o:Object):Object {
  107.             o['time'] = Math.random() * (_pointNum*.5) + (_pointNum*.25);
  108.             var newPos:Object = getRandomPos();
  109.             o['x1'] = newPos['x'];
  110.             o['y1'] = newPos['y'];
  111.             o['z1'] = newPos['z'];
  112.             o['bezier'] = [];
  113.             for (var i:int=0; i<_pointNum; i++) {
  114.                 var newBezierPos:Object = getRandomPos();
  115.                 o['bezier'].push({
  116.                     x:newBezierPos['x'],
  117.                     y:newBezierPos['y'],
  118.                     z:newBezierPos['z']
  119.                 });
  120.             }
  121.             return o;
  122.         }
  123.        
  124.         private function getRandomPos():Object {
  125.             var angleY:Number = Math.random() * 2 * Math.PI;
  126.             var angleXZ:Number = Math.random() * 2 * Math.PI;
  127.             var o:Object = {};
  128.             o['x'] = Math.cos(angleY) * Math.sin(angleXZ) * _maxRadius;
  129.             o['y'] = Math.sin(angleY) * Math.sin(angleXZ) * _maxRadius;
  130.             o['z'] = Math.cos(angleXZ) * _maxRadius;
  131.             return o;
  132.         }
  133.        
  134.         private function reload(e:MouseEvent = null):void {
  135.             Tweener.removeAllTweens();
  136.             for (var r:int=0; r<_linesNum; r++) {
  137.                 scene.removeChild(arrLines[r]);
  138.             }
  139.             _objArray = [];
  140.             arrLines = [];
  141.             init3D();
  142.             init2D();
  143.         }
  144.        
  145.         //
  146.         // PUBLIC
  147.         //________________________________________________________________________________________________
  148.        
  149.     }
  150.    
  151. }

Draw 2 (demo)

And a bit of fun with the Bitmap layer, the ColorMatrixFilter and the BlurFilter.

Actionscript:
  1. /*
  2. * Lines3D2
  3. *
  4. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  5. * Actionscript: built for actionscript 3.0
  6. * 05-2008
  7. *
  8. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  9. * @version    1.0
  10. * @usage       
  11. *
  12. */
  13.  
  14. package {
  15.    
  16.     import flash.geom.Point;   
  17.     import flash.display.Bitmap;   
  18.     import flash.display.BitmapData;   
  19.     import flash.filters.BlurFilter;   
  20.     import flash.filters.ColorMatrixFilter
  21.     import org.papervision3d.core.geom.renderables.*;
  22.     import org.papervision3d.materials.special.*;
  23.     import org.papervision3d.core.geom.*;
  24.     import org.papervision3d.objects.*;
  25.     import org.papervision3d.cameras.*;
  26.     import caurina.transitions.Tweener;
  27.     import caurina.transitions.properties.CurveModifiers;
  28.     import flash.events.*;
  29.    
  30.     public class Lines3D2 extends BaseP3D {
  31.        
  32.         //------------------------------------
  33.         // private properties
  34.         //------------------------------------
  35.        
  36.         private var sight:DisplayObject3D;
  37.         private var lineMaterial:LineMaterial;
  38.         private var arrLines:Array = [];
  39.         private var _objArray:Array = [];
  40.         private var _linesNum:int = 5;
  41.         private var _maxRadius:int = 200;
  42.         private var _pointNum:uint = 80;
  43.         private var _verticesNum:uint = 30;
  44.         private var _cmf:ColorMatrixFilter;
  45.         private var _bf:BlurFilter;
  46.         private var _bmd:BitmapData;
  47.         private var _bm:Bitmap;
  48.        
  49.         //------------------------------------
  50.         // public properties
  51.         //------------------------------------
  52.        
  53.         //------------------------------------
  54.         // constructor
  55.         //------------------------------------
  56.        
  57.         public function Lines3D2() {
  58.             stage.frameRate = 81;
  59.             CurveModifiers.init();
  60.             super(600, 600);
  61.             b.addEventListener(MouseEvent.CLICK, reload);
  62.             addChild(b);
  63.         }
  64.        
  65.         //
  66.         // PRIVATE, PROTECTED
  67.         //________________________________________________________________________________________________
  68.        
  69.         override protected function init2D():void {
  70.             _cmf = new ColorMatrixFilter([1.05,0,0,0,0,
  71.                                           0,1.05,0,0,0,
  72.                                           0,0,1.05,0,0,
  73.                                           0,0,0,.54,0]);
  74.             _bf = new BlurFilter(5, 5, 2);
  75.             createCanvas();
  76.             for (var u:int=0; u<_linesNum; u++) {
  77.                 var obj:Object = {};
  78.                 var newPos:Object = getRandomPos();
  79.                 obj['prevX'] = obj['x'] = newPos['x'];
  80.                 obj['prevY'] = obj['y'] = newPos['y'];
  81.                 obj['prevZ'] = obj['z'] = newPos['z'];
  82.                 obj['color'] = Math.random() * 0xFFFFFF;
  83.                 _objArray.push(obj);
  84.                 randomTween(getRandomData(obj));
  85.             }
  86.         }
  87.        
  88.         override protected function init3D():void {
  89.             camera.zoom = 5;
  90.             camera.z = -200;
  91.             sight = new DisplayObject3D();
  92.             camera.target = sight;
  93.             lineMaterial = new LineMaterial(Math.random()* 0xFFFFFF);
  94.             for (var f:int=0; f<_linesNum; f++) {
  95.                 var line:Lines3D = new Lines3D(lineMaterial, "line");
  96.                 arrLines.push(line);
  97.                 scene.addChild(line, "line");
  98.             }
  99.         }
  100.        
  101.         private function createCanvas():void {
  102.             _bmd = new BitmapData(600, 600, true, 0x000000);
  103.             _bm = new Bitmap(_bmd);
  104.             addChild(_bm);
  105.         }
  106.  
  107.         override protected function processFrame():void {
  108.             for (var h:int=0; h<_linesNum; h++) {
  109.                 arrLines[h].addLine(new Line3D(arrLines[h], new LineMaterial(_objArray[h]['color'], 1), 3, new Vertex3D(_objArray[h]['prevX'],_objArray[h]['prevY'],_objArray[h]['prevZ']), new Vertex3D(_objArray[h]['x'],_objArray[h]['y'],_objArray[h]['z'])));
  110.                 _objArray[h]['prevX'] = _objArray[h]['x'];
  111.                 _objArray[h]['prevY'] = _objArray[h]['y'];
  112.                 _objArray[h]['prevZ'] = _objArray[h]['z'];
  113.                 if (arrLines[h].lines.length> _verticesNum) arrLines[h].lines.shift();
  114.                 camera.x += (((mouseX -(stage.stageWidth*.5))*3)-camera.x)*.01;
  115.                 camera.y += (((mouseY-(stage.stageHeight*.5))*3)-camera.y)*.01;
  116.             }
  117.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _cmf);
  118.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _bf);
  119.             _bmd.draw(this);
  120.         }
  121.        
  122.         private function randomTween(o:Object):void {
  123.             Tweener.addTween(o, {x:o['x1'], y:o['y1'], z:o['z1'], _bezier:o['bezier'], time :o ['time'], transition:"linear", onComplete:
  124.                 function():void {
  125.                     randomTween(getRandomData(o));
  126.                 }
  127.             });
  128.         }
  129.        
  130.         private function getRandomData(o:Object):Object {
  131.             o['time'] = Math.random() * (_pointNum*.5) + (_pointNum*.25);
  132.             var newPos:Object = getRandomPos();
  133.             o['x1'] = newPos['x'];
  134.             o['y1'] = newPos['y'];
  135.             o['z1'] = newPos['z'];
  136.             o['bezier'] = [];
  137.             for (var i:int=0; i<_pointNum; i++) {
  138.                 var newBezierPos:Object = getRandomPos();
  139.                 o['bezier'].push({
  140.                     x:newBezierPos['x'],
  141.                     y:newBezierPos['y'],
  142.                     z:newBezierPos['z']
  143.                 });
  144.             }
  145.             return o;
  146.         }
  147.        
  148.         private function getRandomPos():Object {
  149.             var angleY:Number = Math.random() * 2 * Math.PI;
  150.             var angleXZ:Number = Math.random() * 2 * Math.PI;
  151.             var o:Object = {};
  152.             o['x'] = Math.cos(angleY) * Math.sin(angleXZ) * _maxRadius;
  153.             o['y'] = Math.sin(angleY) * Math.sin(angleXZ) * _maxRadius;
  154.             o['z'] = Math.cos(angleXZ) * _maxRadius;
  155.             return o;
  156.         }
  157.        
  158.         private function reload(e:MouseEvent = null):void {
  159.             Tweener.removeAllTweens();
  160.             for (var r:int=0; r<_linesNum; r++) {
  161.                 scene.removeChild(arrLines[r]);
  162.             }
  163.             removeChild(_bm);
  164.             _objArray = [];
  165.             arrLines = [];
  166.             init3D();
  167.             init2D();
  168.         }
  169.        
  170.         //
  171.         // PUBLIC
  172.         //________________________________________________________________________________________________
  173.        
  174.     }
  175.    
  176. }

Get a random point in a sphere

maxRadius = 200
angleY = Math.random() * 2 * Math.PI
angleXZ = Math.random() * 2 * Math.PI
x = Math.cos(angleY) * Math.sin(angleXZ) * maxRadius
y = Math.sin(angleY) * Math.sin(angleXZ) * maxRadius
z = Math.cos(angleXZ) * maxRadius

Get the source here.

Vote in HexoSearch

Comments 3 Comments »

This has nothing to do with flash but I share this quick try as I saw a lot of people looking for a background that fit the browser in html.

I used the ratio out I explained in this previous post, obvously you don't have the flash smoothing.

It is not perfect, I had to remove the scrollbars as a part of the picture is not visible. See the demo and download the source.

I'm far from being a good html/css/javascript developer so If you know already a good version or if you have developed one, please comment.

HTML:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Soundstep | experiments (html/css background fitting the borwser)</title>
  5. html, body {
  6.     overflow: hidden;
  7. }
  8. </style>
  9. <script type="text/javascript" src="browser.js"></script>
  10. function fixedBackground(url) {
  11.     document.body.style.padding = '0';
  12.     document.body.style.margin = '0';
  13.     var overlay = document.createElement('DIV');
  14.     overlay.style.position = 'absolute';
  15.     overlay.style.top = '0';
  16.     overlay.style.left = '0';
  17.     overlay.style.height = '100%';
  18.     overlay.style.width = '100%';
  19.     overlay.innerHTML = document.body.innerHTML;
  20.     document.body.innerHTML = '<img id="bg" width="10" height="10" src="' + url + '" style="left: 0; top: 0; z-index: 0" />';
  21.     document.body.appendChild(overlay);
  22.     backgroundset = true;
  23.     updateBackground();
  24. }
  25.  
  26. function updateBackground() {
  27.     var bSize = getSize();
  28.     var sWidth = bSize.w;
  29.     var sHeight = bSize.h;
  30.     var ratio = 1024 / 768;
  31.     if (sWidth / ratio <sHeight) sWidth = sHeight * ratio;
  32.     else sHeight = sWidth / ratio;
  33.     var __bg = document.getElementById('bg');
  34.     __bg.top = 0;
  35.     __bg.left = 0;
  36.     __bg.width = sWidth;
  37.     __bg.height = sHeight;
  38. }
  39.  
  40. function getSize() {
  41.     var myWidth = 0, myHeight = 0;
  42.     if( typeof( window.innerWidth ) == 'number' ) {
  43.         //Non-IE
  44.         myWidth = window.innerWidth;
  45.         myHeight = window.innerHeight;
  46.     }
  47.     else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) {
  48.         //IE 6+ in 'standards compliant mode'
  49.         myWidth = document.documentElement.clientWidth;
  50.         myHeight = document.documentElement.clientHeight;
  51.     }
  52.     else if (document.body && ( document.body.clientWidth || document.body.clientHeight )) {
  53.         //IE 4 compatible
  54.         myWidth = document.body.clientWidth;
  55.         myHeight = document.body.clientHeight;
  56.     }
  57.     var r = {w:myWidth, h:myHeight};
  58.     return r;
  59. }
  60. </script>
  61. </head>
  62.  
  63. <body onresize="updateBackground()" onload="fixedBackground('bg.jpg')">
  64.  
  65.  
  66.  
  67. </body>
  68. </html>

Vote in HexoSearch

Comments 3 Comments »

Here is an example to show a element like a background, a image in a portfolio or whatever and make it fitting the browser.

In the demo you can choose three modes.

Mode Fit

The picture is fitting the browser regardless the original ratio. The formula is simple:

imagePositionX = 0
imagePositionY = 0
imageWidth = stageWidth
imageHeight = stageHeight

Mode Out (I called it like that because you'll miss a part of the picture)

The picture is fitting the browser as well but we keep the ratio, we'll miss a part of the picture at the right or the bottom in my example.

ratio = initialImageWidth / initialImageHeight
newWidth = stageWidth
newHeight = stageHeight
if (stageWidth / ratio < stageHeight) newWidth = stageHeight * ratio;
else newHeight = stageWidth / ratio;
imagePositionX = 0
imagePositionY = 0
imageWidth = newWidth
imageHeight = newHeight

Mode In

The image is fitting the browser, we also keep the ratio but we show the whole picture, we'll have a gap around depending of the size of the area.

ratio = initialImageWidth / initialImageHeight
newWidth = stageWidth
newHeight = stageHeight
if (stageWidth / ratio > stageHeight) newWidth = stageHeight * ratio
else newHeight = stageWidth / ratio
imageWidth = newWidth
imageHeight = newHeight
imagePositionX = (stageWidth * .5) - (imageWidth * .5)
imagePositionY = (stageHeight * .5) - (imageHeight * .5)

You can see a demo and download the source.


Vote in HexoSearch

Comments 2 Comments »

After having a look at the tutorial from Lee Brimelow, I used it to make some experiments.

I tried to find a way to draw a moving line on a bezier curve, like a snake. I didn't really reached it. If you have some ideas how to get a "snake line", please comment.

I used Tweener to animate.

Draw 1 (demo)

Just a simple drawing, a line on moving canvas. Here is the code:

Actionscript:
  1. /*
  2. * Class
  3. *
  4. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  5. * Actionscript: built for actionscript 3.0 and flash player 9
  6. * Date: 01-2008
  7. *
  8. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  9. * @version    1.0
  10. * @usage       
  11. *
  12. */
  13.  
  14. package {
  15.    
  16.     import flash.display.*;
  17.     import flash.events.*;
  18.     import flash.geom.*;
  19.     import flash.ui.*;
  20.     import caurina.transitions.Tweener;
  21.    
  22.     public class Draw1 extends Sprite {
  23.        
  24.         //------------------------------------
  25.         // private properties
  26.         //------------------------------------
  27.        
  28.         private var _canvas:Sprite;
  29.         private var _obj:Object;
  30.        
  31.        
  32.         //------------------------------------
  33.         // public properties
  34.         //------------------------------------
  35.        
  36.        
  37.        
  38.         //------------------------------------
  39.         // constructor
  40.         //------------------------------------
  41.        
  42.         public function Draw1() {
  43.             stage.scaleMode = StageScaleMode.NO_SCALE;
  44.             stage.frameRate = 81;
  45.             _obj = {};
  46.             _obj.x = stage.stageWidth * .5;
  47.             _obj.y = stage.stageHeight * .5;
  48.             createCanvas();
  49.         }
  50.        
  51.         //
  52.         // PRIVATE
  53.         //________________________________________________________________________________________________
  54.        
  55.         private function createCanvas(width:int = 500, height:int = 400):void {
  56.             _canvas = new Sprite();
  57.             cacheAsBitmap = true;
  58.             _canvas.cacheAsBitmap = true;
  59.             _canvas.graphics.lineStyle(3, Math.random() * 0xFFFFFF, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  60.             _canvas.graphics.moveTo(_obj.x, _obj.y);
  61.             addChild(_canvas);
  62.             _canvas.addEventListener(Event.ENTER_FRAME, loop);
  63.             randomTween(getRandomData());
  64.         }
  65.        
  66.         private function loop(e:Event):void {
  67.             _canvas.x -= 4;
  68.             var p:Point = _canvas.globalToLocal(new Point(_obj.x, _obj.y));
  69.             _canvas.graphics.lineTo(p.x, p.y);
  70.         }
  71.        
  72.         private function randomTween(o:Object):void {
  73.             Tweener.addTween(_obj, {y:o.y, time :o .time, transition:"easeInOutElastic", onComplete:
  74.                 function():void {
  75.                     randomTween(getRandomData());
  76.                 }
  77.             });
  78.         }
  79.        
  80.         private function getRandomData():Object {
  81.             var o:Object = {};
  82.             o.y = Math.round(Math.random() * stage.stageHeight);
  83.             o.time = Math.random() * 3 + 1;
  84.             return o;
  85.         }
  86.        
  87.         // PUBLIC
  88.         //________________________________________________________________________________________________
  89.        
  90.    
  91.     }
  92.  
  93. }

Draw 2 (demo)

The second one I draw 5 lines contained in a circle. I used the bezier property of Tweener to build the curves. So I first draw the curve on a bitmapdata canvas and then use a color matrix filter to fade the line after each drawing.

Actionscript:
  1. /*
  2. * Class
  3. *
  4. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  5. * Actionscript: built for actionscript 3.0 and flash player 9
  6. * Date: 01-2008
  7. *
  8. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  9. * @version    1.0
  10. * @usage       
  11. *
  12. */
  13.  
  14. package {
  15.    
  16.     import flash.display.*;
  17.     import flash.events.*;
  18.     import flash.filters.BlurFilter;
  19.     import flash.filters.ColorMatrixFilter;
  20.     import flash.geom.*;
  21.     import flash.ui.*;
  22.     import caurina.transitions.Tweener;
  23.     import caurina.transitions.properties.CurveModifiers;
  24.    
  25.     public class Draw2 extends Sprite {
  26.        
  27.         //------------------------------------
  28.         // private properties
  29.         //------------------------------------
  30.        
  31.         private var _lineNum:uint = 5;
  32.         private var _pointNum:uint = 5;
  33.         private var _lineArray:Array = [];
  34.         private var _objArray:Object = [];
  35.         private var _maxRadius:Number = 150;
  36.        
  37.         private var _cmf:ColorMatrixFilter;
  38.         private var _bf:BlurFilter;
  39.        
  40.         //------------------------------------
  41.         // public properties
  42.         //------------------------------------
  43.        
  44.         private var _bmd:BitmapData;
  45.        
  46.         //------------------------------------
  47.         // constructor
  48.         //------------------------------------
  49.        
  50.         public function Draw2() {
  51.             stage.scaleMode = StageScaleMode.NO_SCALE;
  52.             stage.frameRate = 41;
  53.             CurveModifiers.init();
  54.             //graphics.beginFill(0x222222);
  55.             //graphics.drawCircle((stage.stageWidth * .5), (stage.stageHeight * .5), _maxRadius);
  56.             _cmf = new ColorMatrixFilter([1,0,0,0,0,
  57.                                           0,1,0,0,0,
  58.                                           0,0,1,0,0,
  59.                                           0,0,0,.5,0]);
  60.             _bf = new BlurFilter(8, 8, 3);
  61.             createCanvas();
  62.             createLines();
  63.         }
  64.        
  65.         //
  66.         // PRIVATE
  67.         //________________________________________________________________________________________________
  68.        
  69.         public function createCanvas():void {
  70.             _bmd = new BitmapData(550, 400, true, 0x000000);
  71.             var bm:Bitmap = new Bitmap(_bmd);
  72.             addChild(bm);
  73.         }
  74.        
  75.         private function createLines():void {
  76.             for (var i:uint = 0; i <_lineNum; i++) {
  77.                 var obj:Object = { };
  78.                 obj.color = Math.random() * 0xFF0000;
  79.                 obj.x = getRandomPos().x;
  80.                 obj.y = getRandomPos().y;
  81.                 _objArray.push(obj);
  82.                 var l:Sprite = new Sprite();
  83.                 //l.filters = [new BlurFilter(2, 2, 3)]
  84.                 l.name = "line" + i;
  85.                 l.graphics.lineStyle(3, Math.random() * obj.color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  86.                 addChild(l);
  87.                 _lineArray.push(l);
  88.                 randomTween(getRandomData(obj, l), l);
  89.             }
  90.             addEventListener(Event.ENTER_FRAME, loop);
  91.         }
  92.        
  93.         private function loop(e:Event):void {
  94.             for (var i = 0; i <_lineNum; i++) {
  95.                 _lineArray[i].graphics.lineTo(_objArray[i].x, _objArray[i].y);
  96.             }
  97.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _cmf);
  98.             //_bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _bf);
  99.             _bmd.draw(this);
  100.         }
  101.        
  102.         private function randomTween(o:Object, line:Sprite):void {
  103.             line.graphics.clear();
  104.             line.graphics.lineStyle(3, o.color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  105.             line.graphics.moveTo(o.x, o.y);
  106.             Tweener.addTween(o, { x:o.x1, y:o.y1, _bezier:o.bezier, time :o .time, transition:"easeInOutQuad", onComplete:
  107.                 function():void {
  108.                     randomTween(getRandomData(o, line), line);
  109.                 }
  110.             });
  111.         }
  112.        
  113.         private function getRandomData(obj:Object, line:Sprite):Object {
  114.             obj.time = Math.random() * 2 + .8;
  115.             obj.x1 = getRandomPos().x;
  116.             obj.y1 = getRandomPos().y;
  117.             obj.bezier = [];
  118.             for (var i = 0; i <_pointNum; i++) {
  119.                 obj.bezier.push({
  120.                     x:getRandomPos().x,
  121.                     y:getRandomPos().y
  122.                 });
  123.             }
  124.             return obj;
  125.         }
  126.        
  127.         private function getRandomPos():Object {
  128.             var o:Object = {}
  129.             o.x = Math.cos(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageWidth * .5);
  130.             o.y = Math.sin(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageHeight * .5);
  131.             return o;
  132.         }
  133.        
  134.         // PUBLIC
  135.         //________________________________________________________________________________________________
  136.        
  137.    
  138.     }
  139.  
  140. }

Draw 3 (demo)

In this one, the technic is slightly different. I now update the drawing in the frame loop and use the color matrix filter to leave a trail.

Actionscript:
  1. /*
  2. * Class
  3. *
  4. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  5. * Actionscript: built for actionscript 3.0 and flash player 9
  6. * Date: 01-2008
  7. *
  8. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  9. * @version    1.0
  10. * @usage       
  11. *
  12. */
  13.  
  14. package {
  15.    
  16.     import flash.display.*;
  17.     import flash.events.*;
  18.     import flash.filters.BlurFilter;
  19.     import flash.filters.ColorMatrixFilter;
  20.     import flash.geom.*;
  21.     import flash.ui.*;
  22.     import caurina.transitions.Tweener;
  23.     import caurina.transitions.properties.CurveModifiers;
  24.    
  25.     public class Draw3 extends Sprite {
  26.        
  27.         //------------------------------------
  28.         // private properties
  29.         //------------------------------------
  30.        
  31.         private var _lineNum:uint = 5;
  32.         private var _pointNum:uint = 40;
  33.         private var _lineArray:Array = [];
  34.         private var _objArray:Object = [];
  35.         private var _maxRadius:Number = 150;
  36.        
  37.         private var _cmf:ColorMatrixFilter;
  38.         private var _bf:BlurFilter;
  39.        
  40.         //------------------------------------
  41.         // public properties
  42.         //------------------------------------
  43.        
  44.         private var _bmd:BitmapData;
  45.        
  46.         //------------------------------------
  47.         // constructor
  48.         //------------------------------------
  49.        
  50.         public function Draw3() {
  51.             stage.scaleMode = StageScaleMode.NO_SCALE;
  52.             stage.frameRate = 41;
  53.             CurveModifiers.init();
  54.             _cmf = new ColorMatrixFilter([1,0,0,0,0,
  55.                                           0,1,0,0,0,
  56.                                           0,0,1,0,0,
  57.                                           0,0,0,.5,0]);
  58.             _bf = new BlurFilter(8, 8, 3);
  59.             createCanvas();
  60.             createLines();
  61.         }
  62.        
  63.         //
  64.         // PRIVATE
  65.         //________________________________________________________________________________________________
  66.        
  67.         public function createCanvas():void {
  68.             _bmd = new BitmapData(550, 400, true, 0x000000);
  69.             var bm:Bitmap = new Bitmap(_bmd);
  70.             addChild(bm);
  71.         }
  72.        
  73.         private function createLines():void {
  74.             for (var i:uint = 0; i <_lineNum; i++) {
  75.                 var obj:Object = { };
  76.                 obj.color = Math.random() * 0xFF0000;
  77.                 obj.x = obj.prevX = getRandomPos().x;
  78.                 obj.y = obj.prevY = getRandomPos().y;
  79.                 _objArray.push(obj);
  80.                 var l:Sprite = new Sprite();
  81.                 //l.filters = [new BlurFilter(2, 2, 3)]
  82.                 l.name = "line" + i;
  83.                 l.graphics.lineStyle(3, Math.random() * obj.color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  84.                 addChild(l);
  85.                 _lineArray.push(l);
  86.                 randomTween(getRandomData(obj, l), l);
  87.             }
  88.             addEventListener(Event.ENTER_FRAME, loop);
  89.         }
  90.        
  91.         private function loop(e:Event):void {
  92.             for (var i = 0; i <_lineNum; i++) {
  93.                 _lineArray[i].graphics.clear();
  94.                 _lineArray[i].graphics.lineStyle(3, _objArray[i].color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  95.                 _lineArray[i].graphics.moveTo(_objArray[i].prevX, _objArray[i].prevY);
  96.                 _lineArray[i].graphics.lineTo(_objArray[i].x, _objArray[i].y);
  97.                 _objArray[i].prevX = _objArray[i].x;
  98.                 _objArray[i].prevY = _objArray[i].y;
  99.             }
  100.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _cmf);
  101.             //_bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _bf);
  102.             _bmd.draw(this);
  103.         }
  104.        
  105.         private function randomTween(o:Object, line:Sprite):void {
  106.             Tweener.addTween(o, { x:o.x1, y:o.y1, _bezier:o.bezier, time :o .time, transition:"linear", onComplete:
  107.                 function():void {
  108.                     randomTween(getRandomData(o, line), line);
  109.                 }
  110.             });
  111.         }
  112.        
  113.         private function getRandomData(obj:Object, line:Sprite):Object {
  114.             obj.time = Math.random() * 8 + 12;
  115.             obj.x1 = getRandomPos().x;
  116.             obj.y1 = getRandomPos().y;
  117.             obj.bezier = [];
  118.             for (var i = 0; i <_pointNum; i++) {
  119.                 obj.bezier.push({
  120.                     x:getRandomPos().x,
  121.                     y:getRandomPos().y
  122.                 });
  123.             }
  124.             return obj;
  125.         }
  126.        
  127.         private function getRandomPos():Object {
  128.             var o:Object = {}
  129.             o.x = Math.cos(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageWidth * .5);
  130.             o.y = Math.sin(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageHeight * .5);
  131.             return o;
  132.         }
  133.        
  134.         // PUBLIC
  135.         //________________________________________________________________________________________________
  136.        
  137.    
  138.     }
  139.  
  140. }

Draw 4 (demo)

Just a bit of fun on the second experiment with a blur filter, pretty nice if you like techno style :)

Actionscript:
  1. /*
  2. * Class
  3. *
  4. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  5. * Actionscript: built for actionscript 3.0 and flash player 9
  6. * Date: 01-2008
  7. *
  8. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  9. * @version    1.0
  10. * @usage       
  11. *
  12. */
  13.  
  14. package {
  15.    
  16.     import flash.display.*;
  17.     import flash.events.*;
  18.     import flash.filters.BlurFilter;
  19.     import flash.filters.ColorMatrixFilter;
  20.     import flash.geom.*;
  21.     import flash.ui.*;
  22.     import caurina.transitions.Tweener;
  23.     import caurina.transitions.properties.CurveModifiers;
  24.    
  25.     public class Draw4 extends Sprite {
  26.        
  27.         //------------------------------------
  28.         // private properties
  29.         //------------------------------------
  30.        
  31.         private var _lineNum:uint = 5;
  32.         private var _pointNum:uint = 5;
  33.         private var _lineArray:Array = [];
  34.         private var _objArray:Object = [];
  35.         private var _maxRadius:Number = 150;
  36.        
  37.         private var _cmf:ColorMatrixFilter;
  38.         private var _bf:BlurFilter;
  39.        
  40.         //------------------------------------
  41.         // public properties
  42.         //------------------------------------
  43.        
  44.         private var _bmd:BitmapData;
  45.         private var _bm:Bitmap;
  46.        
  47.         //------------------------------------
  48.         // constructor
  49.         //------------------------------------
  50.        
  51.         public function Draw4() {
  52.             stage.scaleMode = StageScaleMode.NO_SCALE;
  53.             stage.frameRate = 41;
  54.             CurveModifiers.init();
  55.             btReload.addEventListener(MouseEvent.CLICK, reload);
  56.             _cmf = new ColorMatrixFilter([1,0,0,0,0,
  57.                                           0,1,0,0,0,
  58.                                           0,0,1,0,0,
  59.                                           0,0,0,1,0]);
  60.             _bf = new BlurFilter(6, 6, 2);
  61.             createCanvas();
  62.             createLines();
  63.         }
  64.        
  65.         //
  66.         // PRIVATE
  67.         //________________________________________________________________________________________________
  68.        
  69.         public function createCanvas():void {
  70.             _bmd = new BitmapData(550, 400, true, 0x000000);
  71.             _bm = new Bitmap(_bmd);
  72.             addChild(_bm);
  73.         }
  74.        
  75.         private function createLines():void {
  76.             for (var i:uint = 0; i <_lineNum; i++) {
  77.                 var obj:Object = { };
  78.                 obj.color = Math.random() * 0xFF0000;
  79.                 obj.x = getRandomPos().x;
  80.                 obj.y = getRandomPos().y;
  81.                 _objArray.push(obj);
  82.                 var l:Sprite = new Sprite();
  83.                 l.filters = [new BlurFilter(3, 3, 2)]
  84.                 l.name = "line" + i;
  85.                 l.graphics.lineStyle(3, Math.random() * obj.color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  86.                 addChild(l);
  87.                 _lineArray.push(l);
  88.                 randomTween(getRandomData(obj, l), l);
  89.             }
  90.             addEventListener(Event.ENTER_FRAME, loop);
  91.         }
  92.        
  93.         private function loop(e:Event):void {
  94.             for (var i = 0; i <_lineNum; i++) {
  95.                 _lineArray[i].graphics.lineTo(_objArray[i].x, _objArray[i].y);
  96.             }
  97.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _cmf);
  98.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _bf);
  99.             _bmd.draw(this);
  100.         }
  101.        
  102.         private function randomTween(o:Object, line:Sprite):void {
  103.             line.graphics.clear();
  104.             line.graphics.lineStyle(3, o.color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  105.             line.graphics.moveTo(o.x, o.y);
  106.             Tweener.addTween(o, { x:o.x1, y:o.y1, _bezier:o.bezier, time :o .time, transition:"linear", onComplete:
  107.                 function():void {
  108.                     randomTween(getRandomData(o, line), line);
  109.                 }
  110.             });
  111.         }
  112.        
  113.         private function getRandomData(obj:Object, line:Sprite):Object {
  114.             obj.time = Math.random() * 2 + .8;
  115.             obj.x1 = getRandomPos().x;
  116.             obj.y1 = getRandomPos().y;
  117.             obj.bezier = [];
  118.             for (var i = 0; i <_pointNum; i++) {
  119.                 obj.bezier.push({
  120.                     x:getRandomPos().x,
  121.                     y:getRandomPos().y
  122.                 });
  123.             }
  124.             return obj;
  125.         }
  126.        
  127.         private function getRandomPos():Object {
  128.             var o:Object = {}
  129.             o.x = Math.cos(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageWidth * .5);
  130.             o.y = Math.sin(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageHeight * .5);
  131.             return o;
  132.         }
  133.        
  134.         // PUBLIC
  135.         //________________________________________________________________________________________________
  136.        
  137.         public function reload(e:MouseEvent = null):void {
  138.             Tweener.removeAllTweens();
  139.             removeEventListener(Event.ENTER_FRAME, loop);
  140.             for (var i:uint = 0; i <_lineNum; i++) {
  141.                 removeChild(_lineArray[i]);
  142.             }
  143.             removeChild(_bm);
  144.             _objArray = [];
  145.             _lineArray = [];
  146.             createCanvas();
  147.             createLines();
  148.         }
  149.    
  150.     }
  151.  
  152. }

Draw 5 (demo)

This one is mixing the colors and creating a shape little by little.

Actionscript:
  1. /*
  2. * Class
  3. *
  4. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  5. * Actionscript: built for actionscript 3.0 and flash player 9
  6. * Date: 01-2008
  7. *
  8. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  9. * @version    1.0
  10. * @usage       
  11. *
  12. */
  13.  
  14. package {
  15.    
  16.     import flash.display.*;
  17.     import flash.events.*;
  18.     import flash.filters.BlurFilter;
  19.     import flash.filters.ColorMatrixFilter;
  20.     import flash.geom.*;
  21.     import flash.ui.*;
  22.     import caurina.transitions.Tweener;
  23.     import caurina.transitions.properties.CurveModifiers;
  24.    
  25.     public class Draw5 extends Sprite {
  26.        
  27.         //------------------------------------
  28.         // private properties
  29.         //------------------------------------
  30.        
  31.         private var _lineNum:uint = 5;
  32.         private var _pointNum:uint = 10;
  33.         private var _lineArray:Array = [];
  34.         private var _objArray:Object = [];
  35.         private var _maxRadius:Number = 150;
  36.        
  37.         private var _cmf:ColorMatrixFilter;
  38.         private var _bf:BlurFilter;
  39.        
  40.         //------------------------------------
  41.         // public properties
  42.         //------------------------------------
  43.        
  44.         private var _bmd:BitmapData;
  45.         private var _bm:Bitmap;
  46.        
  47.         //------------------------------------
  48.         // constructor
  49.         //------------------------------------
  50.        
  51.         public function Draw5() {
  52.             stage.scaleMode = StageScaleMode.NO_SCALE;
  53.             stage.frameRate = 41;
  54.             CurveModifiers.init();
  55.             btReload.addEventListener(MouseEvent.CLICK, reload);
  56.             _cmf = new ColorMatrixFilter([1.1,0,0,0,0,
  57.                                           0,1.1,0,0,0,
  58.                                           0,0,1.1,0,0,
  59.                                           0,0,0,.585,0]);
  60.             _bf = new BlurFilter(5, 5, 2);
  61.             createCanvas();
  62.             createLines();
  63.         }
  64.        
  65.         //
  66.         // PRIVATE
  67.         //________________________________________________________________________________________________
  68.        
  69.         public function createCanvas():void {
  70.             _bmd = new BitmapData(550, 400, true, 0x000000);
  71.             _bm = new Bitmap(_bmd);
  72.             addChild(_bm);
  73.         }
  74.        
  75.         private function createLines():void {
  76.             for (var i:uint = 0; i <_lineNum; i++) {
  77.                 var obj:Object = { };
  78.                 obj.color = Math.random() * 0xFF0000;
  79.                 obj.x = obj.prevX = getRandomPos().x;
  80.                 obj.y = obj.prevY = getRandomPos().y;
  81.                 _objArray.push(obj);
  82.                 var l:Sprite = new Sprite();
  83.                 l.filters = [new BlurFilter(2, 2, 2)]
  84.                 l.name = "line" + i;
  85.                 l.graphics.lineStyle(3, Math.random() * obj.color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  86.                 addChild(l);
  87.                 _lineArray.push(l);
  88.                 randomTween(getRandomData(obj, l), l);
  89.             }
  90.             addEventListener(Event.ENTER_FRAME, loop);
  91.         }
  92.        
  93.         private function loop(e:Event):void {
  94.             for (var i = 0; i <_lineNum; i++) {
  95.                 _lineArray[i].graphics.clear();
  96.                 _lineArray[i].graphics.lineStyle(3, _objArray[i].color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  97.                 _lineArray[i].graphics.moveTo(_objArray[i].prevX, _objArray[i].prevY);
  98.                 _lineArray[i].graphics.lineTo(_objArray[i].x, _objArray[i].y);
  99.                 _objArray[i].prevX = _objArray[i].x;
  100.                 _objArray[i].prevY = _objArray[i].y;
  101.             }
  102.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _cmf);
  103.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _bf);
  104.             _bmd.draw(this);
  105.         }
  106.        
  107.         private function randomTween(o:Object, line:Sprite):void {
  108.             Tweener.addTween(o, { x:o.x1, y:o.y1, _bezier:o.bezier, time :o .time, transition:"linear", onComplete:
  109.                 function():void {
  110.                     randomTween(getRandomData(o, line), line);
  111.                 }
  112.             });
  113.         }
  114.        
  115.         private function getRandomData(obj:Object, line:Sprite):Object {
  116.             obj.time = Math.random() * 3 + 3;
  117.             obj.x1 = getRandomPos().x;
  118.             obj.y1 = getRandomPos().y;
  119.             obj.bezier = [];
  120.             for (var i = 0; i <_pointNum; i++) {
  121.                 obj.bezier.push({
  122.                     x:getRandomPos().x,
  123.                     y:getRandomPos().y
  124.                 });
  125.             }
  126.             return obj;
  127.         }
  128.        
  129.         private function getRandomPos():Object {
  130.             var o:Object = {}
  131.             o.x = Math.cos(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageWidth * .5);
  132.             o.y = Math.sin(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageHeight * .5);
  133.             return o;
  134.         }
  135.        
  136.         // PUBLIC
  137.         //________________________________________________________________________________________________
  138.        
  139.         public function reload(e:MouseEvent = null):void {
  140.             Tweener.removeAllTweens();
  141.             removeEventListener(Event.ENTER_FRAME, loop);
  142.             for (var i:uint = 0; i <_lineNum; i++) {
  143.                 removeChild(_lineArray[i]);
  144.             }
  145.             removeChild(_bm);
  146.             _objArray = [];
  147.             _lineArray = [];
  148.             createCanvas();
  149.             createLines();
  150.         }
  151.    
  152.     }
  153.  
  154. }

Draw 6 (demo)

Almost the same test but I move the bitmapdata layer.

Actionscript:
  1. /*
  2. * Class
  3. *
  4. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  5. * Actionscript: built for actionscript 3.0 and flash player 9
  6. * Date: 01-2008
  7. *
  8. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  9. * @version    1.0
  10. * @usage       
  11. *
  12. */
  13.  
  14. package {
  15.    
  16.     import flash.display.*;
  17.     import flash.events.*;
  18.     import flash.filters.BlurFilter;
  19.     import flash.filters.ColorMatrixFilter;
  20.     import flash.geom.*;
  21.     import flash.ui.*;
  22.     import caurina.transitions.Tweener;
  23.     import caurina.transitions.properties.CurveModifiers;
  24.    
  25.     public class Draw6 extends Sprite {
  26.        
  27.         //------------------------------------
  28.         // private properties
  29.         //------------------------------------
  30.        
  31.         private var _lineNum:uint = 5;
  32.         private var _pointNum:uint = 40;
  33.         private var _lineArray:Array = [];
  34.         private var _objArray:Object = [];
  35.         private var _maxRadius:Number = 150;
  36.        
  37.         private var _cmf:ColorMatrixFilter;
  38.         private var _bf:BlurFilter;
  39.        
  40.         //------------------------------------
  41.         // public properties
  42.         //------------------------------------
  43.        
  44.         private var _bmd:BitmapData;
  45.         private var _bm:Bitmap;
  46.        
  47.         //------------------------------------
  48.         // constructor
  49.         //------------------------------------
  50.        
  51.         public function Draw6() {
  52.             stage.scaleMode = StageScaleMode.NO_SCALE;
  53.             stage.frameRate = 41;
  54.             CurveModifiers.init();
  55.             btReload.addEventListener(MouseEvent.CLICK, reload);
  56.             _cmf = new ColorMatrixFilter([1.1,0,0,0,0,
  57.                                           0,1.1,0,0,0,
  58.                                           0,0,1.1,0,0,
  59.                                           0,0,0,.66,0]);
  60.             _bf = new BlurFilter(8, 8, 2);
  61.             createCanvas();
  62.             createLines();
  63.         }
  64.        
  65.         //
  66.         // PRIVATE
  67.         //________________________________________________________________________________________________
  68.        
  69.         public function createCanvas():void {
  70.             _bmd = new BitmapData(800, 400, true, 0x000000);
  71.             _bm = new Bitmap(_bmd);
  72.             addChild(_bm);
  73.         }
  74.        
  75.         private function createLines():void {
  76.             for (var i:uint = 0; i <_lineNum; i++) {
  77.                 var obj:Object = { };
  78.                 obj.color = Math.random() * 0xFF0000;
  79.                 obj.x = obj.prevX = getRandomPos().x;
  80.                 obj.y = obj.prevY = getRandomPos().y;
  81.                 _objArray.push(obj);
  82.                 var l:Sprite = new Sprite();
  83.                 l.filters = [new BlurFilter(2, 2, 2)]
  84.                 l.name = "line" + i;
  85.                 l.graphics.lineStyle(3, Math.random() * obj.color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  86.                 addChild(l);
  87.                 _lineArray.push(l);
  88.                 randomTween(getRandomData(obj, l), l);
  89.             }
  90.             addEventListener(Event.ENTER_FRAME, loop);
  91.         }
  92.        
  93.         private function loop(e:Event):void {
  94.             for (var i = 0; i <_lineNum; i++) {
  95.                 _lineArray[i].graphics.clear();
  96.                 _lineArray[i].graphics.lineStyle(3, _objArray[i].color, 1, false, LineScaleMode.NONE, CapsStyle.ROUND);
  97.                 _lineArray[i].graphics.moveTo(_objArray[i].prevX, _objArray[i].prevY);
  98.                 _lineArray[i].graphics.lineTo(_objArray[i].x, _objArray[i].y);
  99.                 _objArray[i].prevX = _objArray[i].x;
  100.                 _objArray[i].prevY = _objArray[i].y;
  101.             }
  102.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _cmf);
  103.             _bmd.applyFilter(_bmd, _bmd.rect, new Point(0, 0), _bf);
  104.             _bmd.draw(this);
  105.             _bmd.scroll(-4, 0);
  106.         }
  107.        
  108.         private function randomTween(o:Object, line:Sprite):void {
  109.             Tweener.addTween(o, { x:o.x1, y:o.y1, _bezier:o.bezier, time :o .time, transition:"linear", onComplete:
  110.                 function():void {
  111.                     randomTween(getRandomData(o, line), line);
  112.                 }
  113.             });
  114.         }
  115.        
  116.         private function getRandomData(obj:Object, line:Sprite):Object {
  117.             obj.time = Math.random() * 8 + 12;
  118.             obj.x1 = getRandomPos().x;
  119.             obj.y1 = getRandomPos().y;
  120.             obj.bezier = [];
  121.             for (var i = 0; i <_pointNum; i++) {
  122.                 obj.bezier.push({
  123.                     x:getRandomPos().x,
  124.                     y:getRandomPos().y
  125.                 });
  126.             }
  127.             return obj;
  128.         }
  129.        
  130.         private function getRandomPos():Object {
  131.             var o:Object = {}
  132.             o.x = Math.cos(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageWidth * .5 + 200);
  133.             o.y = Math.sin(Math.random() * (Math.PI * 2)) * (Math.sqrt(Math.random()) * _maxRadius) + (stage.stageHeight * .5);
  134.             return o;
  135.         }
  136.        
  137.         // PUBLIC
  138.         //________________________________________________________________________________________________
  139.        
  140.         public function reload(e:MouseEvent = null):void {
  141.             Tweener.removeAllTweens();
  142.             removeEventListener(Event.ENTER_FRAME, loop);
  143.             for (var i:uint = 0; i <_lineNum; i++) {
  144.                 removeChild(_lineArray[i]);
  145.             }
  146.             removeChild(_bm);
  147.             _objArray = [];
  148.             _lineArray = [];
  149.             createCanvas();
  150.             createLines();
  151.         }
  152.    
  153.     }
  154.  
  155. }

Source

You can download the source here.

More links

More details on the Tweener bezier curve and the color matrix filter use.

Tweener bezier

Abobe matrix

Grant Skinner matrix

Gimp doc

Vote in HexoSearch

Comments No Comments »