# \[8\] bitmapData Circle

**URL:** <https://forum.kirupa.com/t/8-bitmapdata-circle/170243>\
**Category:** open source\
**Created:** [November 24, 2005, 12:53am UTC](https://forum.kirupa.com/t/8-bitmapdata-circle/170243 "2005-11-24T00:53:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![icio](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/icio/32/484_2.png) [@icio](https://forum.kirupa.com/u/icio)\
**Post date:** [November 24, 2005, 12:53am UTC](https://forum.kirupa.com/t/8-bitmapdata-circle/170243/1 "2005-11-24T00:53:02Z")

</div>

I’ve been thinking about how to do this for a while, read a little about it. Here’s what I came up with after trying out a little porting and then modification and optimisation:

```auto
/* Imports
********************************************* */
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;

/* Variables & Objects
********************************************* */
var bitmap:BitmapData = new BitmapData(200, 200, false, 0x00000000);
var bmRect:Rectangle = new Rectangle();

/* Setup
********************************************* */
var holder:MovieClip = _root.createEmptyMovieClip("_holder", _root.getNextHighestDepth());
holder.attachBitmap(bitmap, holder.getNextHighestDepth());
holder._x = Stage.width/2 - holder._width/2;
holder._y = Stage.height/2 - holder._height/2;

/* drawBitmapCircle
********************************************* */
function drawBitmapCircle(target:BitmapData, cX:Number, cY:Number, r:Number, color:Number) {
	var x:Number = 0;
	var y:Number = 0;
	var r2:Number = r*r;
	for (x=1; x<r; x++) {
		y = Math.ceil(Math.sqrt(r2 - x*x));
		bmRect.topLeft = new Point(cX-x, cY-y);
		bmRect.size = new Point(2*x, 2*y);
		target.fillRect(bmRect, color);
	}
}

/* drawBitmapCircle Call
********************************************* */
drawBitmapCircle(bitmap, 100, 100, 90, 0xFFFFFF);

```

The files are attached.
