1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
| package
{
import com.rickigregersen.flow_bump.Arrow;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.ColorTransform;
import flash.media.Camera;
import flash.media.Video;
import mx.core.UIComponent;
public class Main extends UIComponent
{
//theese are the values I had fun playing with, but you might want something a bit more crazy:)
private static const TRAIL : Number = 0.95;
private static const BOOST : int = 110;
private static const VECTORS : int = 1000;
private static const BLUR : int = 4;
private static const SCALE : Number = 6.0;
private static const BACKGROUND : uint = 0x000000;
;
private static var fading : ColorTransform = new ColorTransform( 1, 1, 1, TRAIL );
private static var blurFilter : BlurFilter = new BlurFilter( BLUR, BLUR, 3 )
private static var grayMatrix : Array = [ 0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0.3, 0.59, 0.11, 0, 0, 0, 0, 0, 1, 0 ];
private var grayFilter : ColorMatrixFilter = new ColorMatrixFilter( grayMatrix );
private var brightMatrix : Array = [ 1, 0, 0, 0, BOOST, 0, 1, 0, 0, BOOST, 0, 0, 1, 0, BOOST, 0, 0, 0, 1, 0 ]
private var brightFilter : ColorMatrixFilter = new ColorMatrixFilter( brightMatrix );
private var camBMD : BitmapData;
private var camBMP : Bitmap;
private var renderBMD : BitmapData;
private var renderBMP : Bitmap;
private var vid : Video;
private var cam : Camera;
private var w : int, h : int;
private var flowImage : Sprite;
public function Main( _w : int, _h : int )
{
//width and height, also a sprite for holding the little particles;
w = _w;
h = _h;
flowImage = new Sprite();
//get the video;
cam = Camera.getCamera();
vid = new Video( w, h );
vid.attachCamera( cam );
//make a bitmap for drawing the video into
camBMD = new BitmapData( w, h, false, BACKGROUND );
camBMP = new Bitmap( camBMD );
//a bitmap to stuff it all into and give some sort of effect
renderBMD = new BitmapData( w, h, false, BACKGROUND );
renderBMP = new Bitmap( renderBMD );
//add the cam bmp and the rendered bmp
addChild( camBMP );
camBMP.y = h;
addChild( renderBMP );
//build the little vectors
buildVectors();
}
private function buildVectors() : void
{
//place, rotate and scale them randomly
var a : Arrow;
for ( var i : int = 0; i < VECTORS; i++ )
{
a = new Arrow();
a.x = Math.random() * w;
a.y = Math.random() * h;
a.rotation = Math.random() * 360;
a.scaleX = a.scaleY = Math.random() + 0.1;
flowImage.addChild( a );
}
addEventListener( Event.ENTER_FRAME, update, false, 0, true );
}
private function update( event : Event ) : void
{
//draw the cam to the stage, appy the grayscale Matrix, sometimes blur and brightfilters too
camBMD.draw( vid );
camBMP.filters = [ grayFilter /*, blurFilter, brightFilter */ ];
var a : Arrow;
var brightness : Number;
var radians : Number;
var angle : Number;
var speed : Number;
var pixel : int;
for ( var i : int = 0; i < VECTORS; i++ )
{
a = flowImage.getChildAt( i ) as Arrow;
//get the brightness values of the pixel positioned directly under the vector
pixel = camBMD.getPixel( a.x, a.y );
brightness = pixel / 0xFFFFFF;
//adjust spped and angle acording to the brightness
speed = 0.1 + brightness * a.speed;
angle = 360 * brightness * a.wander;
radians = angle * Math.PI / 180;
//make sure the vector is moving in the same direction as it's velocity
a.x += Math.cos( radians ) * a.speed;
a.y += Math.sin( radians ) * a.speed;
//scale and rotate the vector according to brightness and
a.rotation = angle;
a.scaleX = a.scaleY = 0.1 + brightness * SCALE;
//wrap around
if ( a.x > w )
a.x = 0;
else if ( a.x < 0 )
a.x = w;
if ( a.y > h )
a.y = 0;
else if ( a.y < 0 )
a.y = h;
}
//apply the colortransform, it determines the transparency of the bitmaps being stacked
renderBMD.colorTransform( renderBMD.rect, fading );
//draw the Sprite that hold all the vectors.
renderBMD.draw( flowImage );
}
}
} |