SoundSlime
//////////////////////////////////////
* study on wonderfl
*
* SoundSlime
* copyright 2010 glasses factory
* (http://blog.glasses-factory.net)
* @autor YAMAGUCHI EIKICHI @glasses_factory
*
* 2010 2010/08/30
*
/
///////////////////////////////////
/**
* Copyright glasses_factory ( http://wonderfl.net/user/glasses_factory )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kI4x
*/
/*//////////////////////////////////////
* study on wonderfl
*
* SoundSlime
* copyright 2010 glasses factory
* (http://blog.glasses-factory.net)
* @autor YAMAGUCHI EIKICHI @glasses_factory
*
* 2010 2010/08/30
*
/*//////////////////////////////////////
package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import frocessing.color.ColorHSV;
[SWF(frameRate=30, backgroundColor=0)]
public class Study1 extends Sprite
{
/*//////////////////////////////////////
/* public variables
/*//////////////////////////////////////
/*//////////////////////////////////////
/* getter
/*//////////////////////////////////////
/*//////////////////////////////////////
/* setter
/*//////////////////////////////////////
/*//////////////////////////////////////
/* public methods
/*//////////////////////////////////////
//Constractor
public function Study1()
{
init();
}
public function init():void
{
for( var i:int = 0; i < 10; i++ )
{
var r:Number = 200 - ( i * 19.8 );
var hsv:ColorHSV = new ColorHSV( Math.random() * 110 + 110, Math.random() * 0.7 + 0.3,1 );
var _soundWhole:SoundWhole = new SoundWhole( r, hsv.value );
_soundWhole.x = 465 * 0.5;
_soundWhole.y = 465 * 0.5;
_soundWhole.alpha = 0.5;
_soundWhole.filters = [ _blur ];
_soundWholes.push( _soundWhole );
addChild( _soundWhole );
}
addEventListener( Event.ENTER_FRAME, _enterFrameHandler );
}
/*//////////////////////////////////////
/* private methods
/*//////////////////////////////////////
private function _enterFrameHandler( e:Event ):void
{
for( var i:int = 0; i < _soundWholes.length; i++ )
{
_soundWholes[i].enterFrame();
}
}
/*//////////////////////////////////////
/* private variables
/*//////////////////////////////////////
private var _soundWholes:Array = [];
private var _blur:BlurFilter = new BlurFilter(0, 0);
}
}
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.SampleDataEvent;
import flash.filters.BlurFilter;
import flash.media.Sound;
import flash.utils.ByteArray;
class SoundWhole extends Sprite
{
public function SoundWhole( r:Number = 120, col:uint = 0xffffff )
{
_col = col;
this.filters = [ _blur ];
_sound = new Sound();
_sound.addEventListener( SampleDataEvent.SAMPLE_DATA, _sampleDataHandler );
_sound.play();
_ptVec = new Vector.<Funnel>();
for( var i:int = 0; i < PT_NUM; i++ )
{
var angle:Number = i / PT_NUM * Math.PI * 2;
var pt:Funnel = new Funnel( r * Math.cos( angle ), r * Math.sin( angle ));
_ptVec.push( pt );
}
addEventListener( MouseEvent.MOUSE_OVER, _mouseOverHandler );
addEventListener( MouseEvent.MOUSE_OUT, _mouseOutHandler );
drawCircle();
}
public function drawCircle():void
{
var g:Graphics = this.graphics;
g.clear();
g.beginFill( _col );
g.moveTo( (_ptVec[ PT_NUM - 1].x + _ptVec[0].x ) * .5, ( _ptVec[ PT_NUM - 1].y + _ptVec[0].y ) * .5 );
for( var i:int = 0; i < PT_NUM; ++i )
{
g.curveTo( _ptVec[i % PT_NUM ].x,_ptVec[ i % PT_NUM ].y,
( _ptVec[ i % PT_NUM ].x + _ptVec[ ( i + 1 ) % PT_NUM].x) * 0.5,
( _ptVec[ i % PT_NUM ].y + _ptVec[ ( i + 1 ) % PT_NUM].y) * 0.5);
}
g.endFill();
}
public function enterFrame():void
{
_mx0 = _mx;
_my0 = _my;
_mx = this.mouseX;
_my = this.mouseY;
var dmy:Number = _my - _my0;
var dmx:Number = _mx - _mx0;
_blur.blurX += ( 0 - _blur.blurX ) * 0.1;
_blur.blurY += ( 0 - _blur.blurY ) * 0.1;
_vol += ( 0 - _vol ) * 0.1 * 0.5 % 8;
this.filters = [ _blur ];
for(var i:Number = 0; i < PT_NUM; ++i)
{
var p:Funnel = _ptVec[i];
p.ax += ( p.x0 - p.x ) * _k;
p.ay += ( p.y0 - p.y ) * _k;
p.x += p.vx * t + 0.5 * p.ax * t * t;
p.y += p.vy * t + 0.5 * p.ay * t * t;
p.vx += p.ax * t;
p.vy += p.ay * t;
p.vx *= _fr;
p.vy *= _fr;
p.ax = 0;
p.ay = 0;
}
drawCircle();
}
private function reaction():void
{
for( var i:int = 0; i < PT_NUM; ++i )
{
var p:Funnel = _ptVec[i];
p.ax += ( p.x0 - p.x ) * 10;
p.ay += ( p.y0 - p.y ) * 10;
var maxDist:Number = 100;
var dx:Number = _mx - p.x;
var dy:Number = _my - p.y;
var dist:Number= Math.sqrt( dx * dx + dy * dy );
_pitch = dist * 0.008;
if(dist < maxDist)
{
var par:Number = ( maxDist- dist ) / maxDist;
p.ax += ( _mx - _mx0 ) * par * 50;
p.ay += ( _my - _my0 ) * par * 50;
}
}
}
private function _mouseOverHandler( e:MouseEvent ):void
{
_vol = 0.1;
_blur.blurX = Math.abs( 232.5 - this.mouseX ) * 0.35;
_blur.blurY = Math.abs( 232.5 - this.mouseY ) * 0.35;
reaction();
}
private function _mouseOutHandler( e:MouseEvent ):void
{
//_vol = 0;
_blur.blurX = Math.abs( 232.5 - this.mouseX ) * 0.35;
_blur.blurY = Math.abs( 232.5 - this.mouseY ) * 0.35;
reaction();
}
private function _sampleDataHandler( e:SampleDataEvent ):void
{
for( var i:int = 0; i < 2048; ++i )
{
e.data.writeFloat( Math.sin(( Number( i + e.position ) / Math.PI * _pitch ))* _vol % 8);
e.data.writeFloat( Math.sin(( Number( i + e.position ) / Math.PI * _pitch ))* _vol % 8);
}
}
//ポイントの数
private const PT_NUM:int = 20;
private var _ptVec:Vector.<Funnel>;
private var _mx:Number = 0, _my:Number = 0;
private var _mx0:Number = 0, _my0:Number = 0;
private const _k:Number = 12;
private const _fr:Number = 0.676;
private const t:Number = 0.08;
private var _col:uint;
private var _sound:Sound;
private var _vol:Number = 0;
private var _pitch:Number = 0.5;
private var _blur:BlurFilter = new BlurFilter( 0, 0 );
}
class Funnel
{
public var x:Number = 0, y:Number = 0;
public var x0:Number = 0, y0:Number = 0;
public var vx:Number = 0, vy:Number = 0;
public var ax:Number = 0, ay:Number = 0;
public function Funnel( x:Number, y:Number )
{
this.x = x; this.y = y;
this.x0 = this.x; this.y0 = this.y;
}
}