SoundInteractiveblobs
音にあわせてblobsが動き出します。
// forked from mrdoob's Interactive blobs
// forked from Murai's TrippyAtractor http://wonderfl.net/c/yEFY
// forked from mrdoob's Interactive blobs
// forked from Murai's TrippyAtractor http://wonderfl.net/c/yEFY
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.utils.ByteArray;
[SWF( backgroundColor='0xFFFFFF', frameRate='50', width='465', height='465')]
/*
* Free Music Archive: Digi G'Alessio - ekiti son feat valeska - april deegee rmx
* http://creativecommons.org/licenses/by-nc-nd/3.0/
*/
public class blobsSoundInteractive extends Sprite {
private var snd:Sound;
private var FFTswitch:Boolean = true;
private var vol:Number;
private var bytes:ByteArray;
//blobs
private var bl :Array;
private var r :Bitmap;
private var c :Sprite;
private var b :Sprite;
private var s :Number = 100;
private var p :Number = 0.8;
function blobsSoundInteractive() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.quality = StageQuality.LOW;
//play("http://yabuchany.com/blog/wp-content/uploads/2010/12/src/Lee_Rosevere_-_01_-_Christmas_Eve_At_Midnight_Small_Town_Square.mp3");
//play("http://level0.kayac.com/images/murai/Digi_GAlessio_-_08_-_ekiti_son_feat_valeska_-_april_deegee_rmx.mp3");
play("http://www.takasumi-nagai.com/soundfiles/sound001.mp3");
bytes = new ByteArray();
bl = new Array();
b = new Sprite();
b.graphics.beginFill(0xFFFFFF,0.8);
b.graphics.lineTo(stage.stageWidth,0);
b.graphics.lineTo(stage.stageWidth,stage.stageHeight);
b.graphics.lineTo(0,stage.stageHeight);
b.graphics.lineTo(0,0);
b.graphics.endFill();
addChild(b);
c = new Sprite();
c.filters = [new BlurFilter(20,20,2)];
addChild(c);
r = new Bitmap( new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x00FFFFFF ) );
addChild(r);
addEventListener(Event.ENTER_FRAME, _update);
addEventListener(Event.ENTER_FRAME, render);
}
private function _reset():void {
for (var i:Number = 0; i < 150; i ++)
{
bl[i].offsetx = Math.random()*465-200;
bl[i].offsety = Math.random()*465-200;
}
}
private function _update(e:Event):void {
//blobs
for (var i:Number = 0; i < 150; i ++)
{
if (!bl[i])
{
bl[i] = new MovieClip();
//bl[i].graphics.beginFill(0xFF7004A,1);
bl[i].graphics.beginFill(0x0066FF,1);
bl[i].graphics.drawCircle(0,0,Math.random()*50+5);
bl[i].x = stage.stageWidth*.5 + Math.random()*465-200;
bl[i].y = stage.stageHeight*.5 + Math.random()*465-200;
bl[i].xspeed = bl[i].yspeed = 0;
//bl[i].cycle = Math.random() * .01 + .0005;
bl[i].cycle = Math.random() * .03 + .0005;
bl[i].offsetx = 0;
bl[i].offsety = 0;
c.addChild(bl[i]);
}
bl[i].x += bl[i].xspeed = (( stage.stageWidth/2 - bl[i].x + bl[i].offsetx) * bl[i].cycle ) + ( bl[i].xspeed * p);
bl[i].y += bl[i].yspeed = (( stage.stageHeight/2 - bl[i].y + bl[i].offsety) * bl[i].cycle ) + ( bl[i].yspeed * p);
}
r.bitmapData.fillRect(new Rectangle(0,0,stage.stageWidth, stage.stageHeight),0x00FFFFFF);
r.bitmapData.draw(c);
r.bitmapData.threshold(r.bitmapData,new Rectangle(0,0,stage.stageWidth, stage.stageHeight),new Point(0,0),">",0x00800000,0xFFFFFFFF,0x00808080,true);
}
private function play(sndUrl:String):void {
snd = new Sound();
var context:SoundLoaderContext = new SoundLoaderContext(10, true);
var req:URLRequest = new URLRequest(sndUrl);
snd.load(req, context);
var sndChannel:SoundChannel = new SoundChannel();
sndChannel = snd.play(0, 9999);
}
private function render(e:Event):void {
bytes.clear();
SoundMixer.computeSpectrum(bytes, FFTswitch, 0);
vol = bytes.readFloat();
if(vol > 0)_reset();//A
//if(vol > 1)_reset();//A
for (var i:int = 0; i < 1; i++) {
vol = bytes.readFloat();
}
}
}
}