Help with spiral

Here is the code.
If anyone can help me get it to spiral that would be great.

Also any tutorials you can point me to that explains whats happening in this code would be great also.

One other problem when trying to publish this code to Flash 8. It would slow down and give me an error.

???

[LEFT]

 [LEFT]MovieClip.prototype.ball3d = function (localX, localY) {
ballX = (localX * Math.PI) / 180;
ballY = (localY * Math.PI) / 180;
tempZ = (z * Math.cos (ballY)) - (x * Math.sin (ballY));
Xpos = (z * Math.sin (ballY)) + (x * Math.cos (ballY));
Zpos = (y * Math.sin (ballX))-75 + (tempZ * Math.cos (ballX));
Ypos = (y * Math.cos (ballX)) - (tempZ * Math.sin (ballX));
_x = 4 * Xpos;
_y = 4 * Ypos;
_xscale = (_yscale = Zpos + 150);
swapDepths (Zpos * 50);
};
MovieClip.prototype.spiral = function () {
if (tester && signal) {
i = 0;
while (nextBall >= i) {
spin ();
this["ball" + i].ball3d (tilt, _root.ballY);
i++;
}
}
};
MovieClip.prototype.orbit = function (radius, gesamt) {
x = new Array (0, 0);
y = new Array (0, 0);
z = new Array (0, 0);
angle = (radians = ((360 / gesamt) * Math.PI) / 180);
i = 1;
while (gesamt >= i) {
x* = Math.round (radius * Math.cos (angle));
z* = Math.round (radius * Math.sin (angle));
y* = 0;
angle = angle - radians;
i++;
}
};
MovieClip.prototype.initSpin = function () {
nextBall = ballName.length - 1;
orbit (40, nextBall);
i = 0;
while (nextBall >= i) {
if (i != 0) {
attachMovie ("ball", "ball" + i, i);
}
this["ball" + i].x = x*;
this["ball" + i].y = y*;
this["ball" + i].z = z*;
i++;
}
tester = 4;
};
MovieClip.prototype.spin = function () {
_root.ballY = _root.ballY - (speed);
};[/LEFT]

[/LEFT]

At the moment the code does nothing, it might help to post a fla (MX format) that works.

Here you go sorry

Hmm… it is causing flash to crash. Could the fla be corrupted? It is weird because it is not the typical “Unexpected file format” error. What version of flash did you save it with?

Yes it does crash in flash 8 but not in flash 5.

I dont know why that was the second part of my question.

thanks

Well it won’t open with flash mx either :(. I’ll see if I can spend a moment getting the raw code to do something :slight_smile:

Edit: OK there are definitly some variables being set by movieclips that are not provided in the code. What do you want the code to do when you are done? I think it would be easier for me just to recode it to make it more functional.

That is really strange. I am using flash 8.

Here is the rest of the code that you attach to the clip object and move onto the stage.

 
onClipEvent (load) { 
 ballName = new Array(0,1,2,3,4,5,6,7,8,9,10);
 initSpin();
 speed = 300;
 tilt = -20;
 signal = 1;
}
onClipEvent (enterFrame) {
 spiral();
}

Alright I finally got the code to work :D, now how do you want it to spiral? The code was missing a ton of ‘this’ keywords. It had prototypical functions, but really failed to use them correctly.

Very Cool.

Basically, I want the spiral to start in the middle and spiral towards the screen.

Thank you very much.

Sorry about the errors.:frowning:

man this thread is gold

Alright, is this how you want it? It is coming along quite neatly :D. I totally ditched your code if that is fine, because I found it way easier just to write my own :D. Let me know if you have any questions!

Camera=function(X,Y,Z,focalLength){
	this.fL=focalLength;
	this.X=X;
	this.Y=Y;
	this.Z=Z;
	}
Camera.prototype.Move=function(X,Y,Z){
	this.X+=X;
	this.Y+=Y;
	this.Z+=Z;
	this.engine.Render();
	}
Engine3D=function(Camera,Centerx,Centery){
	this.camera=Camera;
	this.camera.engine=this;
	this.vertexBuffer = _root.createEmptyMovieClip("3Dcontainer"+(containerdepth++),containerdepth);
	this.vertexBuffer._x=Centerx;
	this.vertexBuffer._y=Centery;
	this.depth=0;
	}
Engine3D.prototype.Render=function(){
	for(i in this.vertexBuffer){
		this.vertexBuffer*.Draw();
		}
	}
Engine3D.prototype.Attach3DPoint=function(X,Y,Z){
	this.depth++;
	var mc=this.vertexBuffer.attachMovie("point","point"+this.depth,this.depth);
	mc.parentEngine=this;
	mc.X=X;
	mc.Y=Y;
	mc.Z=Z;
	mc.Draw();
	return mc;
	}
MovieClip.prototype.Draw=function(){
		var focalRatio=this.parentEngine.camera.fL/(this.parentEngine.camera.fL+(this.Z-this.parentEngine.camera.z))
		this._x=focalRatio*(this.parentEngine.camera.X-this.X);
		this._y=focalRatio*(this.parentEngine.camera.Y-this.Y);
		this.swapDepths(10000-this.Z);
		this._xscale=this._yscale=this._alpha=focalRatio*100;
		if(focalRatio>7){
		//	this.removeMovieClip();
			}
	}
Camera1 = new Camera(0,0,-20,40);
Engine1=new Engine3D(Camera1,275,200);

//These are the variables that you will want to manipulate
Radius = 1;
Count=10;
OutwardVelocity =.5
RotationalVelocity =.1 

for(var n = 0;n<Count;n++){
	var mc = Engine1.attach3DPoint(0,0,0);
	mc.T=n/Count*Math.PI*2;
	mc.R=0;
	
    mc.line=line.createEmptyMovieClip("line"+n,n+1);
	mc.line.lineStyle(1,0,100);
	mc.line.moveTo(mc._x+275,mc._y+200);
	mc.onEnterFrame=function(){
		this.T+=RotationalVelocity;
		this.R+=OutwardVelocity;
		this.X=this.R*Math.cos(this.T);
		this.Z=this.R*Math.sin(this.T)+this.R/2;
		this.Y=this.Z;
	}
	}
onEnterFrame=function(){
	Engine1.Render();
	//Camera1.Move(-(-275+_xmouse)/30,-(-200+_ymouse)/30,2);
}

Very cool effect and your code is much easier to understand. I didn’t write all that code just changed things around. Not exactly what I ment by spiral.

Here is an example if you still want to mess with it.

Thanks for all the help. Concidering how many hits this thread has received I think I am not the only one looking for a good 3d spiral effect.

Lol ok. So do you not want it in 3d, because what I posted actually is a spiral, it just doesn’t really look like it. :slight_smile: I posted an example with the lines drawn.

I also posted a 2D spiral :smiley: below. If this is still not quite what you want let me know :wink:


CenterX = 275;
CenterY = 200;
Count = 1;
OutwardVelocity = .5; 
RotationalVelocity = .1;

_root.createEmptyMovieClip("lines",-1);
for(n=0;n<Count;n++){
	var mc = _root.attachMovie("ball","ball"+n,n);
	mc.line=lines.createEmptyMovieClip("line"+n,n);
	mc.line.lineStyle(1,0,100);
	mc.line.moveTo(CenterX,CenterY);
	mc.T= Math.PI*2/Count*n
	mc.R=0;
	mc.onEnterFrame=function(){
		//Logarithmic Spiral : this.R+=OutwardVelocity+=.1;
		this.R+=OutwardVelocity;
		this.T+=RotationalVelocity;
		this._x=CenterX+this.R*Math.cos(this.T);
		this._y=CenterY+this.R*Math.sin(this.T);
		this.line.lineTo(this._x,this._y);
		}
	}

Oh and flash doesn’t like drawing to coordinates like (10,10000) :stuck_out_tongue: That is why Spiral3D.swf is weird looking after a while.

[whisper]I know I shouldn’t double post, I just don’t want to screw up the AS formatting by doing so[/whisper]

Ok I understand much better now.

I guess I wanted something like spiral2d to tranform up giving the illusion of 3d was what I looking for.

Man you code is too cool.

Thank you very much.

Your welcome :slight_smile: So will what I have provided you suffice, or are you still seeking something else?

I can get it to transform from here.

Thank you again.