She walks in beauty like the night // Hypnotising the silence with her powers // Armageddon is bedding this picture alright // My Marilyn come to slum for an hour. An actionscript and music blog.

Circular Motion: Rotation Around a Point

Posted: May 26th, 2009 | Author: Janice | Filed under: Uncategorized | No Comments »
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// p is planet, instance name "p"  
// c is center, instance name "c" 
// rotation about the center 
 
var myRadius:Number = 100;
var mySpeed:Number = 7;
var xCenter:Number = c.x; 
var yCenter:Number = c.y; 
var myDegree:Number = 0; 	
 
addEventListener(Event.ENTER_FRAME, orbit);
 
var myAngle:Number = 45;
var myRadian:Number = myAngle * (Math.PI / 180);
 
function orbit(e:Event):void {
    p.x = (myRadius * Math.cos(myRadian));
    p.y = (myRadius * Math.sin(myRadian));
 
    myDegree += mySpeed;
    myRadian = (myDegree/180)*Math.PI;
    p.x = xCenter + Math.cos(myRadian) * myRadius;
    p.y = yCenter - Math.sin(myRadian) * myRadius;
}


Leave a Reply