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

Morphing Clifford

// forked from kojimajunya's CliffordAttractor
// write as3 code here..
package{

  import flash.display.MovieClip;
  import flash.display.BitmapData;
  import flash.display.Bitmap;
  import flash.geom.Rectangle;
  import flash.geom.Point;
  import flash.filters.BlurFilter;
  import flash.geom.ColorTransform;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.text.TextField;
	
  [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]

  public class Main extends MovieClip{

  private var tf:TextField;
  private var a0:Number;
  private var a1:Number;
  private var a2:Number;
  private var a3:Number;
	
  private var tonedown:ColorTransform;
  private var filter:BlurFilter;
  private var rect:Rectangle;
  private var pt:Point;

  private var objNum:int = 10000;
  private var objAry:Array;		

  private var bmd:BitmapData;
  private var bmp:Bitmap;
  private var color:Number = 0xCCFF9922;
  private var cRed:int=0xFF,
              cGrn:int=0x99,
              cBlu:int=0x22;
  private var changeRate:Number;

    public function Main(){

    color = 0xCCFCA852;

      tf = new TextField();
      tf.textColor = 0xFFFFFF;
      tf.text = "Click -> reset!";
      objAry = new Array();

      tonedown = new ColorTransform(1, 0.99, 0.99, 0.99);
      filter = new BlurFilter(1.5, 1.5, 1);
      rect = new Rectangle(0, 0, 465, 465)
      pt = new Point(0, 0)

      bmd = new BitmapData(465, 465, true, 0xFF000000);
      bmp = new Bitmap(bmd);
////////////////////////////////////////////////////
//////////////////////////////////////////////////constants
      objNum = 7000;
      Particle.jitter = 729;
      changeRate=.4;
///////////////////////////////////////////////////
/////////////////////////////////////////////////////
      for(var i:int = 0; i<objNum; i++){
        var p:Particle = new Particle(bmd);
        objAry.push(p);
      }

      addChild(bmp);
      addChild(tf);
      stage.addEventListener(MouseEvent.MOUSE_DOWN, init);
      //stage.addEventListener(MouseEvent.DOUBLE_CLICK, init);

      init();
    }
	
    private function init(e:MouseEvent = null):void{

      removeEventListener(Event.ENTER_FRAME, update);
      bmd.fillRect(rect, 0xFF000000);
      
      a0 = Math.random()*8-4;
      a1 = Math.random()*8-4;
      a2 = Math.random()*8-4;
      a3 = Math.random()*4-2;
      
      cRed = Math.round(Math.random()*400-200);
      cGrn = Math.round(Math.random()*400-200);
      cBlu = Math.round(Math.random()*400-200);

      setall(a0,a1,a2,a3);
      
      shift();

      addEventListener(Event.ENTER_FRAME, update);			
    }
    
    private function shift(e:MouseEvent = null):void {
        
      a0 = a0 + Math.random()/34;
      if(a0>4)a0-=8;
      a1 = a1 + Math.random()/35;
      if(a1>4)a1-=8;
      a2 = a2 + Math.random()/37;
      if(a2>4)a2-=8;
      a3 = a3 + Math.random()/39;
      if(a3>2)a3-=4;

//      setall(a0, a1, a2, a3);
      setall(Math.abs(a0), Math.abs(a1), Math.abs(a2), Math.abs(a3));
      
      do 
      {
        cRed += Math.round(Math.random()*6+1);
        if(cRed>255)cRed=-511;
        cGrn += Math.round(Math.random()*5);
        if(cGrn>255)cGrn=-511;
        cBlu += Math.round(Math.random()*3);
        if(cBlu>255)cBlu=-511;
      }
      while(Math.abs(cRed) + Math.abs(cBlu) + Math.abs(cGrn) < 24);
      
      color = 0xFF000000
            | (((cRed>0)?cRed:-cRed) << 16)
            | (((cGrn>0)?cGrn:-cGrn) << 8)
            | (((cBlu>0)?cBlu:-cBlu) );

    }
    
    private function setall(a0:Number, a1:Number, a2:Number, a3:Number):void {
      for(var i:int = 0; i<objNum; i++){
        objAry[i].init(a0, a1, a2, a3);
      }
        }

    private function update(e:Event = null):void{
        
      for(var sm:int = 2; sm>0; --sm) {
      bmd.lock();

      bmd.applyFilter(bmd, rect, pt, filter);
      bmd.colorTransform(rect, tonedown);

      for(var i:int = 0; i<objNum; i++){
        objAry[i].update(color);
      }      

      bmd.unlock();
      }
      shift();
      //if(Math.random()<changeRate)shift();
    }
  }
}

import flash.display.BitmapData;

class Particle{
  private var x:Number, y:Number;
  private var nx:Number, ny:Number;
  private var A0:Number, A1:Number, A2:Number, A3:Number;
  private var drawScale:Number;
  private var bmd:BitmapData;
  
  private var dx:Number, dy:Number;
  public static var jitter:int=100;
  private static var jittercount:int=100;
	
  public function Particle(_bmd:BitmapData){
    bmd = _bmd;
    drawScale = 0.25;
    RandomizeMe();
    dx=x;dy=y;
  }
  
  public function RandomizeMe():void {
    x = Math.random()*8-4;
    y = Math.random()*8-4;
//    dx=x;dy=y;
  }
	
  public function init(a0:Number, a1:Number, a2:Number, a3:Number):void{

    A0 = a0;
    A1 = a1;
    A2 = a2;
    A3 = a3;
  }
	
  public function update(clr:Number):void{
      var settle:int = 1;
      --jittercount;
    if(Math.random()<.0001)jittercount/=2;
    if(jittercount<0){
      jittercount=jitter;
      RandomizeMe();
      settle = 3;
    }
    do
    {
    nx = Math.sin( A0 * y ) + Math.cos( A1 * x );
    ny = Math.sin( A2 * x ) + Math.cos( A3 * y );
    x = nx; y = ny;
    } while(--settle>0);
    
//    dx = (dx+2*nx)/3;
//    dy = (dy+2*ny)/3;
    dx=nx;dy=ny;
    
    bmd.setPixel32(
      dx * 465 * drawScale + 465 / 2,
      dy * 465 * drawScale + 465 / 2,
      clr
    );
  }



}