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

AS3 spiral line

何か綺麗な線を描いてみたかった
Get Adobe Flash player
by cheesepie 25 Mar 2009
/**
 * 何か綺麗な線を描いてみたかった
 */
package {
  import flash.display.Sprite;
  import flash.display.Graphics;
  import flash.display.Stage;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.events.Event;

  public class FlashTest extends Sprite {
    private var STAGE:Stage;
    private var angle:Number = 0.0;
    private var speed:Number = 0.01;
    private var radius:Number = 130.0;
    private var sx:Number, sy:Number;
    private var hh:int = 0;
    private var color:uint;
    private var g:Graphics;

    public function FlashTest() {
      STAGE = this.stage;
      STAGE.align = StageAlign.TOP_LEFT;
      STAGE.scaleMode = StageScaleMode.SHOW_ALL;
      init();
    }
    
    private function init():void {
      g = this.graphics;
      g.clear();
      swap(5, 2);
      addEventListener(Event.ENTER_FRAME, draw);
    }

    private function draw(event:Event):void {
      var sinv:Number, cosv:Number;
      var _x1:Number, _y1:Number, _x2:Number, _y2:Number;

      angle += speed;
      sinv = Math.sin(angle / sy);
      cosv = Math.cos(angle);
      _x1 = width / 2 + (cosv * radius);
      _y1 = height / 2 + (sinv * radius);
      _x2 = _x1 + Math.cos(sx * angle) * radius;
      _y2 = _y1 + Math.sin(sy * angle) * radius;

      g.beginFill(0xffffff);
      g.drawEllipse(_x2, _y2, 1, 1);

      if(155 > hh) {
        hh++;
      } else {
        hh = 0;
      }
      color = 0 << 16 | 0 << 8 | (100 + hh);
      g.lineStyle(1, Number("0x" + color.toString(16)));
      g.moveTo(_x1, _y1);
      g.lineTo(_x2, _y2);
      g.endFill();      
    }

    private function swap(_sx:Number, _sy:Number):void {
      sy = _sx;
      sx = _sy;
    }
  }
}