LightCircle [BitmapData版]
////////////////////////////////////////////////////////////////////////////////
// LightCircle [BitmapData版]
//
// [AS3.0] LightCircleクラスだ! (2)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1153
////////////////////////////////////////////////////////////////////////////////
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/one9
*/
////////////////////////////////////////////////////////////////////////////////
// LightCircle [BitmapData版]
//
// [AS3.0] LightCircleクラスだ! (2)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1153
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.geom.Rectangle;
import flash.events.MouseEvent;
import net.hires.debug.Stats;
[SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var light:LightCircle;
public function Main() {
init();
addChild(new Stats());
}
private function init():void {
graphics.beginFill(0x000000);
graphics.drawRect(0, 0, 465, 465);
graphics.endFill();
var rect:Rectangle = new Rectangle(0, 0, 465, 465);
var colors:Array = new Array();
colors.push({h: 270, s: 0.6, v: 1});
colors.push({h: 300, s: 0.8, v: 1});
colors.push({h: 0, s: 0.8, v: 1});
colors.push({h: 60, s: 1, v: 1});
colors.push({h: 76, s: 0.8, v: 1});
colors.push({h: 90, s: 1, v: 1});
colors.push({h: 100, s: 1, v: 0.8});
colors.push({h: 180, s: 1, v: 1});
colors.push({h: 200, s: 1, v: 1});
colors.push({h: 220, s: 1, v: 1});
light = new LightCircle(rect, colors);
addChild(light);
light.start();
}
}
}
//////////////////////////////////////////////////
// LightCircleクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.display.BlendMode;
import frocessing.color.ColorHSV;
class LightCircle extends Sprite {
private var rect:Rectangle;
private var bitmapData:BitmapData;
private var bitmap:Bitmap;
private var colors:Array;
private var max:uint;
private var circles:Array;
private var bds:Array;
public function LightCircle(r:Rectangle, c:Array) {
rect = r;
colors = c;
max = colors.length;
init();
}
private function init():void {
bitmapData = new BitmapData(rect.width, rect.height, false, 0xFF000000);
bitmap = new Bitmap(bitmapData);
addChild(bitmap);
circles = new Array();
bds = new Array();
for (var n:uint = 0; n < max; n++) {
var hue:uint = colors[n].h;
var saturation:Number = colors[n].s;
var value:Number = colors[n].v;
var color:ColorHSV = new ColorHSV(hue, saturation, value);
var circle:Circle = new Circle(100);
circle.x = Math.random()*rect.width;
circle.y = Math.random()*rect.height;
circle.vx = Math.random()*8 - 4;
circle.vy = Math.random()*8 - 4;
circle.color = color.value;
circles.push(circle);
bds.push(circle.bitmapData);
}
}
public function start():void {
addEventListener(Event.ENTER_FRAME, update, false, 0, true);
}
public function stop():void {
removeEventListener(Event.ENTER_FRAME, update);
}
private function update(evt:Event):void {
bitmapData.lock();
bitmapData.fillRect(rect, 0xFF000000);
for (var n:uint = 0; n < max; n++) {
var circle:Circle = circles[n];
var bd:BitmapData = bds[n];
if (circle.x < rect.left || circle.x > rect.right) circle.vx = - circle.vx;
if (circle.y < rect.top || circle.y > rect.bottom) circle.vy = - circle.vy;
circle.x += circle.vx;
circle.y += circle.vy;
var matrix:Matrix = new Matrix();
matrix.translate(circle.x - 150, circle.y - 150);
bitmapData.draw(bd, matrix, null, BlendMode.ADD);
}
bitmapData.unlock();
}
}
//////////////////////////////////////////////////
// Circleクラス
//////////////////////////////////////////////////
import flash.display.Shape;
import flash.display.BitmapData;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
class Circle extends Shape {
private var radius:uint = 100;
private var size:uint = 300;
private var rgb:uint = 0xFFFFFF;
private var blur:BlurFilter
public var vx:Number = 0;
public var vy:Number = 0;
public var bitmapData:BitmapData;
public function Circle(r:uint) {
radius = r;
blur = new BlurFilter(radius*0.5, radius*0.5, 3);
//draw();
}
private function draw():void {
graphics.clear();
graphics.beginFill(rgb);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
var blur:BlurFilter = new BlurFilter(50, 50, 3);
filters = [blur];
bitmapData = new BitmapData(size, size, false, 0xFF000000);
var matrix:Matrix = new Matrix();
matrix.translate(size/2, size/2);
bitmapData.draw(this, matrix);
}
public function set color(c:uint):void {
rgb = c;
draw();
}
}