# Help with spiral

**URL:** <https://forum.kirupa.com/t/help-with-spiral/185550>\
**Category:** flash\
**Created:** [April 14, 2006, 3:38am UTC](https://forum.kirupa.com/t/help-with-spiral/185550 "2006-04-14T03:38:43Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 14, 2006, 3:38am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/1 "2006-04-14T03:38:43Z")

</div>

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]

```auto
 [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]

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [April 14, 2006, 4:11am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/2 "2006-04-14T04:11:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 14, 2006, 4:50am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/3 "2006-04-14T04:50:11Z")

</div>

Here you go sorry

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [April 14, 2006, 8:23am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/4 "2006-04-14T08:23:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 14, 2006, 2:09pm UTC](https://forum.kirupa.com/t/help-with-spiral/185550/5 "2006-04-14T14:09:26Z")

</div>

> [@freeskier89](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [April 14, 2006, 5:08pm UTC](https://forum.kirupa.com/t/help-with-spiral/185550/6 "2006-04-14T17:08:18Z")

</div>

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 🙂

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.

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 14, 2006, 5:15pm UTC](https://forum.kirupa.com/t/help-with-spiral/185550/7 "2006-04-14T17:15:16Z")

</div>

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.

```auto
 
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();
}

```

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [April 14, 2006, 6:20pm UTC](https://forum.kirupa.com/t/help-with-spiral/185550/8 "2006-04-14T18:20:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 14, 2006, 9:27pm UTC](https://forum.kirupa.com/t/help-with-spiral/185550/9 "2006-04-14T21:27:37Z")

</div>

> [@freeskier89](#):
>
> 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.☹

---

<div class="post-metadata">

**Author:** ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)\
**Post date:** [April 14, 2006, 11:57pm UTC](https://forum.kirupa.com/t/help-with-spiral/185550/10 "2006-04-14T23:57:10Z")

</div>

man this thread is gold

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [April 15, 2006, 1:55am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/11 "2006-04-15T01:55:01Z")

</div>

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!

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 15, 2006, 3:12am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/12 "2006-04-15T03:12:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [April 15, 2006, 4:07am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/13 "2006-04-15T04:07:06Z")

</div>

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. 🙂 I posted an example with the lines drawn.

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

```auto

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);
		}
	}

```

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [April 15, 2006, 4:14am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/14 "2006-04-15T04:14:23Z")

</div>

Oh and flash doesn’t like drawing to coordinates like (10,10000) 😛 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]

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 15, 2006, 4:37am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/15 "2006-04-15T04:37:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![freeskier89](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@freeskier89](https://forum.kirupa.com/u/freeskier89)\
**Post date:** [April 15, 2006, 5:52am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/16 "2006-04-15T05:52:58Z")

</div>

> [@artistwantab](#):
>
> 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 🙂 So will what I have provided you suffice, or are you still seeking something else?

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 15, 2006, 6:13am UTC](https://forum.kirupa.com/t/help-with-spiral/185550/17 "2006-04-15T06:13:31Z")

</div>

I can get it to transform from here.

Thank you again.
