import
flash.display.Bitmap;
import
flash.display.BitmapData;
import
flash.utils.Timer;
import
flash.events.TimerEvent;
import
flash.geom.Point;
import
flash.utils.ByteArray;
import
flash.events.MouseEvent;
import
flash.geom.ColorTransform;
import
flash.filters.GlowFilter;
const
MAX_UNIT:
int
=
4096
;
var
bmpDatF:BitmapData =
new
BitmapData(
1
,
1
,
false
,
0x0000ff
);
var
bmpDatB:BitmapData =
new
BitmapData(stage.stageWidth, stage.stageHeight,
false
,
0x000000
);
var
canvas:Bitmap =
new
Bitmap(
new
BitmapData(stage.stageWidth, stage.stageHeight,
false
,
0xffffff
));
var
velVec:Vector.<Point> =
new
Vector.<Point>(MAX_UNIT);
var
posVec:Vector.<Point> =
new
Vector.<Point>(MAX_UNIT);
var
colorVec:Vector.<
uint
> =
new
Vector.<
uint
>(MAX_UNIT);
var
blueTransform:ColorTransform =
new
ColorTransform(
0.86
,
0.86
,
0.86
);
var
datumPoint:Point =
new
Point(
0
,
0
);
var
theta:
Number
=
0
;
velVec.fixed =
true
;
posVec.fixed =
true
;
colorVec.fixed =
true
;
for
(
var
i:
int
=
0
; i<MAX_UNIT; i++) {
velVec[i] =
new
Point(
0
,
0
);
posVec[i] =
new
Point(
0
,
0
);
colorVec[i] = getColorByHue(i/MAX_UNIT*i/MAX_UNIT*i/MAX_UNIT*i/MAX_UNIT*
360
);
}
addChild(canvas);
var
timer:Timer =
new
Timer(
1000
/
60
);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
function
timerHandler(evt:TimerEvent):
void
{
canvas.bitmapData.lock();
if
(podoed)
canvas.bitmapData.colorTransform(canvas.bitmapData.rect, blueTransform);
else
canvas.bitmapData.copyPixels(bmpDatB,bmpDatB.rect,datumPoint);
var
dx:
Number
;
var
dy:
Number
;
var
direction:
Number
;
var
color:
uint
;
for
(
var
i:
int
=MAX_UNIT-
1
; i>=
0
; i--) {
dx = stage.mouseX-posVec[i].x;
dy = stage.mouseY-posVec[i].y;
direction = Math.atan2(dy,dx);
velVec[i].x += (i/MAX_UNIT*
3.6
+
0.5
)*Math.cos(direction);
velVec[i].y += (i/MAX_UNIT*
3.6
+
0.5
)*Math.sin(direction);
posVec[i].x += velVec[i].x;
posVec[i].y += velVec[i].y;
velVec[i].x *= i/MAX_UNIT*
0.14
+
0.85
;
velVec[i].y *= i/MAX_UNIT*
0.14
+
0.85
;
if
(Math.abs(dx)<
1
&&Math.abs(dy)<
1
) {
posVec[i].x = stage.mouseX;
posVec[i].y = stage.mouseY;
velVec[i].x =
0
;
velVec[i].y =
0
;
}
canvas.bitmapData.setPixel(posVec[i].x,posVec[i].y,colorVec[i]);
}
canvas.bitmapData.unlock();
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
function
clickHandler(evt:MouseEvent):
void
{
if
(evt.stageX>podo.x && evt.stageX<podo.x+podo.width
&& evt.stageY>podo.y && evt.stageY<podo.y+podo.height) {
podoClicked(
null
);
return
;
}
for
(
var
i:
int
=
0
; i<MAX_UNIT; i++) {
velVec[i].x =
0
;
velVec[i].y =
0
;
posVec[i].x = evt.stageX;
posVec[i].y = evt.stageY;
}
}
function
getColorByHue(angle:
Number
):
uint
{
var
hue:
Number
= (angle+
0
) %
360
;
var
var
iation:
uint
=
uint
((hue %
60
)/
60
*
0xff
);
var
red:
uint
, blue:
uint
, green:
uint
;
if
(hue<
60
) {
red =
0xff
;
blue =
0
;
green =
var
iation;
}
else
if
(hue <
120
) {
red =
0xff
-
var
iation
blue =
0
;
green =
0xff
;
}
else
if
(hue <
180
) {
red =
0
blue =
var
iation;
green =
0xff
;
}
else
if
(hue <
240
) {
red =
0x0
;
blue =
0xff
;
green =
0xff
-
var
iation;
}
else
if
(hue <
300
) {
red =
var
iation;
blue =
0xff
;
green =
0x0
;
}
else
if
(hue <
360
) {
red =
0xff
;
blue =
0xff
-
var
iation;
green =
0
;
}
return
red<<
16
|green<<
8
|blue;
}
var
podo:Sprite =
new
Podo();
podo.width*=
0.40
;
podo.height*=
0.40
;
podo.x = stage.stageWidth-podo.width;
podo.y = stage.stageHeight-podo.height;
stage.addChild(podo);
var
podoed:
Boolean
=
false
;
var
podoFilter:GlowFilter =
new
GlowFilter(
0xffff00
,
1
,
4
,
4
,
4
,
3
);
function
podoClicked(evt:MouseEvent):
void
{
if
(!podoed) {
podo.filters = [podoFilter];
podoed =
true
;
}
else
{
podo.filters = [];
podoed =
false
;
}
}