PDA

View Full Version : generate spirals


treatkor
01-15-2006, 11:59 PM
more spirally goodness.
click to generate a new one, then click again to make another, etc..

*edit - much improved version here: http://www.kirupa.com/forum/attachment.php?attachmentid=32647&d=1137412554
improved code here: http://www.kirupa.com/forum/showthread.php?p=1754527#post1754527


var randomNum = function (Min, Max) {
return Min+random(((Max+1)-Min));
};
var myRefArray = [];
var HH=this.createEmptyMovieClip("HH", this.getNextHighestDepth());
HH._x = HH._y=200;
onMouseDown = function () {
startRotate(randomNum(-30, 60), randomNum(-100, 100), 0, randomNum(60, 600));
};
startRotate = function(aaa, bbb, c, scl) {
for (var p = 0; p<30; p++) {
var hw = (200/(p+1))+6;
var aHH = HH.createEmptyMovieClip("aHH", 300+p);
var cHH = aHH.createEmptyMovieClip("cHH", 2000+p);
var eHH = cHH.createEmptyMovieClip("eHH", this.getNextHighestDepth()+1);
eHH.lineStyle(0.8, 0xFFFFFF, (6*p)+10);
for (i=0; i<4; i++) {
eHH.curveTo(hw*Math.cos(aaa), hw*Math.sin(bbb), hw*Math.cos(aaa), hw*Math.cos(bbb));
eHH.curveTo(hw*Math.cos(bbb), hw*Math.sin(aaa), 0, 0);
}
myRefArray[p] = cHH;
}
this.onEnterFrame = function() {
myRefArray[c]._parent._yscale = myRefArray[c]._parent._xscale=scl;
myRefArray[c].onEnterFrame = function() {
this._parent._rotation -= aaa;
this._rotation += bbb;
};
if (c<myRefArray.length) {
c++;
} else {
c = 0;
}
};
};



can someone check if i'm meeting the <=25 lines requirement? i think i'm counting this right, but i hope i'm not over.

kdd
01-16-2006, 12:05 AM
whoa, that's mesmerizing and cool... :thumb: sorry i haven't counted lines...

jerez_z
01-16-2006, 12:52 AM
24 lines I think

ElectricGrandpa
01-16-2006, 01:21 AM
I counted 23, but if you changed the last part from:

if (c<myRefArray.length) {
c++;
} else {
c = 0;
}

...to...

(c<myRefArray.length)? c++: c = 0;

...you'd save some lines.

dbarbarian
01-16-2006, 01:52 AM
Very nice. Very hypnotic and also makes it look like there is a light source at the center point. Perhaps add a Stage.scaleMode = "noScale" into there to make it run faster. It sometimes lags a little bit since its so big.
EDIT: Definately make it smaller! I just resized my window to decrease its size, and it looks so much better with faster movement.

I only count 22 lines as it is. You probably counted the second EnterFrame function declaration too ElectricGrandpa ;)

And although you don't need to , do what EG suggested to save extra lines just in case you want to add stuff to it.

:thumb2:

J
01-16-2006, 03:14 AM
thats nice :)

icio
01-16-2006, 04:05 AM
Cool :thumb:

treatkor
01-16-2006, 06:49 AM
cool thanks for replies all.

I counted 23, but if you changed the last part from:

if (c<myRefArray.length) {
c++;
} else {
c = 0;
}

...to...

(c<myRefArray.length)? c++: c = 0;

...you'd save some lines.
i think i'll do that and add in a Stage.scaleMode="noScale";
thx for the tips.
i've seen some awesome code in this contest.

treatkor
01-16-2006, 06:56 AM
geez, after i went back and looked at my code again i realized i'd done a bunch of unnecessary stuff.

so here's a much improved version. should run faster even if you take out the noScale.


Stage.scaleMode = "noScale";
var randomNum = function (Min, Max) {
return Min+random(((Max+1)-Min));
};
var myRefArray = [];
var HH = this.createEmptyMovieClip("HH", this.getNextHighestDepth());
HH._x = HH._y=HH._xscale=HH._yscale=200;
onMouseDown = function () {
startRotate(randomNum(-30, 60), randomNum(-200, 200), 0);
};
startRotate = function (aaa, bbb, c) {
for (p=0, hw=0; p<30; p++, hw=(200/(p+1))+6) {
myRefArray[p] = HH.createEmptyMovieClip("cHH", 2000+p);
var eHH = myRefArray[p].createEmptyMovieClip("eHH", this.getNextHighestDepth()+1);
eHH.lineStyle(0.8, 0xFFFFFF, ((6*p)+6));
eHH.curveTo(hw*Math.cos(aaa), hw*Math.sin(bbb), hw*Math.cos(aaa), hw*Math.cos(bbb));
eHH.curveTo(hw*Math.cos(bbb), hw*Math.sin(aaa), 0, 0);
}
this.onEnterFrame = function() {
myRefArray[c].onEnterFrame = function() {
this._rotation += bbb;
};
(c<myRefArray.length) ? c++ : c=0;
};
};


so i think that's down to 15 lines now for basically the same effect.

squan
01-16-2006, 07:00 AM
Damn, looks really nice, would make an excellent mediaplayer-visualisation.