Rainbow Falls forked from: Saqoosha challenge for amateurs
上部にマウスを持っていくと暖色、下部にマウスを持っていくと寒色になっています。
/**
* Copyright k3lab ( http://wonderfl.net/user/k3lab )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xtQs
*/
// forked from checkmate's Saqoosha challenge for amateurs
package {
/*上部にマウスを持っていくと暖色、下部にマウスを持っていくと寒色になっています。*/
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
[SWF(width="465", height="465", frameRate="60")]
public class Main extends Sprite {
private var clt:ColorTransform = new ColorTransform(1, 1, 1, 1, 0, 0,-2, -2);
private var ParticleNum:Number = 10000;
private var pArr:Array = []
private var canvas:BitmapData;
private var canvasbmp:Bitmap;
private var clones:BitmapData;
private var grad:Gradation;
public function Main():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
grad = new Gradation(0xFFFF0000, 0x00FF0000, 0xFF00FF00);
var grads:Gradation = new Gradation(0xFFFFFF,0x052eff);
for (var y:int = 0; y < 465; y++) {
var sp:Sprite = addChild(new Sprite()) as Sprite;
sp.graphics.beginFill(grads.getColor(y / 464));
sp.graphics.drawRect(0, y, 465, 1);
sp.graphics.endFill();
}
canvas = new BitmapData(465, 465, true, 0);
canvasbmp = addChild(new Bitmap(canvas)) as Bitmap;
canvasbmp.blendMode = "add";
clones = canvas.clone();
addChild(new Bitmap(clones)) as Bitmap;
while (ParticleNum--) {
pArr.push(new Particle(int(Math.random() * 465), 465 - int(Math.random() * 465 * 2), Math.random()*0xFFFF8800))
}
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void {
var n:int;
var cl:uint;
for each (var p:Particle in pArr) {
var xp:Number = mouseX - p.x;
var yp:Number = mouseY - p.y;
p.vy += 2;
if (( n = xp * xp + yp * yp) < 80 * 80 && p.y > 0) {
n = Math.sqrt(n) /3;
p.vx -= xp / n;
p.vy -= yp / n;
}
p.vx *= 0.79;
p.vy *= 0.79;
p.x+= p.vx;
if ((p.y += p.vy) > 465) {
p.y = -int(Math.random() * 465);
p.x = int(Math.random() * 465);
p.vx = 0;
p.vy = 0;
p.color = grad.getColor(Math.sqrt(n))-n
}
(p.x < 0)?p.x = 0:p.x;
(p.x > 465)?p.x = 465:p.x;
(p.x < 0||p.x > 465)?p.vx*=-3:p.vx;
p.color += p.vy *60
cl=canvas.getPixel(p.x,p.y)|p.color
canvas.setPixel32(p.x + 0.5, p.y + 0.5, cl);
n++;
}
canvas.lock();
clones.lock();
clones.draw(canvas);
clones.applyFilter(clones, canvas.rect, new Point(0, 0), new BlurFilter(0, 2, 1));
canvas.applyFilter(canvas, canvas.rect, new Point(0, 0), new BlurFilter(2, 2, 2));
canvas.colorTransform(canvas.rect, clt);
clones.colorTransform(clones.rect, clt);
clones.scroll(0,-3)
canvas.unlock();
clones.unlock();
}
}
}
class Particle {
public var x:Number;
public var y:Number;
public var vx:Number;
public var vy:Number;
public var color:uint;
public function Particle(x:Number, y:Number, color:uint) {
this.x = x;
this.y = y;
this.vx = 0;
this.vy = 0;
this.color = color;
}
}
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);
}
}
}