somebody621
Member
|
Oops... You meant the little spiral things that spin around. It still shouldn't be so hard. The only time you actually need sine and cosine calculations is while plotting the spiral coordinates, and rotating the coordinates. Make a for loop to increase y. within each loop, make an object with x, y, and z value. (In flash 7, for loops are the fastest kind) Make a corresponding angle to the y. y is equal to the y. z is equal to the sine of the angle multiplied by the radius of the double helix x is equal to the cosine of the angle multiplied by the radius of the double helix (in other words) z axis^ / angle line azzzzz|/ azzzzz|/ az<---------> = x axis azzzzz| azzzzzv where this is a layer of y use the sine and cosine values to find the coordinates of the end of the angle line so you can find the x and z coordinates In the loop, x2 is equal to y and angle2 is angle + 180 degrees (pi radiens); the object that holds this value is also object2 + y Find y2 and z2 using the same formula. Before you end the loop, also find the values for the cartesian coordinates. I think that should find the x, y, and z for points on the spirals. Of course though, it was done right up on the spot, so it might not work. Edit2: I was bored and did a non-rotating version of it. DNA And here is the crappily organized and unstructured code... beware... no comments and no depth swapping ( too lazy ) var dist:Number = 800;
var centerX:Number = Stage.width/2;
var centerY:Number = Stage.height/2;
var pi = Math.PI;
var wave = new Object();
wave.radius = 50;
wave.interval = 25;
function findCar(x:Number, y:Number, z:Number):Array{
//This function is almost copied code from Glen Rhodes' book, "Macromedia Flash MX 2004 Game Development"
var zFactor:Number = dist/z;
var sX:Number = x * zFactor + centerX;
var sY:Number = y * zFactor + centerY;
var ar:Array = [sX, sY];
return(ar);
}
for(y = -centerX; y<Stage.height; y+= wave.interval){
var loop:Number = y/wave.interval
var d1:String = "Object1_" + loop;
wave[d1] = new Object();
var d2:String = "Object2_" + loop;
wave[d2] = new Object();
var a:Number = y * 30;
var radians:Number = a * pi/180;
var z:Number = Math.sin(radians)*wave.radius;
var x:Number = Math.cos(radians)*wave.radius;
var x2:Number = x * -1;
var z2:Number = z * -1;
var ar1:Array = findCar(x, y, z+ 1500);
var ar2:Array = findCar(x2, y, z2+1500);
wave[d1].sx = ar1[0];
wave[d2].sx = ar2[0];
wave[d1].sy = ar1[1];
wave[d2].sy = ar2[1];
var n1:String = "b1_" + loop;
var n2:String = "b2_" + loop;
_root.attachMovie("b", n1, loop + 600);
_root.attachMovie("b", n2, loop);
var b1:MovieClip = _root[n1]
var b2:MovieClip = _root[n2]
b1._x = ar1[0];
b1._y = ar1[1];
b2._x = ar2[0];
b2._y = ar2[1];
//again, formula from Glen Rhodes' book, "Macromedia Flash MX 2004 Game Development"
b1._xscale = b1._yscale = 100 * dist/(z + 1500);
b2._xscale = b2._yscale = 100 * dist/(z2 + 1500);
trace(b1._xscale);
_root.lineStyle( 1, 0x0000ff, 100 );
_root.moveTo(ar1[0], ar1[1]);
_root.lineTo(ar2[0], ar2[1]);
} Edit1: Does everyone not feel flash worth it now? It can be a real treat once you learn how to use it. Edit3:Is it possible to access variables outside of a class inside the class without get and set? NVM gotit IF Microsoft gets ANYWHERE with Sparkle, I'm buying macs the rest of my life. If anyone here has anything to do with sparkle, well...
< Message edited by somebody621 -- 8/8/2006 21:51:19 >
|