Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with random function

Status
Not open for further replies.

iostream71

Programmer
Mar 13, 2002
229
US
i want to make some stars and have them twinkle randomly. this is what i have so far:

just duplicating a single star MC 100 times and randomly placing...but i'm not sure how to make them twinkle randomly

for(i = 0; i < 100; i++){
duplicateMovieClip(star, 'star' + i, i);
xHigh = 699;
xLow = 1;
yHigh = 1;
yLow = 171;
alphaHigh = 100;
alphaLow = 10;
randAlpha = Math.floor(Math.random() * (alphaHigh - alphaLow)) + alphaLow;
randX = Math.floor(Math.random() * (xHigh - xLow)) + xLow;
randY = Math.floor(Math.random() * (yHigh - yLow)) + yLow;
_root['star' + i]._x = randX;
_root['star' + i]._y = randY;
_root['star' + i]._alpha = randAlpha;
}

 
What if the original star clip is a continuously rotating clip to start with? Regards,

cubalibre2.gif
 
hmm...i tried something like that, but they all blink at the same rate. i was wanting it to be more random
 
it looks like your code is just giving each star a random alpha. for twinkle the alpha must change (randomly if you wish)

twinkle = setInterval(shine,50);

function shine(){
for(i = 0; i < 100; i++){
randAlpha = Math.floor(Math.random() * (alphaHigh - alphaLow)) + alphaLow;
_root['star' + i]._alpha = randAlpha;
}


dont forget to clear the interval at some stage.
 
I would like to keyframe this starfield. I created this starfield (the duplicated movie clips) in a movie clip called "MC_stars". But when I placed it on the main timeline, keyframed it, and tested the movie, only 1 star showed up (none of the other duplicates showed up).

Any ideas?

Here's my code for "MC_stars":

for(i = 0; i < 200; i++){
duplicateMovieClip(introstar, 'introstar' + i, i);
xHigh = 999;
xLow = 1;
yHigh = 1;
yLow = 299;
alphaHigh = 60;
alphaLow = 40;
xscaleHigh = 150;
xscaleLow = 50;
yscaleHigh = xscaleHigh;
yscaleLow = xscaleLow;
randAlpha = Math.floor(Math.random() * (alphaHigh - alphaLow)) + alphaLow;
randxScale = Math.floor(Math.random() * (xscaleHigh - xscaleLow)) + xscaleLow;
randyScale = randxScale;
randX = Math.floor(Math.random() * (xHigh - xLow)) + xLow;
randY = Math.floor(Math.random() * (yHigh - yLow)) + yLow;
_root['introstar' + i]._x = randX;
_root['introstar' + i]._y = randY;
_root['introstar' + i]._alpha = randAlpha;
_root['introstar' + i]._xscale = randxScale;
_root['introstar' + i]._yscale = randyScale;
}

twinkle = setInterval(shine,100);

function shine(){
for(i = 0; i < 200; i++){
randAlpha = Math.floor(Math.random() * (alphaHigh - alphaLow)) + alphaLow;
_root['introstar' + i]._alpha = randAlpha;
}
}

By the way, this creates some killer twinkling stars!

-Skeletrooper
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top