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 coord
-
dx = i - halfSize;
-
dy = j - halfSize;
-
theta = Math.sqrt((dx * dx)+(dy * dy)) * rings;
-
color = (100 + 100 * Math.sin(theta * Math.PI/180)) <<16;
-
canvas.setPixel(i, j, color);
-
}
-
}
-
-
/*
-
WARNING: This code was written for fun. Use at your own risk.
-
*/
This is the previous post written in a readable way. Draws a radial gradient using pythagorean theorem and sine.