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: MeloBall.ver3.4

SiONのインポート
Get Adobe Flash player
by sir4shumman 09 Feb 2010
/**
 * Copyright sir4shumman ( http://wonderfl.net/user/sir4shumman )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qwXX
 */

package {
    import flash.display.Sprite;
    import flash.events.*;
     //SiONのインポート
	import org.si.sion.*;
	import org.si.sion.events.*;
	import org.si.sion.effector.*;
	import org.si.sion.utils.SiONPresetVoice;
    
    
    [SWF(backgroundColor="#FFFFFF",width='600',height='800', frameRate=60)]
    
    public class DrawCircle extends Sprite {
    	
    		private var myStage:Sprite = new Sprite();

 		private var bounce:Number = -1.0;
    		// driver
		private var driver:SiONDriver = new SiONDriver();
		// preset voice
		private var presetVoice:SiONPresetVoice = new SiONPresetVoice(); 
    		//MML
        public var rythmLoop:SiONData;
    		//String
    		private	var Melody:String;
    		
    		private var Balls:Array = new Array();
    		private var Num:uint = 0;
    		private var ball:Ball;
    		private var MouseSw:Boolean = false;//
    		private var OverSw:Boolean = false;//
		//押下時マウスの座標
		private var pre_mx:Number;
		private var pre_my:Number;
		
		//マウスを放したときの座標
		private var mx:Number;
		private var my:Number;

		//ボールのアルファ値
		private var xalpha:Number = 0.7;
		//半径
		private var radius:Number = 15; //半径はみんな同じ。つまりmassも同じで属性的に全く同じ

		//コンストラクタ
        public function DrawCircle(){        		
        		Back();
        		PlayBt();
        		Stage();
        		driver.play();
        		myStage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);
        		
        } 
        private function Stage():void{
        			myStage.graphics.beginFill(0,0.05);
				myStage.graphics.drawRect(0,0,600,600);
				myStage.graphics.endFill();
				myStage.width = 600;
				myStage.height = 600;
				addChild(myStage);

        	}  
        private function Back():void{
			for(var i:uint;i<8;i++){
				var back:Sprite = new Sprite();
				back.graphics.beginFill(0,0.05);
				back.graphics.drawRect(0,80*i,600,40);
				back.graphics.endFill();
				addChild(back);
			}
        	}
        	private function PlayBt():void{
        		
        			var PlayBt:Sprite = new Sprite();//デザインはFlashで作る

				PlayBt.graphics.beginFill(0,1);
				PlayBt.graphics.drawRect(100,650,60,40);
				PlayBt.graphics.endFill();
				addChild(PlayBt);
				PlayBt.buttonMode = true;
				PlayBt.addEventListener(MouseEvent.MOUSE_DOWN,onPlayBt);

        	}         
        private function MouseDown(event:MouseEvent):void{
        		if(OverSw == false){
        			MouseSw = true;
	        		var cx:Number = myStage.stage.mouseX;
	        		var cy:Number = myStage.stage.mouseY;
	        		pre_mx = cx;
	        		pre_my = cy;
	        		trace(cx);
	        		trace(cy);
	        		MakeBall(cx,cy);
	        		myStage.addEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
        		}    		
        	}
        		
        	private function MouseMove(event:MouseEvent):void{
        		//for(var i:uint=0;i<Num;i++){

	        		var dx:Number = ball.x - stage.mouseX;
				var dy:Number = ball.y - stage.mouseY;
	        		var radius:Number = Math.sqrt(dx*dx + dy*dy);
	        		if(radius<10){
	        			ball.width = 20;
					ball.height = 20;
	        			}
	        		else if(radius<30){
					ball.width = 60;
					ball.height = 60;
	        		}
	        		else if(radius<50){
					ball.width = 100;
					ball.height = 100;
	        		}
	        		else if(radius<100){
					ball.width = 200;
					ball.height = 200;
	        		}



        		//} 
        		myStage.addEventListener(MouseEvent.MOUSE_UP, MouseUp);       		
        	}
        	private function MouseUp(event:MouseEvent):void{
        		MouseSw = false;
        		myStage.removeEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
        		if(ball.width==20){ball.NL = 1;ball.noteL="16";}//*noteOnでは16分音符が何個分かで音の長さを制御する.この値はカウンタにも使う
        		else if(ball.width==60){ball.NL =4;ball.noteL="8";}//16*4
        		else if(ball.width==100){ball.NL = 8;ball.noteL="4";}//1/16*8
        		else if(ball.width==200){ball.NL = 16;ball.noteL="1";}//1/16*16
        		Sichou();       		


        	}
        private function MakeBall(cx:Number,cy:Number):void{
        		ball = new Ball(20,Math.random()*0xffffff,0.5);
        		myStage.addChild(ball);
        		ball.x = cx;
        		ball.y = cy;
        		Num += 1;
        		ball.buttonMode = true;
        		ball.addEventListener(MouseEvent.MOUSE_OVER,MouseOverd);
        		ball.addEventListener(MouseEvent.MOUSE_OUT,MouseOut);
        		ball.addEventListener(MouseEvent.CLICK,DClicked);
        		Balls.push(ball);
        		
        }
        private function DClicked(event:MouseEvent):void{
        		var target:Ball = event.currentTarget as Ball;
        		ball = event.currentTarget as Ball;
			myStage.removeChild(target);
        }
        
        private function MouseOverd(event:MouseEvent):void{
        		OverSw = true;
        }
        
        private function MouseOut(event:MouseEvent):void{
        		OverSw = false;
        }
        private function Sichou():void{
        		var by:Number = ball.y//現在(最新)のボールのy座標を利用する
        		
        		if(by<40){driver.noteOn(84,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o6c"}//o6C
        		else if(by<80){driver.noteOn(83,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o5b"}//o5B
        		else if(by<120){driver.noteOn(81,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o5a"}//o5A
        		else if(by<160){driver.noteOn(79,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o5g"}//o5G
        		else if(by<200){driver.noteOn(77,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o5f"}//o5F
        		else if(by<240){driver.noteOn(76,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o5e"}//o5E
        		else if(by<280){driver.noteOn(74,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o5d"}//o5D
        		else if(by<320){driver.noteOn(72,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o5c"}//o5C
        		else if(by<360){driver.noteOn(71,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o4b"}//o4B
        		else if(by<400){driver.noteOn(69,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o4a"}//o4A
        		else if(by<440){driver.noteOn(67,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o4g"}//o4G
        		else if(by<480){driver.noteOn(65,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o4f"}//o4F
        		else if(by<520){driver.noteOn(64,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o4e"}//o4E
        		else if(by<560){driver.noteOn(62,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o4d"}//o4D
        		else if(by<600){driver.noteOn(60,null,ball.NL,0,0,0,0,0,0,true); ball.note = "o4c"}//o4C
       	}        	
        	private function onPlayBt(event:MouseEvent):void{
        		Num = myStage.numChildren;
        		var melody:String = "t120;";
        		var meloBall:Ball;
        		for(var i:uint=0;i<Num;i++){
        			Balls[i] = myStage.getChildAt(i);        			      			
        		}
        		Play();
 			//stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			//driver.noteOn(60,null,1,0,0,0,0,0,0,true);
        	}
        	private function Play():void{
        		var n:uint = myStage.numChildren;
        		var meloBall:Ball;
        		for(var i:uint=0;i<n;i++){
        			Balls[i] = myStage.getChildAt(i);        			      			
        		}		
			//driver.noteOn(40,null,1,0,0,0,0,0,0,true);
			CompileMML();
        	}
        	private function onEnterFrame(event:Event):void {
        		 for (var i:uint = 0; i<Num; i++) {
			  var b:Ball = Balls[i];
			  b.x += b.vx;
			  b.y += b.vy;
			  checkWalls(b);
			 }
			}        	
        	private function checkWalls(b:Ball):void {
        		 if (b.x + b.width/2 > 600) {
        		 	 b.x = 600 - b.width/2;
        		 	 b.vx *= bounce;
        		 }
        		 else if (b.x - b.width/2 < 0) {
			  b.x = b.width/2;
			  b.vx *= bounce;
			 }
			  
			 if (b.y + b.height/2 > 600) {
			  b.y = 600 - b.height/2;
			  b.vy *= bounce;
			  }
			 else if (b.y - b.height/2 < 0) {
			  b.y = b.height/2;
			  b.vy *= bounce;
			 }        		 
        	}
        	/*このあたりからMMLの作成関係*/
        	private function CompileMML():void {
        		var target:Ball;
        		var mml:String = "#EFFECT1{lf3000delay300,32,1};t120;";
        		mml += "%6@0o3l8";
        		for(var i:uint=0;i<Num;i++){
        			target = Balls[i];
        			mml += target.noteL;
        			mml += target.note; 			      			
        		}
			mml += ";";
        		mml += "%6@1v8l8o3cccb16_ccc16c16>b16a16g16;";   
        		rythmLoop = driver.compile(mml);
        		rythmLoop.setVoice(0, presetVoice["valsound.piano6"]);
        		rythmLoop.setVoice(1, presetVoice["valsound.bass2"]);
        		driver.play(rythmLoop);  
			/*mml += "%6@0o3l8$c2cc.c.; %6@1o3$rcrc; %6@2v8l16$[crccrrcc]; %6@3v8o3$[rc8r8];";
			mml += "%6@4v8l16o3$aa<a8>a<ga>ararara<e8>;";
            rythmLoop = driver.compile(mml);
            // set voices of "%6@0-4" from preset 
			rythmLoop.setVoice(0, presetVoice["valsound.percus1"]);
			rythmLoop.setVoice(1, presetVoice["valsound.percus28"]);
			rythmLoop.setVoice(2, presetVoice["valsound.percus17"]);
			rythmLoop.setVoice(3, presetVoice["valsound.percus23"]);
			rythmLoop.setVoice(4, presetVoice["valsound.bass3"]);
			driver.play(rythmLoop);    */   		
        	}

        		 	 	      		

    }     	
		


    		
}

/*-------------------------------------
			パッケージ外クラス定義
 ---------------------------------------*/

import flash.display.*;
import flash.events.*;
class Ball extends Sprite
{
	private var velocity:Number = 1;//ここに速度を入れる
	public var sw:Boolean = false;
	public var vx:Number =(Math.random() * 10 - 5) * velocity;
	public var vy:Number =(Math.random() * 10 - 5) * velocity;
	public var NL:uint = 1;//カウンタ用の長さ、およびnoteOn時の長さ
	public var note:String;//MMLで使うノート文字
	public var noteL:String = "16";//MMLで使う音の長さ。デフォルト値の16は16分音符
	
    //x
    function Ball(rd:Number,cl:Number,al:Number){
		this.width = 20;
    		this.height = 20;    				
        this.graphics.beginFill(cl,al);
        this.graphics.drawCircle(0, 0, 20);
        //this.graphics.endFill();これするとあとで色換えられない?

        
    }
}