forked from: Space Butterfly Sound
@author itoz ( http://www.romatica.com/ )
フォーク元 [butterfly sound ] http://wonderfl.net/c/8xSc
- 音はTsabeat より拝借
- http://www.ektoplazm.com/2010/highpersonic-whomen-alternative-energysource
/**
* Copyright makc3d ( http://wonderfl.net/user/makc3d )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rvz4
*/
// forked from romatica's Space Butterfly Sound
// forked from rettuce's Butterfly Sound
/**
* @author itoz ( http://www.romatica.com/ )
* フォーク元 [butterfly sound ] http://wonderfl.net/c/8xSc
*
* - 音はTsabeat より拝借
* - http://www.ektoplazm.com/2010/highpersonic-whomen-alternative-energysource
*/
package
{
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.display.Shape;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.media.SoundMixer;
import flash.utils.ByteArray;
import flash.media.SoundLoaderContext;
public class SpaceButterflySound extends MovieClip
{
private var _bg:Sprite;
private var _sound:Sound;
private var _channel:SoundChannel;
private var _byteArray:ByteArray;
private var _rectArray1:Vector.<Rect>;
private var _rectArray2 : Vector.<Rect>;
private var _radius:Number;
private var _flg:Boolean = true;
public static var _bold : Number = 10 ;
private var _keisu : Number = 5;
private var _count : int;
private var _star : StarDust;
private var _wrap : Sprite;
private var _wrap2 : Sprite;
private var sw : int;
private var sh : int;
private var scx : Number;
private var scy : Number;
public function SpaceButterflySound()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init );
}
private function init(e:Event = null ):void
{
removeEventListener(Event.ADDED_TO_STAGE, init );
sw =stage.stageWidth;
sh =stage.stageHeight;
scx=sw/2;
scy=sh/2;
_byteArray = new ByteArray();
// _rectArray1 = _rectArray2 = new Vector.<Shape>();
_count = 10;
_radius = stage.stageHeight / 2.5;
_bg = addChild( new Sprite() ) as Sprite;
_bg.graphics.beginFill(0x0);
_bg.graphics.drawRect(0,0,468,468);
_bg.graphics.endFill();
_star = addChild( new StarDust() ) as StarDust;
_star.create(150);
_wrap =addChild(new Sprite) as Sprite;
_wrap.x =scx;
_wrap.y =scy;
_wrap.filters = [ new GlowFilter (0xFF1F7FFF, 1, 16, 16) ];
_wrap.blendMode = "add";
_wrap.transform.colorTransform = new ColorTransform (10, 5, 1);
_wrap2 =addChild(new Sprite) as Sprite;
_wrap2.x =scx;
_wrap2.y = scy;
_wrap2.filters = [ new BlurFilter (8, 8, 1) ];
_wrap2.blendMode = "difference";
_rectArray1 = soundRectSet( -_bold * 1.3, _wrap );
_rectArray2 = soundRectSet( -_bold * 4, _wrap2 );
soundSet();
addEventListener(Event.ENTER_FRAME, update );
}
private function soundRectSet(yy:Number,_wrap:Sprite):Vector.<Rect>
{
var vec:Vector.<Rect> = new Vector.<Rect>();
for (var i:int = 0; i < 1024; i++) {
var rect:Rect = new Rect (yy); _wrap.addChild (rect);
rect.alpha = 0.3;
rect.width = sw / 256;
rect.height = sh / 512;
var p:Point = Point.polar(0,(((360 / 1024) * i+90)* Math.PI / 180));
rect.x = p.x;
rect.y = p.y;
rect.rotation = (360 / 1024) * i ;
rect.scaleY =Math.random()*2+0.75;
vec.push(rect);
}
return vec;
}
private function soundSet():void
{
_sound = new Sound();
_sound.addEventListener(Event.COMPLETE, onSoundLoaded,false,0,true);
_sound.load(new URLRequest("http://rettuce.com/material/mp3/PieceOfCake.mp3"),
new SoundLoaderContext(1000, true));
_channel = _sound.play( 0, 1 );
}
private function onSoundLoaded(event : Event) : void
{
_sound.removeEventListener(Event.COMPLETE, onSoundLoaded);
//
}
private function update(e : Event) : void
{
soundAnimation( _rectArray1, _flg );
soundAnimation( _rectArray2, !_flg );
}
private function soundAnimation(arr : Vector.<Rect>, flag : Boolean) : void
{
_wrap.rotation++; _wrap2.rotation--;
SoundMixer.computeSpectrum( _byteArray, flag, _count );
for (var i : int = 0; i < 512; i += 2) {
var n : int = 1023 - i;
var numL:Number = _byteArray.readFloat () * _keisu +1.4;
numL *= 5
arr[i].rect.y = numL;
arr[i+1].rect.y = numL;
arr[n].rect.y = numL;
arr[n-1].rect.y = numL;
}
}
public function get _sh() : int {
return sh;
}
public function set _sh(sh : int) : void {
this.sh = sh;
}
}
}
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
class Rect extends Sprite {
public var rect:Shape;
public function Rect (yy : Number) {
super ();
mouseEnabled = false;
mouseChildren = false;
var _bold:Number = SpaceButterflySound._bold;
rect = new Shape();
rect.graphics.beginFill( 0xff * Math.random() * 0xff * Math.random() );
rect.graphics.drawRect( 0, yy, _bold, _bold );
rect.graphics.endFill();
addChild (rect);
}
}
class StarDust extends Sprite
{
private const _fl : int = 5000;
private var _vpx : int;
private var _vpy : int;
private var _starVec : Vector.<Star>
public function StarDust()
{
setVp();
}
public function create(allNum : int) : void
{
_starVec = new Vector.<Star>();
for (var i : int = 0; i < allNum; i++) {
var s : Star = addChild( new Star() ) as Star;
s.graphics.beginFill( 0xaaaaaa );
s.graphics.drawCircle( 0, 0, 1.5);
s.setPosition(Math.floor( Math.random() * 1000 - Math.random() * 1500 )
, Math.floor( Math.random() * 1000 - Math.random() * 500 )
, Math.floor( Math.random() * 8000 - Math.random() * 16000 ));
s._speed = Math.floor( Math.random() * 50+100 );
_starVec.push(s);
}
addEventListener( Event.ENTER_FRAME, moveStars );
}
private function moveStars(e : Event) : void
{
var i:int =0;
var max:int = _starVec.length;
for ( i = 0; i < max; i++) {
var s : Star = _starVec[i] as Star;
s.zz -= s._speed;
s.rota();
if (s.zz <= -_fl) {
s.setPosition( s.xx,s.yy,16000 );
s._speed = Math.floor( Math.random() * 50+100 );
} else {
var scale : Number = _fl / (_fl + s.zz);
s.scaleX = s.scaleY = scale * 1.1;
s.x = _vpx + s.xx * scale;
s.y = _vpy + s.yy * scale;
}
}
}
private function setVp() : void
{
_vpx = 468 / 2;
_vpy = 468 / 2;
}
}
import flash.display.Shape;
class Star extends Shape
{
public var xx : Number;
public var yy : Number;
public var zz : Number;
public var _speed : Number;
private var leng : Number;
private var radian : Number;
public function Star(){}
public function setPosition(_xx : Number , _yy : Number , _zz : Number ) : void
{
xx = _xx;
yy = _yy;
zz = _zz;
radian = Math.atan2( xx, yy );
}
public function rota() : void
{
leng = Math.sqrt(xx*xx +yy*yy);
radian +=_speed/5000;
xx = Math.sin(radian)*leng;
yy = Math.cos(radian)*leng;
}
}