Actionscript:
-
var canvas:BitmapData = new BitmapData(400,400,false, 0xCCCCCC);
-
addChild(new Bitmap(canvas));
-
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
canvas.fillRect(canvas.rect, 0xCCCCCC);
-
-
var r:Number = Math.abs(200 - mouseX);
-
var r2:Number = r * r;
-
var inc:Number = 1 / r;
-
var xp:Number = .00000001;
-
var yp:Number = -r;
-
while(yp<r){
-
var y:Number = 200 + yp;
-
yp += xp * inc;
-
xp = Math.sqrt(r2 - yp * yp);
-
canvas.setPixel(200 + xp, y, 0x000000);
-
canvas.setPixel(200 - xp, y, 0x000000);
-
}
-
}
A slow way to draw circles using setPixel().
Actionscript:
-
var canvas:BitmapData = new BitmapData(400,400,false, 0xCCCCCC);
-
addChild(new Bitmap(canvas));
-
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
canvas.fillRect(canvas.rect, 0xCCCCCC);
-
var r:Number = Math.abs(200 - mouseX);
-
var r2:Number = r * r;
-
var inc:Number = 1 / r;
-
var xp:Number = .000001;
-
var yp:Number = -r;
-
while(yp <= 0){;
-
var x1:Number = 200 + xp;
-
var y1:Number = 200 + yp
-
var x2:Number = 200 - xp;
-
var y2:Number = 200 - yp;
-
canvas.setPixel(x1, y1, 0x000000);
-
canvas.setPixel(x1, y2, 0x000000);
-
canvas.setPixel(x2, y1, 0x000000);
-
canvas.setPixel(x2, y2, 0x000000);
-
yp += xp * inc;
-
xp = Math.sqrt(r2 - yp * yp);
-
}
-
}
Little better, still slow.
I was brainstorming about a few things today and somehow these two slow circle drawing algorithms popped out. These are pretty useless compared to some of the famous algorithms I've posted in the past. Kind of interesting nevertheless.