PDA

View Full Version : [DBarbarian Entry 4] - Polar



dbarbarian
January 15th, 2006, 03:49 PM
A collection of polar movements.

***INSTRUCTIONS***
Click to change the graph
Move the mouse around.
Most look the best when you move the mouse from point A to B and don't shake it around.
*****************


Mouse.hide();
Stage.scaleMode = "noScale";

this.propA = function(n,prop,val) {
this.methodsA = {lineStyle:["width","color","alpha"], lineTo:["x","y"], cx:["x"], cy:["y"], del:["d"], ang:["a"]};
(prop=="lineStyle" or prop=="lineTo") ? n[prop](val[this.methodsA[prop][0]],val[this.methodsA[prop][1]],val[this.methodsA[prop][2]]) : n[prop]=(val[this.methodsA[prop][0]]);
return n;
}

this.reset = function(numP,s,ngRot,nlRot,period,nind) {
this.gP = {gRot:ngRot,lRot:nlRot,lP:period,ind:nind};
for (i in this.oA) {
this.oA[i].removeMovieClip();
}
this.oA = new Array();
for (i=1;i<numP;i++) {
this.createEmptyMovieClip("o"+i,i);
this.propA(this["o"+i],"lineStyle",{width:s,color:0xFFFFFF,alpha:100})._parent.propA (this["o"+i],"lineTo",{x:1,y:0})._parent.propA(this["o"+i],"cx",{x:this._xmouse})._parent.propA(this["o"+i],"cy",{y:this._ymouse})._parent.propA(this["o"+i],"del",{d:i})._parent.propA(this["o"+i],"ang",{a:((period/(numP-1))*i)});
this.oA.push(this["o"+i]);
}
}

this.calcR = function(rad,ang,ind) {
return [((50+this.rad)*(Math.pow(Math.cos(14*ang),3))),(50 +this.rad)*Math.sin(5*this.oA[i].ang),(60+this.rad)*(-Math.sin(Math.cos(Math.tan(this.oA[i].ang)))),(50+this.rad)*(Math.sin(5*this.oA[i].ang/10)),(16+(50+this.rad)*(Math.sin(4*this.oA[i].ang))),(2+this.rad)*(this.oA[i].ang),40*(Math.sin(954*this.oA[i].ang)-2*Math.cos(this.oA[i].ang)),(200*Math.cos(2*this.oA[i].ang)*Math.sin(2*this.oA[i].ang)/this.oA[i].ang),20*Math.abs(Math.log(Math.log(Math.tan(Math. cos(Math.pow(Math.sin(this.oA[i].ang),10)))))/Math.log(10)),50*Math.sin(19*this.oA[i].ang/20),40-Math.tan(2*this.oA[i].ang)][this.gP.ind];
}

this.nA = new Array([31,3,100,1500,2*Math.PI,0],[31,5,100,200,Math.PI,1],[51,2,100,300,2*Math.PI,2],[41,2,100,150,1000,3],[51,2,100,150,2*Math.PI,4],[51,2,200,150,6*Math.PI,5],[51,2,250,240,2*Math.PI,6],[51,2,250,240,2*Math.PI,7],[41,2,50,240,2*Math.PI,8],[41,2,50,10,125.67,9],[41,4,90,500,2*Math.PI,10]);

this.onMouseDown = function() {
(this.gP.ind<10)?(this.reset(this.nA[this.gP.ind+1][0],this.nA[this.gP.ind+1][1],this.nA[this.gP.ind+1][2],this.nA[this.gP.ind+1][3],this.nA[this.gP.ind+1][4],this.nA[this.gP.ind+1][5])):(this.reset(31,3,100,1500,2*Math.PI,0));

this.onEnterFrame = function() {
(this.cr + (2*Math.PI)/this.gP.gRot <= 2*Math.PI) ? (this.cr += (2*Math.PI)/this.gP.gRot):(this.cr+=(2*Math.PI)/this.gP.gRot-2*Math.PI);
for (i in this.oA) {
(this.oA[i].ang + this.gP.lP/this.gP.lRot <= this.gP.lP) ? (this.oA[i].ang += this.gP.lP/this.gP.lRot):(this.oA[i].ang+=this.gP.lP/this.gP.lRot-this.gP.lP);
(this.rad += (Math.sqrt((this._xmouse-this.px)*(this._xmouse-this.px)+(this._ymouse-this.py)*(this._ymouse-this.py))/20-this.rad)/30);
for (j=0;j<2;j++) {
(j==0) ? (this.oA[i].cx += (this._xmouse-this.oA[i].cx)/this.oA[i].del):this.oA[i].cy += (this._ymouse-this.oA[i].cy)/this.oA[i].del;
(j==0) ? (this.oA[i]._x = this.oA[i].cx + (this.calcR(this.rad,this.oA[i].ang,this.gP.ind))*Math.cos(this.oA[i].ang+this.cr)):(this.oA[i]._y = this.oA[i].cy +(this.calcR(this.rad,this.oA[i].ang,this.gP.ind))*Math.sin(this.oA[i].ang+this.cr));
}
}
this.px = this._xmouse;
this.py = this._ymouse;
}
}

EDIT: Forgot to thank Sinister Shadow for the property assignment idea. :)

ElectricGrandpa
January 15th, 2006, 05:22 PM
neat!

dbarbarian
January 15th, 2006, 05:26 PM
Thanks :)

squan
January 15th, 2006, 05:36 PM
Damn, that's some wicked geometry/math ... whatever it is with the numbers :).

Lovely particle-thingy.

dbarbarian
January 15th, 2006, 06:03 PM
Yea, never imagined that math would come in handy before I started working with flash. Glad you liked it. =)

kdd
January 16th, 2006, 01:21 AM
that's cool. :thumb:

icio
January 16th, 2006, 05:24 AM
That's really cool :thumb:

hybrid101
January 16th, 2006, 06:41 AM
really smooth on my computer, dbarbarian, i love all of your works!!!

dbarbarian
January 16th, 2006, 12:45 PM
Thanks :beam:

hybrid101: That's good to hear. I was a little worried about speed issues, with up at 50 particles calculating a bunch of stuff each frame.
I hope I don't dissapoint with future entries :)

Seb Hughes
January 16th, 2006, 01:11 PM
OMFG that pwns, gotta be the best one i seen so far.

Sammo
January 16th, 2006, 02:11 PM
The points redraw themselves everytime the mouse is moved instead of just moving to the mouse point right?

I see a discrepency everytime the mouse is moved.