Graphics Programs Reference
In-Depth Information
ner on startAngle , since it is constantly changing. A simple way of doing this is given
below. The factor of 2 just speeds up the rotation of each object about itself.
33
34
35
// rotate each object about its center point
this["object"+i]._rotation = myAngle + 2*startAngle;
}
Tip: Try substituting -2 or -3 for +2 in the line above for a very different effect.
Step 3: Add simple user interactivity
Up to this point, the movie has been a passive experience for the user. Let's add a little
interactivity through keyboard control. An easy-to-implement technique is to increase
or decrease the radius using the Up Arrow and Down Arrow keys.
36
37
38
39
40
41
42
// update the start angle
startAngle += 2;
// check up & down arrow keys to change the radius
if ( Key.isDown(Key.UP) ) { r += 5; }
if ( Key.isDown(Key.DOWN) ) { r -= 5; }
}
Another simple technique is to use the Left Arrow and Right Arrow keys to control the
direction and speed of rotation of the objects about their registration points. Define a
direction variable d as follows.
6
7
8
9
10
// define the object characteristics
numberOfObjects = 6; // number of objects to rotate
startAngle = 0; // starting rotation angle
d = 3; // direction & speed of rotation
Modify the object rotation line and then add the test for the Left Arrow and Right Arrow
keys.
34
35
36
// rotate each object about its center point
this["object"+i]._rotation = myAngle + d*startAngle;
}
 
Search WWH ::




Custom Search