# I suck at math please help

**URL:** <https://forum.kirupa.com/t/i-suck-at-math-please-help/184984>\
**Category:** flash\
**Created:** [April 10, 2006, 12:55am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984 "2006-04-10T00:55:52Z")\
**Posts on this page:** 17\
**Page:** 1

<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 10, 2006, 12:55am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/1 "2006-04-10T00:55:52Z")

</div>

Ok so Ive forgotten all my H.S. Geom

I have this code that will move a single object in a spiral trajectory toward the center of the screen

```auto

setInterval(MoveBall,30)
function MoveBall(){
    if(myCounter > 0){
        myCounter--
    }else if(myCounter < 0){
         myCounter++
    }

    var angleEnd:Number = 180
    var angleStart:Number = myCounter
    var angleSteps:Number = 100
    var centerX:Number = 200
    var centerY:Number = 250

    simpleSpiralXY = function(inAngle){
    return inAngle/2;
    }    
    
    var aStep:Number=(angleEnd-angleStart)/angleSteps;
    var curAngle:Number=angleStart;

    
   this_mc._x =centerX+simpleSpiralXY(curAngle)*Math.cos(curAngle*Math.PI/180);

    this_mc._y = centerY+simpleSpiralXY(curAngle)*Math.sin(curAngle*Math.PI/180);
    
    curAngle+=aStep

```

and it works like a champ…but the problem is i need to move several objects in a spiral towards the center of the screen

so i need to incrementally step x,y instead of dirrectly assigning em  
instead of …\_x= # i need …\_x += #  
hehe and i just cant figure out the formula

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 10, 2006, 1:15am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/2 "2006-04-10T01:15:47Z")

</div>

I have some code stolen from an anonymous source:pa:, I feel it will really benefit you:

```auto
function setBrightness(col:Color, brightness:Number):Void {
	var anum:Number = 100-brightness;
	var bnum:Number = 255/100*brightness;
	col.setTransform({re:anum, ga:anum, ba:anum, rb:bnum, gb:bnum, bb:bnum, aa:100, ab:0});
}
var scaleMax:Number = 800;
var fadeOut:Number = 0.93;
var frequency:Number = 10;
var colMin:Number = 0;
var colMax:Number = 40;
var colVariance:Number = colMax-colMin;
function hRad(Void):Number {
	return 4+Math.random();
}
function vRad(Void):Number {
	return 4+Math.random();
}
function vRadInc(Void):Number {
	return 0.1;
}
function hRadInc(Void):Number {
	return 0.1;
}
function lrSpeed(Void):Number {
	return 5+Math.random()*40;
}
function scaleUpSpeed(Void):Number {
	return 1.02;
}
function nooCol(Void):Number {
	return colMin+Math.random()*colVariance;
}
var depth:Number = 0;
onEnterFrame = function () {
	if (Math.floor(Math.random()*frequency) == 0) {
		depth++;
		var noo:MovieClip = _root.attachMovie("ball", "ball"+depth, depth);
		var col:Color = new Color(noo);
		setBrightness(col, nooCol());
		noo._x = -50;
		noo._y = -50;
		noo._xscale = noo._yscale=10;
		noo.scaleSpeed = scaleUpSpeed();
		noo.lrSpeed = lrSpeed();
		noo.hRad = hRad();
		noo.vRad = vRad();
		noo.hRadInc = hRadInc();
		noo.vRadInc = vRadInc();
		noo.lr = 0;
		noo.onEnterFrame = _root.expand;
	}
};
function expand() {
	this.lr += this.lrSpeed;
	this.hRad += this.hRadInc;
	this.vRad += this.vRadInc;
	this._x = Stage.width/2+this.hRad*Math.sin(this.lr*Math.PI/180);
	this._y = Stage.width/2+this.vRad*Math.cos(this.lr*Math.PI/180);
	this._yscale = this._xscale *= this.scaleSpeed;
	this.swapDepths(Math.floor(this._xscale));
	if (this._xscale>_root.scaleMax) {
		this._alpha *= _root.fadeOut;
		if (this._alpha<3) {
			this.removeMovieClip();
		}
	}
}

```

I would have a read over that, it may give you some inspiration in the right direction.🙂

---

<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 10, 2006, 1:17am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/3 "2006-04-10T01:17:01Z")

</div>

sweet thanks man…checking it out now

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 10, 2006, 1:22am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/4 "2006-04-10T01:22:53Z")

</div>

np:flower:

---

<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 10, 2006, 3:14am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/5 "2006-04-10T03:14:13Z")

</div>

well i messed around a lot with that code…Its pretty awesome…

unfortunatly it still doesnt provide me with a

\_x += # instead of \_x = #  
type of equation for movement

I can prolly tweak it to do what i want…but it would be awesome if anyone out there had a += formula i could get 😛

edit im 90% sure i can get this code to do what i need though…im figuring out what to manipulate

---

<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 10, 2006, 3:55am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/6 "2006-04-10T03:55:02Z")

</div>

is there anyway to corect the way that objects circle faster on the outside of the spiral

here ill post my FLA  
see how theres huge gaps on the outside and they get all bunched up inside?  
I want to keep uniform distance throughout the spiral

im talking about the horizontal bunching not the vertical…i can fix the vertical but the horizontals gonna need some math to control speed

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 10, 2006, 4:19am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/7 "2006-04-10T04:19:38Z")

</div>

yeah, that’ll be fun. I’m not sure where to point you, that seems like quite a bit of a pain.

---

<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 10, 2006, 5:59am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/8 "2006-04-10T05:59:36Z")

</div>

basically what i want to do is have it like a static movie clip and the next movie clip pushes the first one in the path of the spiral…like htey were solid objects that couldnt overlap

[edit] This is my code in its entirety atm(as commented as i could make it)

```auto

stop()
var myCount = 1
/*
function setBrightness(col:Color, brightness:Number):Void {
    var anum:Number = 100-brightness;
    var bnum:Number = 255/100*brightness;
    col.setTransform({re:anum, ga:anum, ba:anum, rb:bnum, gb:bnum, bb:bnum, aa:100, ab:0});
}*/

var scaleMax:Number =2500; //Max Scale
var fadeOut:Number = 0.93; //Fadeout(think i made it useless by removing setBrightness...but meh
var frequency:Number = 10; // frequency of ball release(somewhat randomized
var colMin:Number = 5; // ??????
var colMax:Number = 10; // ??????
var colVariance:Number = colMax-colMin; //???????

var hRad:Number = 400.25 //Horizontal radius
var vRad = 400.25 //Vert Radius

var vRadInc:Number = -0.8 //these control how quickly the objects spiral in/ out
var hRadInc:Number = -0.8 // a neg number will spiral in a pos num will spiral out

function lrSpeed(Void):Number { //
    return 1+1.98953*1;
}
function scaleUpSpeed(Void):Number {
    return 1;
}
function nooCol(Void):Number {
    return colMin+0.1573*colVariance;
}
var depth:Number = 0;
onEnterFrame = function () {
    myCount++
    if (depth == 0 || _root["ball"+depth]._x < 670) {
        depth++;
        var MC_toAttach:String = AssignMovie()
        var noo:MovieClip = _root.attachMovie(MC_toAttach, "ball"+depth, depth);
        var col:Color = new Color(noo);
        //setBrightness(col, nooCol());
        noo._x = -150;
        noo._y = -150;
        noo._xscale = noo._yscale=100;
        noo.scaleSpeed = scaleUpSpeed();
        noo.lrSpeed = lrSpeed();
        noo.hRad = hRad;
        noo.vRad = vRad;
        noo.hRadInc = hRadInc;
        noo.vRadInc = vRadInc;
        
        noo.lr = 0;
        noo.onEnterFrame = _root.Spiral;
    }
};
function Spiral() { //this is the function thats in each clips on enter
                    //It Moves the clip in a spiral
    this.lr += this.lrSpeed // LR has something to do with speed
    this.hRad += this.hRadInc;
    this.vRad += this.vRadInc;
        //this code just figures out what ball were moving not used atm
        stringtoparse = String(this)
         parsedstring = stringtoparse.split("ball")
        thisindex = Number(parsedstring[1]);
        
    
        // this places the object
    this._y = 300+this.hRad*Math.sin(this.lr*Math.PI/180); 
    this._x = 300+this.vRad*Math.cos(this.lr*Math.PI/180);
}
function AssignMovie(){
    return "Catseye_grn"
}

```

and this is the SWF in its current form

---

<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 10, 2006, 3:10pm UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/9 "2006-04-10T15:10:35Z")

</div>

just seeing if anyone in the monday morning crowd has any ideas on how i can alter my code to gradually speed up the objects movement as it gets closer to the center so it doesnt bunch up like that

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [April 10, 2006, 3:25pm UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/10 "2006-04-10T15:25:56Z")

</div>

> [@joran420](#):
>
> just seeing if anyone in the monday morning crowd has any ideas on how i can alter my code to gradually speed up the objects movement as it gets closer to the center so it doesnt bunch up like that

maybe like this?

```auto
function Spiral() { //this is the function thats in each clips on enter
                    //It Moves the clip in a spiral
    this.lr += this.lrSpeed // LR has something to do with speed
	
    this.hRad += this.hRadInc;
    this.vRad += this.vRadInc;
	 this.hRadInc*=1.001
	 this.vRadInc*=1.001
        //this code just figures out what ball were moving not used atm
        stringtoparse = String(this)
         parsedstring = stringtoparse.split("ball")
        thisindex = Number(parsedstring[1]);
        
    
        // this places the object
    this._y = 300+this.hRad*Math.sin(this.lr*Math.PI/180); 
    this._x = 300+this.vRad*Math.cos(this.lr*Math.PI/180);
	if(Math.abs(this._x-300)<1 && Math.abs(this._y-300)<1){
		this.removeMovieClip()
	}
}

```

---

<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 10, 2006, 4:35pm UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/11 "2006-04-10T16:35:07Z")

</div>

thanks for the sugestion…unfortunatly it didnt fix it

heres my WIP so far (Spirals1)  
spirals2 has your amendment added

(the only thing i changed was  
this.hRadInc\*=1.001  
this.vRadInc\*=1.001  
)  
Spirals1.swf = my current one(I want the spiral like this but i dont want the balls to bunch up at center)

spirals2.swf = my current code with suggested amendmant

[edit] it wont let me post other attach for some reason…but it doesnt stop the overlap just changes the shap of the spiral basically

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [April 10, 2006, 4:48pm UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/12 "2006-04-10T16:48:36Z")

</div>

> [@joran420](#):
>
> thanks for the sugestion…unfortunatly it didnt fix it
> 
> heres my WIP so far (Spirals1)  
> spirals2 has your amendment added
> 
> (the only thing i changed was  
> this.hRadInc\*=1.001  
> this.vRadInc\*=1.001  
> )  
> Spirals1.swf = my current one(I want the spiral like this but i dont want the balls to bunch up at center)
> 
> spirals2.swf = my current code with suggested amendmant
> 
> [edit] it wont let me post other attach for some reason…but it doesnt stop the overlap just changes the shap of the spiral basically

maybe change the frequency at which you are creating mcs?

```auto
mi = setInterval(function () {
	myCount++;
	if (depth == 0 || _root["ball"+depth]._x<670) {
		depth++;
		var MC_toAttach:String = AssignMovie();
		var noo:MovieClip = _root.attachMovie("MC_toAttach", "ball"+depth, depth);
		var col:Color = new Color(noo);
		//setBrightness(col, nooCol());
		noo._x = -150;
		noo._y = -150;
		noo._xscale = noo._yscale=100;
		noo.scaleSpeed = scaleUpSpeed();
		noo.lrSpeed = lrSpeed();
		noo.hRad = hRad;
		noo.vRad = vRad;
		noo.hRadInc = hRadInc;
		noo.vRadInc = vRadInc;
		noo.lr = 0;
		noo.onEnterFrame = _root.Spiral;
	}
}, 500);

```

---

<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 10, 2006, 7:05pm UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/13 "2006-04-10T19:05:51Z")

</div>

I messed with that a bit before i posted…It wasnt helping but ill try some other stuff once i get home from work in 8 hours

bassically what would be ideal would be if everytime a MC was created all the previous MC’s would be pushed forward along the trajectory(like if the circles were solid objects)

(like  
Create 1\_mc at 30,35  
create 2\_mc @ 30,35 (push 1\_mc to 60,35)  
create 3\_mc @ 30,35(push 1\_mc to 90,35 ; push 2\_mc to 60,35)  
(each cycle is MC.\_x +=30 )  
…  
would move them in a straight line

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 10, 2006, 7:11pm UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/14 "2006-04-10T19:11:06Z")

</div>

So almost like hittest each other?

---

<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 10, 2006, 10:42pm UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/15 "2006-04-10T22:42:02Z")

</div>

Yeah exactly like hitTest each other…but it gets all choppy if i add  
[AS]  
if(!this.hitTest(\_root[“ball” +(thisindex - 1)]){ // check to make sure its not coliding with the ball in fron before moving  
this.\_y = 300+this.hRad_Math.sin(this.lr_Math.PI/180);  
this.\_x = 300+this.vRad_Math.cos(this.lr_Math.PI/180);  
}

[/AS]

and the motion just looks like crap and gets all jerky when they start hitTesting

I think its cause the Object I want to hittest is a circle(but hittests always register as squares…)

Im just getting frusterated with getting my balls to act the way i want(heh that sounds bad)

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 10, 2006, 10:55pm UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/16 "2006-04-10T22:55:35Z")

</div>

leave your balls out of this.😃

---

<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 11, 2006, 5:31am UTC](https://forum.kirupa.com/t/i-suck-at-math-please-help/184984/17 "2006-04-11T05:31:30Z")

</div>

Bah I cant figure out how to make it spiral(I still really really want the spiral so i made it a box using the following(\*\*\*\*ty code)

```auto

    if(this._x < 630 && this._y == 50){this._x += speed; }
    else if(this._x == 630 && this._y < 600){this._y += speed}
    else if ( this._x > 0 && this._y == 600){this._x -= speed;}
    else if (this._x == 0 && this._y > 120){this._y -=speed}
    else if ((this._x < 560) && (this._y == 120)){this._x +=speed}
    else if (this._x ==560 && this._y < 530){ ; this._y += speed}
    else if((this._x > 70) && (this._y == 530)){this._x -= speed}
    else if (this._x == 70 && this._y >190){this._y -= speed}
    else if ( this._x < 490 && this._y == 190){this._x+=speed}
    else if (this._x == 490 && this._y 140 && this._y == 460) {this._x-=speed}
    else if (this._x == 140 && this._y > 260){this._y-=speed}
    else if (this._x < 420 &&this._y ==260){this._x +=speed}
    else if (this._x ==420 && this._y < 390){this._y+=speed}
    else if (this._x > 210 && this._y == 390) {this._x-=speed}
    else if (this._x == 210 && this._y > 340){this._y-=speed}
    else{
    
    this._x += Math.random()
    ; this._y += Math.random()}
    
    

```

If anyone knows of a better way to do this please please please tell me

anyway here is what i wanted the spiral to look like …if i could have gotten it right
