본문 바로가기

AS3/ActionScript

쿡북 lineTo를 이용한 랜덤 선생성


package {
 
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.events.MouseEvent;
 import flash.text.TextField;

 public class ExampleApplication extends Sprite
 {
  private var _sprite:Sprite;
  private var _textField:TextField;
  
  public function ExampleApplication()
  {
   _sprite = new Sprite();
   addChild(_sprite);
   _sprite.graphics.beginFill( 0xffffff);
   _sprite.graphics.drawRect(260, 180, 50, 50);
   _sprite.graphics.endFill();
   
   _textField = new TextField();
   addChild(_textField);
   
   _textField.x = 270;
   _textField.y = 195;
   _textField.text = "stop";
   
   
   graphics.lineStyle( 1, 0, 1 );
   addEventListener(Event.ENTER_FRAME, onEnter);
   _textField.addEventListener(MouseEvent.CLICK, onClick);
  }
  
  private function onEnter( e:Event ):void
  {
   graphics.lineTo( Math.random() * 540, Math.random() * 400 )
  }
  private function onClick( e:MouseEvent ):void
  {
   removeEventListener( Event.ENTER_FRAME, onEnter );
  }
 }
}


lineTo와 랜덤 함수를 이용한 무한 선긋기.....계속 두면 cpu가 싫어할듯..
재미있는 작업이 가능할거 같다~