Sound of Hydrogen
inspired by tutorial from here:
http://www.youtube.com/watch?v=IhvW8yZdE5A
/**
* Copyright Jacky.Riawan ( http://wonderfl.net/user/Jacky.Riawan )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aw5U
*/
package
{
import flash.display.Sprite;
import flash.events.SampleDataEvent;
import flash.media.Sound;
/**
* ...
*inspired by tutorial from here: http://www.youtube.com/watch?v=IhvW8yZdE5A
*http://en.wikipedia.org/wiki/Rydberg_formula
* @author Jacky Riawan
*/
[SWF(width="465",height="465")]
public class Main extends Sprite
{
private var position:int=0;
public function Main()
{
var sound:Sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
sound.play();
}
private function onSampleData(e:SampleDataEvent):void {
graphics.clear();
graphics.lineStyle(1);
graphics.lineTo(0, stage.stageHeight / 2);
for(var i:int = 0; i < 2048; i++)
{
position++;
var t:Number = position / 44100;
var sample:Number = 0;
for (var n:int = 2; n <= 10;n++){
sample+= Math.sin((1-1/Math.pow(n,2))*2*Math.PI*t*440)+Math.sin((1/4-1/Math.pow(n+1,2))*2*Math.PI*t*440)
}
graphics.lineTo(i * stage.stageWidth/2048, stage.stageHeight / 2+sample*stage.stageHeight*.01);
e.data.writeFloat(sample);
e.data.writeFloat(sample);
}
}
}
}