Anyone know where I could find some code on how to produce a few small circles randomly moving around inside one major circle? The major circle's border reflects the smaller circles and keeps them contained inside it.
I am trying to finish a project and I need to imitate a basic molecular level model with protons and neutrons.
MovieClip.prototype.drawCircle = function(x,y,radius)
{
var r = radius;
var theta = 45*kDegreesToRadians;
var cr = radius/Math.cos(theta/2);
var angle = 0;
var cangle = -theta/2;
this.moveTo(x+r, y);
for (var i=0;i < 8;i++)
{
angle += theta;
cangle += theta;
var endX = r*Math.cos (angle);
var endY = r*Math.sin (angle);
var cX = cr*Math.cos (cangle);
var cY = cr*Math.sin (cangle);
this.curveTo(x+cX,y+cY, x+endX,y+endY);
}
}
moveCircle = function()
{
var dx = this.tx - this._x;
var dy = this.ty - this._y;
if (Math.abs(dx) < 1 && Math.abs(dy) < 1)
{
var range = Math.random()*(outer_mc.rad - this.rad);
var a = Math.random()*2*Math.PI;
this.tx = SW/2 + Math.cos(a) * range;
this.ty = SH/2 + Math.sin(a) * range;
}
else {
this._x += dx/5;
this._y += dy/5;
}
}
The problem I am runing into now is that I am trying to put this script into a MC that can be resized to slowly shrink away into the BG and fade away...I tried substituting the occurences of _root with _parent, the final result is that nothings works.
Here is where i am at so far...I am now trying to get this stuff "encapsulated" into a MC but i cant seem to get that part. I have erased my efforts in that regard...but here is my .fla.
I turned your blue circle into a movieclip called circle_mc and put the animation inside of it. There's a commmented out routine at the bottom which animates circle_mc...