# 3D Circular Ring

In this experiment I wanted to work out the best method for finding the depth at which to move movieclips to as they rotate.

I did it on the second attempt, too, after starting from scratch. Here is the result:

The code in action

``````var x:Number = 275;
var y:Number = 200;

var h:Number = 0;
var w:Number = 300;

var c:Array = [];
var cCount:Number = 1;

var theta:Number = 0;

function init() {
for (var i:Number =0; i < cCount; i++) {
var circle:MovieClip = _root.attachMovie("circle", "circle_"+i, i, {
_x: x + w/2*Math.sin(Math.PI*2*i/cCount),
_y: y + h/2*Math.cos(Math.PI*2*i/cCount)
});
c.push(circle);

var col:Color = new Color(circle);
var o = {
r: 255*(2*Math.abs(i-cCount/2)/cCount),
g: 100+155*(2*Math.abs(i-cCount/2)/cCount),
b: 100
};
col.setRGB((o.r<<16)+(o.g<<8)+o.b);
}
}

function onEnterFrame() {
theta += 0.02 *Math.PI*(_root._xmouse-Stage.width/2)/Stage.width;
theta = (theta-Math.PI)%(2*Math.PI)+Math.PI;
theta = (theta+Math.PI)%(2*Math.PI)-Math.PI;

h = (_root._ymouse - Stage.height/2)*0.4;

for (var i in c) {
var circle = c*;

var t:Number = Math.PI*2*i/cCount + theta;
t = (t-Math.PI)%(2*Math.PI)+Math.PI;
t = (t+Math.PI)%(2*Math.PI)-Math.PI;

circle._x = x+w/2*Math.sin(t);
circle._y = y+h/2*Math.cos(t);

circle._xscale = circle._yscale = 70+30*Math.cos(t);
circle._xscale *= Math.cos(t);

t = 1 - Math.abs(t)/Math.PI;
circle.swapDepths(Math.round(t*2*cCount));
}
}

this.onMouseWheel = function(d) {
while (c.length > 0) c.pop().removeMovieClip();
cCount = Math.max(cCount+d, 1);
init();
}