ActionScript 3的三角函数公式创建椭圆椭圆、公式、函数、ActionScript

由网友(微风吹过的声音)分享简介:我正与此函数移动的物体围绕在一个完美的圆圈的中心点,我试图修改它以移动为椭圆形的1/2高,因为它是宽?I am working with this function that moves an object around a center point in a perfect circle and am trying...

我正与此函数移动的物体围绕在一个完美的圆圈的中心点,我试图修改它以移动为椭圆形的1/2高,因为它是宽?

I am working with this function that moves an object around a center point in a perfect circle and am trying to modify it to move it in an oval shape that is 1/2 as high as it is wide?

基本上,我有一个设定速度

Basically, I have a set speed

var myVelocity:Number = 0.25;

然后,我计算我的基于速度正弦和余弦

then I calculate my Sine and Cosine based on the speed

var myCos:Number = Math.cos(myVelocity);
var mySin:Number = Math.sin(myVelocity);

那么我想从一个固定的中心点沿每个轴的物体的距离和

then I figure the distance of the the object from a fixed center points along each axis and

var x1:Number = myBall.x - centerX;
var y1:Number = myBall.y - centerY;
var x2:Number = myCos * x1 - mySin * y1;
var y2:Number = myCos * y1 + mySin * x1;
myBall.x = centerX + x2;
myBall.y = centerY + y2;

我有另一个函数,数字基于myBall.x =的centerX + COS(角度)x和y *半径;这是很容易修改半径变成椭圆,但有一个简单的方法,以mod上述之一,成为一个椭圆?我想这样做是与code更有效,更减少了数学函数的调用次数

I have another function that figures x and y based upon myBall.x = centerX + cos(angle) * radius; that is easy enough to modify the radius to become an ellipse, but is there an easy way to mod the one above to become an ellipse? I want to do this to be more efficient with the code and reduce the number of math function calls

推荐答案

这个问题几乎是逐字什么基思·彼得斯覆盖基金会的ActionScript 3.0:使事情移动

This question is nearly verbatim to what Keith Peters covers in Foundation Actionscript 3.0: Making Things Move!

我从书上刮起了快速的片断给你。

I've whipped up a quick snippet for you from the book.

import flash.display.Shape;
import flash.events.Event;

var box:Shape = new Shape();
box.graphics.beginFill(0xFF0000);
box.graphics.drawRect(0, 0, 50, 50);
box.graphics.endFill();
addChild(box);
var angle:Number = 0;
var centerX:Number = stage.stageWidth/2 - (box.width/2);
var centerY:Number = stage.stageHeight/2 - (box.height/2)
var radiusX:Number = 200;
var radiusY:Number = 100;
var speed:Number = .1;
stage.addEventListener(Event.ENTER_FRAME, loop, false, 0, true);

function loop(evt:Event):void
{
    box.x = centerX + Math.sin(angle) * radiusX;
    box.y = centerY + Math.cos(angle) * radiusY;
    angle += speed;
}

结果: http://www.swfupload.com/view/155573.htm

阅读全文

相关推荐

最新文章