In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: Saqoosha challenge for amateurs

- - -
* 画面をクリックすると別のアナライザに変わります
* VectorにAnalyzer関数を追加するだけで動きます
* 
* ※ 別ウィンドウでサウンドを扱うSWFコンテンツを閲覧していると 動きません
* ※ 音量注意
/**
 * Copyright owrv ( http://wonderfl.net/user/owrv )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/y8HE
 */

// forked from break's forked from: Saqoosha challenge for amateurs
// forked from checkmate's Saqoosha challenge for amateurs
/*
 * - - -
 * 画面をクリックすると別のアナライザに変わります
 * VectorにAnalyzer関数を追加するだけで動きます
 * 
 * ※ 別ウィンドウでサウンドを扱うSWFコンテンツを閲覧していると 動きません
 * ※ 音量注意
 */

 package {
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.media.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
        import flash.text.TextField; 
	import flash.utils.*;
	
	import org.libspark.betweenas3.*;
	import org.libspark.betweenas3.tweens.*;
	import org.libspark.betweenas3.easing.*;
	
	import org.libspark.thread.*;

	[SWF(backgroundColor="#000000", frameRate=40)]
	public class Main extends Sprite {
		private var sound:Sound = new Sound();
		public function Main() {
			if(!Thread.isReady) Thread.initialize(new EnterFrameThreadExecutor());
			Security.loadPolicyFile("http://clockmaker.jp/crossdomain.xml");
			this.addEventListener(Event.ADDED, added);
		}
		
		public function added(e:Event = null):void {
			this.removeEventListener(Event.ADDED, added);
			//clockmakerさん ありがとうございます!
			sound.load(new URLRequest("http://clockmaker.jp/labs/081031_pv3d_visualizer/bin/music.mp3")); 
			//sound.load(new URLRequest("sound/sound.mp3")); 
			sound.addEventListener(Event.COMPLETE, init);
		}
		
		private var ac:AnalyzerController;
		public function init(e:Event = null):void {
			sound.removeEventListener(Event.COMPLETE, init);
			var soundChannel:SoundChannel = sound.play(0, 99);
			
			ac = new AnalyzerController(stage);
			ac.start();
		}
	}
}

import org.libspark.thread.Thread;
import flash.display.*;
import flash.events.*;
class AnalyzerController extends Thread {
	private var _stage:Stage;
	private var bitmap:Bitmap;
	private var bitmapData:BitmapData;
	private var soundSpectrum:SoundSpectrum;
	private var analyzer:Analyzer;
	public function AnalyzerController(stage:Stage):void {
		this._stage = stage;
		analyzer = new Analyzer(stage);
		analyzer.start();
	}
	override protected function run():void {
		event(_stage, MouseEvent.CLICK, myStart);
	}
	private function myStart(e:MouseEvent):void {
		analyzer.changeAnalyzer();
		next(run);
	}
}
import org.libspark.thread.Thread;
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.media.*;
import flash.geom.*;
import flash.filters.*;
import flash.text.*;
class Analyzer extends Thread {
	private var _stage:Stage;
	private var bitmapData:BitmapData;
	private var bitmap:Bitmap;
	private var ss:SoundSpectrum;
	//private var grad:Gradation = new Gradation(0x555555, 0x44617b, 0x6c848d, 0xb8d200, 0xffd900, 0xdb8449, 0xe45e32, 0xf08300, 0xe83929);
	private var grad:Gradation = new Gradation(0x99ff00, 0x009900, 0x0099cc, 0x0066ff , 0x9933cc, 0xff33ff, 0xff0099, 0xffff00, 0xff6600, 0xff3300);
	private var grad2:Gradation = new Gradation(0x000000, 0xff0000, 0xffffff);
	private var tf:TextField = new TextField();
	private var AV:Vector.<Function>;
	private var playingAnalyzer:uint;
	public function Analyzer(stage:Stage) {
		this._stage = stage;
		ss = new SoundSpectrum(stage);
		ss.start();
		playingAnalyzer = 0;
		bitmapData = new BitmapData(465, 465, false, 0x000000);
		bitmap = _stage.addChild(new Bitmap(bitmapData, PixelSnapping.AUTO, false)) as Bitmap;
		var pointZero:Point = new Point();
		
		AV  = new Vector.<Function>();
		/*
		 * 最終的に bitmapData で描画してください
		 * SoundSpectrum.dataAll
		 * SoundSpectrum.dataVector[i]
		 */
		AV[0] = function():void{
                    var sprite:Sprite = new Sprite();
                    var g:Graphics = sprite.graphics;
                    g.lineStyle(ss.dataAll*0.1,0xff5577,0.05);
                    g.moveTo (0, 232+ss.dataAll*-0.8);
                    g.lineTo (460, 232+ss.dataAll*0.8);
                    g.lineStyle(ss.dataAll*0.1,0xff5577,0.05);
                    g.moveTo (0, 232+ss.dataAll*0.8);
                    g.lineTo (460, 232+ss.dataAll*-0.8);
                    g.lineStyle(5,0xff5577);
                    g.drawCircle(460+ss.dataAll*-3.5, 232, ss.dataAll);
                    g.lineStyle(5,0xff3355);
                    g.drawCircle(ss.dataAll*3.5, 232, ss.dataAll);
                    g.lineStyle(3,grad.getColor(ss.dataAll / 350));
                    g.drawCircle(232, 232, ss.dataAll*1.5);
                    g.endFill();
                    bitmapData.lock();
                    bitmapData.applyFilter(bitmapData, bitmapData.rect, pointZero, new BlurFilter(6,5,2.));
                    bitmapData.draw(sprite,null,null,"add");
                    bitmapData.unlock();
                };
		
		AV[1] = function():void{
                    var m:Matrix = new Matrix();
                        m.translate(0, 215+ss.dataAll*-0.5);
                        m.scale(2,2);
                    var sprite:Sprite = new Sprite();
                    var g:Graphics = sprite.graphics;
                        g.lineStyle (1, 0xffffff, 1.0);
                        g.beginFill (0xffffff, 1.0);
                        g.drawRect (30,400+ss.dataAll*-0.5,50,400+ss.dataAll*2 );
                    bitmapData.lock();
                    bitmapData.applyFilter(bitmapData, bitmapData.rect, pointZero, new BlurFilter(6,5,2.));
                    bitmapData.draw(sprite,null,null,"add");
                    bitmapData.unlock();
                    var tf:TextField = new TextField();
                    tf.text = "\(^o^)/";
                    tf.textColor = 0xfff0000;
                    bitmapData.applyFilter(bitmapData, bitmapData.rect, pointZero, new BlurFilter(10,10,5));
                    bitmapData.draw(tf,m);

                   var tf2:TextField = new TextField()
                   tf2.text = String(ss.dataAll);
                   tf2.textColor = grad.getColor(ss.dataAll / 400);
                   bitmapData.lock();
                   bitmapData.draw(tf2, new Matrix(10,0,0,5,220,220));
                   bitmapData.unlock();

                   var tf3:TextField = new TextField()
                   tf3.text = String("OwataAnalyzer");
                   tf3.textColor = grad.getColor(0xffffff);
                   bitmapData.lock();
                   bitmapData.draw(tf3,new Matrix(15,0,0,5,10,20));
                   bitmapData.unlock();
                };
                

	}
	override protected function run():void {
		event(_stage, Event.ENTER_FRAME, analyzerRun);
	}
	private function analyzerRun(e:Event):void {
		AV[playingAnalyzer].call();
		next(run);
	}
	public function changeAnalyzer():void {
		playingAnalyzer  = Math.random() * AV.length;
		return;
	}
}

import org.libspark.thread.Thread;
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.media.*;
import flash.utils.ByteArray;
import flash.geom.Rectangle;
import flash.events.Event;
import flash.media.SoundMixer;
class SoundSpectrum extends Thread {
	private var _stage:Stage;
	public function SoundSpectrum(stage:Stage):void {
		this._stage = stage;
	}
	override protected function run():void {
		event(_stage, Event.ENTER_FRAME, soundSpectrumRefresh);
	}
	
	public var dataAll:uint;
	public var dataVector:Vector.<Number>;
	private function soundSpectrumRefresh(e:Event):void {
		var bytes: ByteArray = new ByteArray();
		SoundMixer.computeSpectrum(bytes, true, 0);
		
		dataAll = new uint();
		dataVector = new Vector.<Number>();
		
		for( var i: int = 0 ; i < 256 ; i++ ) {
			var value:Number = bytes.readFloat();
			var smooth:Number;
			if( i == 0 ) smooth = value;
			else smooth += ( value - smooth ) / 8;
			var height:Number = smooth * 0xa;
			dataAll += height;
			
			dataVector.push(300 - height * 0xf);
		}
		next(run);
	}
}

import frocessing.color.ColorLerp;
import org.libspark.betweenas3.core.easing.IEasing;
import org.libspark.betweenas3.easing.Linear;

class Gradation {
    private var _colors:Array;
    private var _easing:IEasing;
    
    public function Gradation(...args) {
        _colors = args.concat();
        _easing = Linear.linear;
    }
    
    public function setEasing(easing:IEasing):void {
        _easing = easing;
    }
    
    public function getColor(position:Number):uint {
        position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
        var idx:int = position;
        var alpha:Number = _easing.calculate(position - idx, 0, 1, 1);
        return (alpha == 0)?_colors[idx]:ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
    }
}