Graphics Programs Reference
In-Depth Information
Figure 5.24 Elliptical motion of an object
You can use the Left Arrow and Right Arrow keys to narrow and widen the horizontal
radius. The Up Arrow and Down Arrow keys will lengthen and shorten the vertical radi-
us. The car traversing the path will adjust accordingly.
Let's take a quick look at the script. Open ellipsor.fla in the Chapter 5 folder. As
before, we begin by defining the path characteristics. This consists of specifying the
coordinates (xc,yc) of the center of the path as well as the initial horizontal radius xro
and the initial vertical radius yro . They are defined as half the width and half the height
respectively. Our path is initially a circle, so these two values will start out the same.
1
2
3
4
5
// define the elliptical path characteristics
xc = path_mc._x; // xc = horizontal center of path
yc = path_mc._y; // yc = vertical center of path
xro = path_mc._width/2; // xro = initial path x-radius
yro = path_mc._height/2; // yro = initial path y-radius
We are using the arrow keys to modify the shape of the curve, so we'll define a function
checkKeys() to specify the desired behaviors. The way in which we'll modify the path
will be to change the horizontal and vertical scale factors _xscale and _yscale . The
scale factors each begin with a value of 100%. If we press on the Right Arrow key, the
_xscale will keep increasing by 2; if we press on the Left Arrow key, it will decrease by
2. This will serve to widen or narrow the path horizontally. Similar changes occur with
_yscale as we press on the Down Arrow key and Up Arrow key.
Search WWH ::




Custom Search