To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-17-2004, 02:28 PM   #1
Bostonian
Senior Member
 
Join Date: Feb 2004
Location: Worcester Ma
Posts: 161
Circles in Circle

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.

Really appreciate any feedback.

Thanks.
Bostonian is offline   Reply With Quote
Old 10-17-2004, 02:52 PM   #2
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
There are a few movies on my site that do things like this. See link below.

- Jim
__________________
jbum is offline   Reply With Quote
Old 10-17-2004, 02:59 PM   #3
Bostonian
Senior Member
 
Join Date: Feb 2004
Location: Worcester Ma
Posts: 161
Wow its you Krazydad. Cant beleive you just replied...I was on your site for a few hours last night looking at your bio & stuff. You're a genius.

I have been looking at your code, especially the "Wheel of Trinkets". Obviously my answer lies there but I am having trouble isolating what I need.
Bostonian is offline   Reply With Quote
Old 10-17-2004, 06:20 PM   #4
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
A lot of my sample code, including 'clumping' and 'wheel of trinkets' include sample functions for drawing circles using parameters x, y and radius.

If your outer circle has center ox,oy and radius oRad, then your inner circles need to be within that.

If an inner circle has center ix,iy and radius iRad, then distance of the center of the inner circle from the center of the outer circle is given by

dist = Math.sqrt(Math.pow(ox-ix,2) + Math.pow(oy-iy,2));

This distance should not allowed to exceed (oRad - iRad).

Here is a script that draws two circles which randomly move within an outer circle.

I'll add some comments later when I have more time...

code:


SW = Stage.width;
SH = Stage.height;
kRadiansToDegrees = 180/Math.PI;
kDegreesToRadians = Math.PI/180;

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;
}
}

_root.createEmptyMovieClip("outer_mc", 1);
_root.createEmptyMovieClip("inner_mc1", 2);
_root.createEmptyMovieClip("inner_mc2", 3);

outer_mc._x = SW/2;
outer_mc._y = SH/2;
outer_mc.rad = 300;
outer_mc.clear();
outer_mc.lineStyle(2, 0xFF0000, 100);
outer_mc.drawCircle(0,0,outer_mc.rad);

inner_mc1._x = inner_mc1.tx = W/2;
inner_mc1._y = inner_mc1.ty = SH/2;
inner_mc1.rad = 50;
inner_mc1.clear();
inner_mc1.tx =
inner_mc1.lineStyle(2, 0x00FF00, 100);
inner_mc1.drawCircle(0,0,inner_mc1.rad);
inner_mc1.onEnterFrame = moveCircle;

inner_mc2._x = inner_mc2.tx = SW/2;
inner_mc2._y = inner_mc2.ty = SH/2;
inner_mc2.rad = 64;
inner_mc2.clear();
inner_mc2.lineStyle(2, 0x0000FF, 100);
inner_mc2.drawCircle(0,0,inner_mc2.rad);
inner_mc2.onEnterFrame = moveCircle;


__________________
jbum is offline   Reply With Quote
Old 10-17-2004, 06:26 PM   #5
Bostonian
Senior Member
 
Join Date: Feb 2004
Location: Worcester Ma
Posts: 161
Thanks for the help JBum!

I have been racking my brains over this one all day. I can definitely work with this...and hopefully you do add more comments...thanks again.
Bostonian is offline   Reply With Quote
Old 10-17-2004, 07:04 PM   #6
Bostonian
Senior Member
 
Join Date: Feb 2004
Location: Worcester Ma
Posts: 161
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.
Bostonian is offline   Reply With Quote
Old 10-17-2004, 08:35 PM   #7
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
Post your .fla and I'll take a look.
__________________
jbum is offline   Reply With Quote
Old 10-17-2004, 08:41 PM   #8
Bostonian
Senior Member
 
Join Date: Feb 2004
Location: Worcester Ma
Posts: 161
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.

Thanks
Attached Files
File Type: fla nucleus2.fla (64.0 KB, 155 views)
Bostonian is offline   Reply With Quote
Old 10-18-2004, 12:08 AM   #9
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
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...
Attached Files
File Type: fla nucleus2.fla (51.5 KB, 298 views)
__________________
jbum is offline   Reply With Quote
Old 10-18-2004, 12:22 AM   #10
Bostonian
Senior Member
 
Join Date: Feb 2004
Location: Worcester Ma
Posts: 161
Thanks so much this works great. This project is due tomorrow and you helped me out a ton (this one hurddle was killing me).

Really appreciate the time you've spent on this.

Thanks again...I'll be joining your site's forums. Cant help but to say again that the stuff on your site is incredible.
Bostonian is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:06 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.