Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

circle.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
_global.circle = function(mc, x,y, w,h, centered, lstyle, fstyle) {
	w /= 2; h /= 2;
	if (!centered){
		x += w; y += h;
	}
	var xc1 = w*(Math.SQRT2-1), xc2 = w*(Math.SQRT2/2);
	var yc1 = h*(Math.SQRT2-1), yc2 = h*(Math.SQRT2/2);
	// lstyle and fstyle are arrays of lineStyle and beginFill arguments respectively
	if (lstyle) mc.lineStyle.apply(mc, lstyle);
	if (fstyle) mc.beginFill.apply(mc, fstyle);
	mc.moveTo(x+w, y);
	mc.curveTo(x+w, y+yc1, x+xc2, y+yc2);
	mc.curveTo(x+xc1, y+h, x, y+h);
	mc.curveTo(x-xc1, y+h, x-xc2, y+yc2);
	mc.curveTo(x-w, y+yc1, x-w, y);
	mc.curveTo(x-w, y-yc1, x-xc2, y-yc2);
	mc.curveTo(x-xc1, y-h, x, y-h);
	mc.curveTo(x+xc1, y-h, x+xc2, y-yc2);
	mc.curveTo(x+w, y-yc1, x+w, y);
	if (fstyle) mc.endFill();
	return mc;
};