Lined Gradient
/**
* Copyright leichtgewicht ( http://wonderfl.net/user/leichtgewicht )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/yNZg
*/
package {
import flash.events.Event;
import flash.display.*;
public class Lines extends Sprite {
private const lineDistance: int = 3;
private const lineMargin: int = 1;
private const lineMin: int = 40;
private const lineDiff: int = 10;
private const brightNessLoss: int = 25;
private const formerLengths: Vector.<int> = new Vector.<int>();
public function Lines() {
addEventListener( Event.ADDED_TO_STAGE, init );
}
private function init( e: Event = null ): void {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
addEventListener( Event.RESIZE, onResize );
onResize();
}
private function onResize( e: Event = null ): void {
draw( stage.stageWidth, stage.stageHeight );
}
public function setSize( width: Number, height: Number ): void {
removeEventListener( Event.RESIZE, onResize );
draw( width, height );
}
private function draw( width: Number, height: Number ): void {
graphics.clear();
var diff: int = (lineDistance+1);
var amount: int = width / diff;
var i: int = formerLengths.length;
while( --i > -1 )
{
formerLengths[i] = 0;
}
while( formerLengths.length < amount )
{
formerLengths.push( 0 );
}
var color: int = 30;
while( color < 256 )
{
i = amount;
graphics.lineStyle( 1, color << 16 | color << 8 | color );
while( --i > -1 )
{
var y: int = formerLengths[i] + lineMin + lineDiff * Math.random();
var x: int = i * diff;
graphics.moveTo( x, formerLengths[i] );
graphics.lineTo( x, y );
formerLengths[i] = y+lineMargin;
}
color += brightNessLoss;
}
}
}
}