forked from: variousParticles from: nengafl

by kanatara
タイトル:回転する各種パーテイクル
♥0 | Line 103 | Modified 2010-08-15 20:21:20 | MIT License
play

ActionScript3 source code

/**
 * Copyright kanatara ( http://wonderfl.net/user/kanatara )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/55FR
 */

// forked from cybernet's variousParticles from: nengafl
// タイトル:回転する各種パーテイクル
package {
    import flash.accessibility.Accessibility;
    import flash.events.MouseEvent;
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.display.Sprite;
    
    import flash.display.*;
    
        [SWF( width="465", height="465", backgroundColor="0x000000", frameRate="30" )] 
    public class variousParticles extends Sprite {
                    
        public function variousParticles() {
            /*
              これからActionScript3.0を始める人が、あなたの作品を通してFlashの楽しさを知り
              ASの世界に足を踏み入れるきっかけになるような課題作品をつくってください!

              一番FORKされた方に、wonderflからお年玉、なんと現金10万円を贈呈します! 

             単純に数字を変えるだけで、面白い動きがでるのもOK! 
             真面目な課題ももちろんOK!
            「面白いAS 」の定義はみなさんにおまかせします!
             Flash仲間が増え、Flash界が盛り上がるような作品の応募をお待ちしております。
            */
            /*
            var nengaText:String = "<font color='#FF0000'><b>これからActionScript3.0を始める人が、あなたの作品を通してFlashの楽しさを知り<br>" + 
              "ASの世界に足を踏み入れるきっかけになるような課題作品をつくってください!<br><br>" +
              "一番FORKされた方に、wonderflからお年玉、なんと現金10万円を贈呈します! <br><br>" +
              "単純に数字を変えるだけで、面白い動きがでるのもOK! <br>" +
              "真面目な課題ももちろんOK! <br>" +
              "「面白いAS 」の定義はみなさんにおまかせします!<br>" +
              "Flash仲間が増え、Flash界が盛り上がるような作品の応募をお待ちしております。</b></font>"; 

            var format:TextFormat = new TextFormat();
            format.size = 12;
            format.color = 0xFF0000;
            
            var nengaTextBox:TextField = new TextField();
            nengaTextBox.width = 465; 
               nengaTextBox.height = 200; 
               nengaTextBox..y = 100;
            nengaTextBox.multiline = true; 
            nengaTextBox.wordWrap = true; 
            nengaTextBox.border   = false;
            nengaTextBox.defaultTextFormat = format;
            nengaTextBox.htmlText = nengaText;
            
             this.addChild(nengaTextBox);
             */
             
             var tf:TextField = new TextField();
             tf.x = 0;
             tf.y = 20;
             tf.width = 230;
             tf.height = 80;
             tf.textColor = 0x999999;
             tf.text = "画面上でマウスをクリックしてください。\n"+
             "楕円や長方形がクリックの度に1個現れて、\n"+
             "ランダムに回転し始めます。\n" +
             "放置しておくと図形は1個づつ消えていきます。";
             stage.addChild(tf); 
             stage.addEventListener(MouseEvent.CLICK,onClick,false,0,true);
                    
        }//function variousParticles
        
        private function onClick(evt:MouseEvent): void {
                var zk1:Kaiten = new Kaiten(
                    200,
                    200,
                    50+100*Math.random(),
                    2.0*(0.5-Math.random()),
                    0.1,
                    1.8*Math.random(),
                    Math.PI/6*(0.2+0.8*Math.random())
            );
            addChild(zk1);
        }//function onClick                                
    }//function variousParticles
  }//class variousParticles


import flash.display.*;

class Ball extends Sprite {
    public function Ball(){
        var mytama:Sprite = new Sprite();
        var mt:Graphics = mytama.graphics;
        
        mt.lineStyle();
        mt.beginFill(0xFF0000*Math.random(), 0.4+ 0.6*Math.random());
        var pro:Number = Math.random();
        if(pro < 0.5){
            mt.drawEllipse(0,0,2+38*Math.random(),2+38*Math.random());
        }
        else {
            mt.drawRect(0,0,2+38*Math.random(),2+38*Math.random());
        }
        mt.endFill();
        addChild(mytama);
    }//function Ball
}//class Ball    

import flash.display.*;
import flash.events.*;

class Kaiten extends Sprite {
    private var t:Number = 0;
    private var tp:Number;
    private var thp:Number;
    private var L:Number = 1;
    private var rp:Number;
    private var xp:Number;
    private var yp:Number;
    private var w:Number = 0.5;
    private var ball:Sprite = new Ball();
    private var bit:Number = 0;
    
    public function Kaiten(
          x0:Number,
          y0:Number,
          L0:Number,
          w0:Number,
          t0:Number,
          ratio:Number,
          th:Number
     ){
         L = L0;
         w = w0;
         xp = x0;
         yp = y0;
         tp = t0;
         rp = ratio;
         thp = th;
         
         ball.x = xp;
         ball.y = yp;
         addChild(ball);
         
         addEventListener(Event.ENTER_FRAME,onRun,false,0,true);
     
     }//func Kaiten
     
     private function onRun(e:Event):void {
         t += 0.1;
         var xx:Number = xp + rp*L*Math.sin(w*t);
         var yy:Number = yp + L*Math.cos(w*t);
         
         ball.x = (xx-200)*Math.cos(thp)-(yy-200)*Math.sin(thp) + 200;
         ball.y = (xx-200)*Math.sin(thp)-(yy-200)*Math.cos(thp) + 200;
         
         if(t > 50){
             removeEventListener(Event.ENTER_FRAME,onRun);
             parent.removeChild(this);
         }
     }//func onRun
} //Class Kaiten