Author Archives: Zevan

Readable Radial Gradient

CLICK HERE TO COPY
Actionscript:

var size:Number = 400;

var halfSize:Number = size / 2;

var canvas:BitmapData = new BitmapData(size, size,false, 0x000000);

addChild(new Bitmap(canvas, PixelSnapping.AUTO, true));

 

var rings:Number = 40;

var color:uint, theta:Number, dx:Number, dy:Number;

 

for (var i:int = 0; i<canvas.width; i++){

    for (var j:int = 0; j<canvas.height; j++){

        // distance from center of canvas to current x, y [...]

Posted in BitmapData, pixel manipulation, setPixel | Leave a comment

setPixel() Radial Gradient

CLICK HERE TO COPY
Actionscript:

// add a BitmapData object to the stage in one line:

addChild(new Bitmap(new BitmapData(200,200,false,0x00000)));

 

// draw a radial gradient

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

Bitmap(getChildAt(0)).bitmapData.setPixel( i, j, 100 + 100 * Math.sin(Math.sqrt(Math.pow(i - 100, 2)+Math.pow(j - 100, 2)) * 40 * Math.PI/180) <<16 );

 

/*

WARNING: This code [...]

Posted in BitmapData, pixel manipulation, setPixel | Tagged , , | Leave a comment

MovieClip Random Frame

CLICK HERE TO COPY
Actionscript:

myClip.gotoAndStop(int(Math.random() * myClip.totalFrames + 1));

An easy way to make a MovieClip go to a random frame. In the future I may post a demo of this technique.

Posted in MovieClip, random | Leave a comment

Quick Alphabet Array

CLICK HERE TO COPY
Actionscript:

var alphabet:Array = ("abcdefghijklmnopqrstuvwxyz").split("");

trace("this is the letter b...", alphabet[1]);

trace(alphabet);

/* outputs:

this is the letter b... b

a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

*/

This is an easy way to create an array of the alphabet. It's easier to type than:
CLICK HERE TO COPY
Actionscript:

var alphabet:Array = ["a","b","c".... etc];

Posted in arrays, string manipulation, strings | 3 Comments