1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
public class Main extends Sprite
{
private var a:Number; //demi grand axe
private var b:Number; //demi petit axe
private var theta:int;
private var l:Number;
private var h:Number;
private var O:Point;
private var R:Number;
private var oldM:Point;
private const degtorad:Number = Math.PI / 180;
private var roue:Shape = new Shape();
public function Main():void
{
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
l = stage.stageWidth;
h = stage.stageHeight;
a = l / 4;
b = h / 4;
O = new Point(2 * a, 2 * b);
R = l / 30;
oldM = new Point(O.x + a + R, 0);
with (graphics)
{
lineStyle(3, 0);
drawEllipse(O.x - a, O.y - b, 2 * a, 2 * b);
}
with (roue.graphics)
{
lineStyle(3, 0);
drawCircle(0, 0, R);
lineStyle(2, 0);
moveTo(-R, 0);
lineTo(R, 0);
moveTo(0, -R);
lineTo(0, R);
}
addChild(roue);
stage.addEventListener(Event.ENTER_FRAME, contourner);
}
private function contourner(e:Event):void
{
var M:Point;
var dl:Number;
theta++;
M = new Point(O.x + (a + R) * Math.cos(theta * degtorad), O.y + (b + R) * Math.sin(theta * degtorad));
dl = Math.sqrt((M.x - oldM.x) * (M.x - oldM.x) + (M.y - oldM.y) * (M.y - oldM.y));
roue.x = M.x;
roue.y = M.y;
roue.rotationZ += dl / (R * degtorad);
oldM = M;
}
}
} |
Partager