Author Archives: Zevan

setPixel() Flames Attractor

CLICK HERE TO COPY
Actionscript:

[SWF(width = 600, height = 600)]

var a:Number = 0.02;

 

var xn:Object = new Object();

 

var scale:Number = 20;

var iterations:Number = 10000;

 

var canvas:BitmapData = Bitmap(addChild(new Bitmap(new BitmapData(600,600,false,0xEFEFEF)))).bitmapData;

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

   

    canvas.fillRect(canvas.rect, 0xEFEFEF);

    a = mouseX / 100;

   

    // equations from here: http://www.discretedynamics.net/Attractors/Flames.htm

    // i used object syntax [...]

Posted in setPixel | Tagged , | Leave a comment

Parallax Based on Y

CLICK HERE TO COPY
Actionscript:

[SWF(backgroundColor=0x000000, frameRate=30)]

 

var elements:Array = new Array();

for (var i:int = 0; i<200; i++){

    var c:MovieClip= MovieClip(addChild(new MovieClip()));

    c.x = Math.random()*(stage.stageWidth + 100) - 50;

    c.y = Math.random()*stage.stageHeight;

    with(c.graphics) lineStyle(2, 0xFFFFFF,3), drawCircle(0,0,2 + c.y / 20);

    c.startX = c.x;

    elements.push(c);

}

 

var offset:Number = 0;

var t:Number = 0;

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void [...]

Posted in motion | Tagged , | 2 Comments

Animate Graphics.lineTo()

CLICK HERE TO COPY
Actionscript:

// line thickness, line color, start point, end point, divisor, callback

function animateLineTo( thick:Number, col:uint, sp:Point, ep:Point, div:Number=4, callback:Function=null):void {

     var s:Shape  = Shape(addChild(new Shape()));

     var ap:Point = sp.clone();

     div = Math.max(2, div);

     setTimeout(runLineAnimation, 1000/stage.frameRate, s.graphics , thick , col , sp , ep , ap, div, callback);

}

 

function runLineAnimation(g:Graphics [...]

Posted in motion | Tagged , | 1 Comment

Readable Conditionals

CLICK HERE TO COPY
Actionscript:

// NOTE: this code won't do anything in you're timline....

 

// do you do this?

 

if (ball.x <0 || ball.y <0 || ball.x> stage.stageWidth || ball.y> stage.stageHeight){

       // cause ball to explode

}

 

// or this?

 

if (isAtStageEdge(ball)){

       // cause ball to explode

}

 

function isAtStageEdge(mc:MovieClip):Boolean{

   return (mc.x <0 || mc.y <0 || mc.x> stage.stageWidth [...]

Posted in functions | Tagged , | Leave a comment