forked from: Saqoosha challenge for amateurs
/**
* Copyright nbhd ( http://wonderfl.net/user/nbhd )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kY5m
*/
// forked from checkmate's Saqoosha challenge for amateurs
package {
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.utils.Timer;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
import org.libspark.betweenas3.tweens.*;
[SWF(width=465, height=465, backgroundColor=0x0, frameRate=60)]
public class Grad extends Sprite {
private var _container:Sprite = new Sprite();
private var _mask:Sprite = new Sprite();
private var _spList:Array = new Array();
public function Grad() {
addEventListener(Event.ADDED_TO_STAGE, _onAdded);
}
private function _onAdded(e:Event):void {
removeEventListener(e.type, arguments.callee);
addChild(_container);
var total:int = 465;
var grad:Gradation = new Gradation(0xffff00, 0x00ff00, 0x0000ff, 0xff00ff);
for (var i:int = 0; i < total; i++) {
_spList[i] = new Sprite();
// grad.setEasing(Elastic.easeOutIn);
var g:Graphics = _spList[i].graphics as Graphics;
g.beginFill(grad.getColor(i/(total-1)));
g.drawRect(0, 0, stage.stageWidth, 1);
g.endFill();
i != 0 ? _spList[i].y = _spList[i - 1].y + _spList[i].height : false;
_container.addChild(_spList[i]);
_spList[i].addEventListener(Event.ENTER_FRAME, _loop);
}
_addCircle();
addChild(_mask);
// m.alpha = 0.5;
// m.filters = [ new BlurFilter()];
// m.cacheAsBitmap = true;
// _container.cacheAsBitmap = true;
_container.mask = _mask;
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, _onTimer);
timer.start();
}
private function _onTimer(e:TimerEvent):void {
BetweenAS3.tween(_container, {scaleY:Math.random()*3+1},null,3,Circ.easeOut).play();
_addCircle();
}
private function _loop(e:Event):void {
var sp:Sprite = e.target as Sprite;
// sp.filters = [ new BlurFilter(4, 20)];
// sp.blendMode = "add";
if (sp.y > stage.stageHeight) sp.y = 0;
// sp.y += 1;
sp.y += Math.random()*3;
}
private function _addCircle():void {
// 丸いの更新敷き詰めるのねん
var mg:Graphics = _mask.graphics as Graphics;
mg.clear();
var p:Point = new Point();
var n:int = Math.random() * 40 + 10;
var r:Number = stage.stageWidth / n / 2;
mg.beginFill(0x0);
for(var v:int = 0; v < n; v++){
for(var k:int = 0; k < n; k++){
if(v == 0){
k == 0 ? mg.drawCircle(p.x, p.y, r) : mg.drawCircle((p.x + r*2) * k, p.y, r);
}else {
k == 0 ? mg.drawCircle(p.x, (p.y + r * 2) * v, r) : mg.drawCircle((p.x + r * 2) * k, (p.y + r * 2) * v, r);
}
}
}
_mask.x = _mask.y = r;
}
}
}
import frocessing.color.ColorLerp;
import org.libspark.betweenas3.core.easing.IEasing;
import org.libspark.betweenas3.easing.Linear;
class Gradation {
private var _colors:Array;
private var _easing:IEasing;
public function Gradation(...args) {
_colors = args.concat();
_easing = Linear.linear;
}
public function setEasing(easing:IEasing):void {
_easing = easing;
}
public function getColor(position:Number):uint {
position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
var idx:int = position;
var alpha:Number = _easing.calculate(position - idx, 0, 1, 1);
if (alpha == 0) {
return _colors[idx];
} else {
return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
}
}
}