Deril
January 12th, 2006, 04:00 PM
Hello,
here is my little code...
move the mouse for better experience...
_root.totalcount = 0;
_root.stararray = [{altx:0, alty:-12}, {altx:3, alty:-3}, {altx:12.5, alty:-3}, {altx:5, alty:3}, {altx:7.5, alty:12}, {altx:0, alty:6.5}, {altx:-7.5, alty:12}, {altx:-5, alty:3}, {altx:-12.5, alty:-3}, {altx:-3, alty:-3}];
function drowstar(mc) {
mc.beginFill(random(16777215));
mc.moveTo(_root.stararray[0].altx, _root.stararray[0].alty);
for (id=1; id<_root.stararray.length; id++) {
mc.lineTo(_root.stararray[id].altx, _root.stararray[id].alty);
}
}
function startFirework(Cx, Cy) {
_root.totalcount++;
_root.createEmptyMovieClip((curentadres=('firework '+_root.getNextHighestDepth())), _root.getNextHighestDepth());
_root[curentadres]._x = Cx;
_root[curentadres]._y = Cy;
_root[curentadres]._xscale = _root[curentadres]._yscale=0;
_root[curentadres]._rotation = random(360);
_root[curentadres].onEnterFrame = function() {
this._yscale = this._xscale += (100-this._xscale)*(0.25+Math.random()*0.1);
this._x += (_root._xmouse-this._x)*0.1;
this._y += (_root._ymouse-this._y)*0.1;
if (this._yscale>95) {
if (_root.totalcount--<200) {
_root.startFirework(random(800), random(600));
_root.startFirework(random(800), random(600));
}
this.removeMovieClip();
}
};
_root.drowstar(_root[curentadres]);
}
_root.startFirework(400, 300);
have fun.
mpelland
January 12th, 2006, 04:01 PM
thats great.. gets pretty intense for me.
Deril
January 12th, 2006, 04:14 PM
if your pc lags... try changing....
if (_root.totalcount--<200) {
to
if (_root.totalcount--<100) {
less stars...
I didn't counted
"}"
as lines.. I hope thats ok.
kdd
January 12th, 2006, 05:00 PM
you're not supposed to count '}' and that's supposed to be in single quotes, it's a character. :P j/k
it's good i think...
NiñoScript
January 12th, 2006, 05:42 PM
yeah it lags here :P
but it looks good :)
Seb Hughes
January 14th, 2006, 01:38 PM
Wow very nice.
McGiver
January 15th, 2006, 06:58 AM
cool, looks like starfield simulation from the backside window of the spaceship :D
hybrid101
January 15th, 2006, 07:10 AM
pretty sweet! i also like the fact that it moves with the mouse!
Deril
January 19th, 2006, 10:51 AM
Hello.. i manage to find few hours beatwean my exams to flash a bit...
so here is my final version of StarCarousel
functions:
- generates random stars and animates toward the mouse
- has "buid in" FPS counter and tries to adapt to user pc for performance.. (50 stars still minimum.)
- Up/down keys can be uset to change speed and direction of animation...
(so its posible to see stars from fronside window of the spaceship... or even stop the spaship? :D )
// starCarusel in 25 lines (v2.1)
// Author: Raimundas Banevičius (Deril)
// 2006/01
// raima156@yahoo.com
// comment: presented in www.kirupa.com event - 25 Line AS Contest.
//
//
// description: generates field of stars and animates it toward the mouse.
// functions: star count will adapt for better performance (still.. no less then 50)
// press up/down to change animation (right/left, +/- also available)
//
//
//
// 1 (no scalefor better performance)
Stage.scaleMode = "noScale";
// (function for seting all variables from array to given object)
function multiSet(obj, variables) {
// 2
for (i=0; i<variables.length; i++) {
//3
obj[variables[i].Name] = variables[i].Value;
}
}
// 4 (init)
multiSet(_root, [{Name:'animEffectStr', Value:0.12}, {Name:'totalStarCount', Value:0}, {Name:'maxStarsAllowed', Value:150}, {Name:'stararray', Value:[{pointX:0, pointY:-12}, {pointX:3, pointY:-3}, {pointX:12.5, pointY:-3}, {pointX:5, pointY:3}, {pointX:7.5, pointY:12}, {pointX:0, pointY:6.5}, {pointX:-7.5, pointY:12}, {pointX:-5, pointY:3}, {pointX:-12.5, pointY:-3}, {pointX:-3, pointY:-3}, {pointX:0, pointY:-12}]}, {Name:'FPS', Value:0}, {Name:'bgBounds', Value:[[-2000, -2000], [-2000, 4000], [4000, 4000], [4000, -2000], [-2000, -2000]]}, {Name:'fpsParentTime', Value:0}, {Name:'onEnterFrame', Value:fpsCounter}]);
// {function draws a star from predefined array.}
// 5 drow backgrownd (to enshure its black)
for (_root.beginFill(0x000000); bgBounds.length != 0; _root.lineTo(bgBounds.shift()[0], bgBounds[0][1])) {
}
function drowStar(mc, colorToSet) {
// 6 (if colorToSet not passed - random collor, number generated to be lighter (for black background))
(colorToSet == 1) ? mc.beginGradientFill("radial", [0xFFffff, 0x000000], [100, 50], [0, 12], {a:200, b:0, c:0, d:0, e:200, f:0, g:0, h:0, i:1}) : mc.beginFill(((random(128)+128)*256*256)+((random( 128)+128)*256)+(random(128)+128));
//7
for (id=0; id<_root.stararray.length; mc.lineTo(_root.stararray[id++].pointX, _root.stararray[id].pointY)) {
}
}
// (create a star)
function starBirth(Cx, Cy) {
// 8 (this line defines star mc adders(curentadres) .. creates mc, drows star in it.. and sets all variables of it.. )
multiSet((_root.createEmptyMovieClip((curentadres= ('firework_'+(_root.totalStarCount++)+"_"+_root.getNextHighestDepth())), _root.getNextHighestDepth())), [{Name:'_x', Value:Cx}, {Name:'_y', Value:Cy}, {Name:'_xscale', Value:0}, {Name:'_yscale', Value:0}, {Name:'_rotation', Value:random(360)}, {Name:'onEnterFrame', Value:moveStar}, {Name:'onLoad', Value:drowStar(_root[curentadres])}]);
}
// function set for star onEnterFrame event listener.
function moveStar() {
// 9 (scale up.. )
this._yscale = this._xscale += (100-this._xscale)*(0.25+Math.random()*0.25);
// 10 (cheks the size, and total starcount, if more stars can be created - create 2 stars )
if ((this._yscale>95) && (_root.totalStarCount--<_root.maxStarsAllowed || _root.totalStarCount<50)) {
//11
_root.starBirth((400+(randomdist=random(800))*Math .sin(((randomdir=random(360))*Math.PI/180))), (300+randomdist*Math.cos((randomdir*Math.PI/180))));
//12
_root.starBirth((400+(randomdist=random(800))*Math .sin(((randomdir=random(360))*Math.PI/180))), (300+randomdist*Math.cos((randomdir*Math.PI/180))));
}
//13 (checks FPS.. if its ok... maxStarsAllowed is increased a bit. if pc performs bad.. maxStarsAllowed is reduced a bit )
_root.maxStarsAllowed += (_root.FPS>19) ? 0.1 : -0.1;
// 14 (cheks the size. if star is big enough its time to die.. otherwise. move toward the mouse..
(this._yscale>95) ? this.removeMovieClip() : multiSet(this, [{Name:'_x', Value:(this._x+(_root._xmouse-this._x)*_root.animEffectStr)}, {Name:'_y', Value:(this._y+(_root._ymouse-this._y)*_root.animEffectStr)}]);
}
// 15 (creates and sets listiner for key presses )
Key.addListener(keyL=new Object());
//
//( up/down ; right/left ; +/- ; keypresses will change animation speed and direction)
keyL.onKeyDown = function() {
// 16
(_root.animEffectStr>-0.9 && (Key.getCode() == 107 || Key.getCode() == 38 || Key.getCode() == 39)) ? _root.animEffectStr -= 0.03 : 0;
// 17
(_root.animEffectStr<2.5 && (Key.getCode() == 109 || Key.getCode() == 37 || Key.getCode() == 40)) ? _root.animEffectStr += 0.03 : 0;
// 18,19 ( creats a loop effect in animation )
((_root.animEffectStr>2.5) ? _root.animEffectStr -= 3 : 0);
((_root.animEffectStr<-0.9) ? _root.animEffectStr += 3 : 0);
};
/// ( little fps counter. sometimes not acurate, but avarage is what i nead. )
function fpsCounter() {
// 20
_root.FPS = (Math.round((1/(((_root.dr=getTimer())-_root.fpsParentTime)/1000))*1000)/1000);
// 21
_root.fpsParentTime = _root.dr;
}
// 22 (creating mouse pointer MC)
(_root.createEmptyMovieClip((mousePointerAdr='mous ePointer'), -10)).startDrag(true);
// 23 (seting variables.. to mausepointer)
multiSet(_root.mousePointer, [{Name:'_xscale', Value:500}, {Name:'_yscale', Value:500}, {Name:'onLoad', Value:drowStar(_root[mousePointerAdr], 1)}]);
// 24 (OMG... mouse is gone...!)
Mouse.hide();
// 25 (creates first 10 stars)
for (trace("Hello!, have fun with the script. :)"); _root.totalStarCount<10; _root.starBirth((400+(randomdist=random(800))*Math .sin(((randomdir=random(360))*Math.PI/180))), (300+randomdist*Math.cos((randomdir*Math.PI/180))))) {
}
ok.. back to my studies...
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.