| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: Apr 2004
Location: Portugal
Posts: 2
|
Theme : WORM
My code...(set Stage to 40 fps, black background)... Code:
count = 0;
j = 0;
k = 0;
dx = 0;
dt = 0;
dy = 0;
w = 25;
d = w/1.68;
angle = 0;
xcenter = 270;
ycenter = 200;
aa = Math.random()*6;
ab = Math.random()*6;
ac = Math.random()*6;
onEnterFrame = function () {
red = Math.sin(aa += .09)*128+127;
green = Math.sin(ab += .06)*128+127;
blue = Math.sin(ac += .03)*128+127;
myCol = red << 16 | green << 8 | blue;
dx = Math.sin(dt/33)*Math.sin(dt/9+20)*Math.sin(dt/15)*175;
dy = Math.sin(dt/50+0.7)*Math.sin(dt/9)*Math.sin(dt/13+2)*175;
dt += .175;
j += .05;
draw(0, 0);
};
function draw(x, y) {
mc= createEmptyMovieClip("mc"+count, count++);
mc._x = xcenter+dx;
mc._y = ycenter+dy;
mc.lineStyle(w, myCol, 100);
mc.moveTo(x-d, y-d);
mc.lineTo(x+d, y+d);
mc._rotation = Math.sin(angle+=.0005)*360;
mc.x = 0;
mc.onEnterFrame = control;
}
function control() {
this._yscale = this._xscale-=.75;
this._rotation += Math.sin(j*2)*Math.sin(j/8)*4+Math.cos(2*j)*4
this.x++;
if (this.x>50) {
this.removeMovieClip();
}
}
![]() Last edited by joca; 04-22-2004 at 03:10 AM.. Reason: Add a link |
|
|
|
|
|
#2 |
|
Allez les Bleus!!!
Join Date: Oct 2002
Location: Paname
Posts: 2,495
|
Long live the worm!
Code:
Mouse.hide();
/*** Variables ***/
amplitudes = [] ;
amp = 40 ;
size = 20 ;
incr_red = Math.random() / 10 ;
incr_green = Math.random() / 10 ;
incr_blue = Math.random() / 10 ;
a = 0.1 ;
for (var p=0; p < size; p++) {
amplitudes.push(amp*Math.sin(a += Math.PI/(size+1))) ;
}
myClips=[];
friction=.96;
amplitudeBrown=.45;
amplitudeSpring=.002;
radius=80;
nClip=7;
depth=100;
centre = {x:250, y:200}
function init (){
this.createEmptyMovieClip("container", 0) ;
container.createEmptyMovieClip("d",0)._visible=0;
for (var p=0;p < nClip;p++){
myClips.push(container.d.duplicateMovieClip("d"+p,p+1));
myClips[p].centx=radius*Math.cos(p*Math.PI*2/nClip);
myClips[p].centy=radius*Math.sin(p*Math.PI*2/nClip);
myClips[p].onEnterFrame=effect;
};
};
function grow () {
this.ind ++ ;
if (this.ind < amplitudes.length) {
var dx = _xmouse-centre.x ;
var dy = _ymouse-centre.y ;
this._x += d_x / 30 ;
this._y += d_y / 30 ;
this._xscale = this._yscale = amplitudes[this.ind] ;
}
else {
this.removeMovieClip () ;
}
};
MovieClip.prototype.effect=function(){
this.loop++;
this.loop=this.loop % 5;
if (!this.loop) {
this.brownX = (Math.random() - .5) * amplitudeBrown;
this.brownY = (Math.random() - .5) * amplitudeBrown;
};
var springX = amplitudeSpring * (this.centx - this._x);
var springY = amplitudeSpring * (this.centy - this._y);
this.velX += springX + this.brownX;
this.velY += springY + this.brownY;
this.velX *= friction;
this.velY *= friction;
this._x += this.velX;
this._y += this.velY;
};
function drawShape(){
var mc=container.createEmptyMovieClip("c"+(++depth),depth);
d_x = _xmouse - pos_x ;
d_y = _ymouse - pos_y ;
pos_x += d_x / 7 ;
pos_y += d_y / 7 ;
mc._x = pos_x ;
mc._y = pos_y ;
// mc.lineStyle(0, 0x999999, 50);
var red = 127 * (1 + Math.sin(angle1 += incr_red)) ;
var green = 127 * (1 + Math.sin(angle2 += incr_green)) ;
var blue = 127 * (1 + Math.sin(angle3 += incr_blue)) ;
var colRand = red << 16 | green << 8 | blue ;
mc.beginFill(colRand, 100);
var end = [] ;
for (j=0; j < nClip; j++) {
var dx = (myClips[j]._x + myClips[(j+1)%nClip]._x) / 2 ;
var dy = (myClips[j]._y + myClips[(j+1)%nClip]._y) / 2 ;
end.push({x:dx, y:dy}) ;
};
this.clear() ;
mc.moveTo(end[0].x, end[0].y) ;
for (j=1; j <= nClip; j++){
mc.curveTo(myClips[j%nClip]._x, myClips[j%nClip]._y, end[j%nClip].x, end[j%nClip].y);
};
mc.endFill();
mc.ind = 0 ;
mc._xscale = mc._yscale = amplitudes[mc.ind] ;
mc.onEnterFrame = grow ;
};
init();
this.onEnterFrame=drawShape;
|
|
|
|
|
|
|
|
|
#3 |
|
Registered User
Join Date: Apr 2004
Location: Portugal
Posts: 2
|
Cool...
joca |
|
|
|
|
|
#4 |
|
Addicted To FLASH
|
POM
what's the problem?? copied/pasted the code seen nothing??
__________________
â€* GOD Is Near â€* Questions Don't PM for Questions An eye for an eye, make the whole world blind _____________________________________________GHANDI |
|
|
|
|
|
#5 |
|
Goldmember
Join Date: Feb 2003
Location: bavaria in germany
Posts: 1,627
|
@faffy: works fine in flash 6.
You just have to wait some time |
|
|
|
|
|
#6 |
|
Addicted To FLASH
|
wooooooooooooooh
this is very cool POM but why didn't work in Flash Player 7?? now this is the question
__________________
â€* GOD Is Near â€* Questions Don't PM for Questions An eye for an eye, make the whole world blind _____________________________________________GHANDI |
|
|
|
|
|
#7 |
|
Goldmember
Join Date: Feb 2003
Location: bavaria in germany
Posts: 1,627
|
Flash 7 player will not accept someting like
i++ or i+=10 if i hasn't been declared before by the way, i'm creating an own one at the moment if I am allowed to ![]() |
|
|
|
|
|
#8 |
|
Goldmember
Join Date: Feb 2003
Location: bavaria in germany
Posts: 1,627
|
ok, my worm is finished.
I call it Flashy, you will recognize why when you run it. Flashy will circle clockwise around the cursor, slowly decreasing the radius. I am sure you will get used to controlling him. If Flashy eats his food (a flashing worm will obviously eat flashing drops as food) he will grow. While he is digesting the food, a dent will wander through Flashy's body. Code:
///////////Flashy-Worm by Roland Plass/////////////
function getangle(x, y) {
angle = Math.atan(y/x)/(Math.PI/180);
if ((0<=x)) {
angle = angle+180;
}
if (0<=x && 0<=y) {
angle = angle+360;
}
return (angle);
}
mpointarr = [250, 250, 250, 250];
_root.opointarr = [];
wormarray = [];
wormarray0 = [0, 0];
for (i=0; i<28; i++) {
wormarray0.push(-0.0001*Math.pow(i-14, 4)+4);
}
eatenarr = [];
createEmptyMovieClip("food", 20);
food.lineStyle(13, 0, 50);
food.lineTo(1, 0);
food.createEmptyMovieClip("inner", 20);
_root.createEmptyMovieClip("worm", 100);
food._x = random(600)+50;
food._y = random(600)+50;
_root.onEnterFrame = function() {
if (_root.food.hitTest(mpointarr[mpointarr.length-2], mpointarr[mpointarr.length-1], true)) {
food._x = random(600)+50;
food._y = random(600)+50;
eatenarr.push(wormarray0.length-2);
wormarray0.splice(Math.round(wormarray0.length/2), 0, wormarray0[Math.round(wormarray0.length/2)-1]);
}
wormarray = wormarray0.concat();
for (i_e in eatenarr) {
eatenarr[i_e] -= 0.1;
for (i_a in wormarray0) {
wormarray[i_a] *= (1+1/(0.1*Math.pow(i_a-eatenarr[i_e], 4)+(10+(wormarray0.length-eatenarr[i_e]))/17));
}
if (eatenarr[i_e]<=1) {
eatenarr.splice(i_e, 1);
}
}
wormcol = random(0xFFFFFF);
food.inner.clear();
food.inner.lineStyle(11, wormcol, 100);
food.inner.lineTo(1, 0);
n += 0.4;
x = _xmouse-mpointarr[i];
y = mpointarr[i+1]-_ymouse;
npangle = getangle(x, y);
mpointarr.push(Math.sin((npangle-15)*Math.PI/180)*5+mpointarr[i+2]);
mpointarr.push(Math.cos((npangle-15)*Math.PI/180)*5+mpointarr[i+3]);
if (mpointarr.length>wormarray.length*2) {
mpointarr.splice(0, mpointarr.length-wormarray.length*2);
}
if (opointarr.length>wormarray.length*2) {
opointarr.splice(0, opointarr.length-wormarray.length*2);
}
_root.worm.clear();
for (i=0; i<_root.mpointarr.length-4; i += 2) {
x = _root.mpointarr[i]-_root.mpointarr[i+2];
y = _root.mpointarr[i+3]-_root.mpointarr[i+1];
angle = getangle(x, y);
ax1 = Math.sin(angle*Math.PI/180)*wormarray[i/2+2]+_root.mpointarr[i+2];
ay1 = Math.cos(angle*Math.PI/180)*wormarray[i/2+2]+_root.mpointarr[i+3];
ax3 = Math.sin((angle+180)*Math.PI/180)*wormarray[i/2+2]+_root.mpointarr[i+2];
ay3 = Math.cos((angle+180)*Math.PI/180)*wormarray[i/2+2]+_root.mpointarr[i+3];
x = _root.mpointarr[i+2]-_root.mpointarr[i+4];
y = _root.mpointarr[i+5]-_root.mpointarr[i+3];
angle2 = getangle(x, y);
ax0 = Math.sin(angle2*Math.PI/180)*wormarray[i/2+3]+_root.mpointarr[i+4];
ay0 = Math.cos(angle2*Math.PI/180)*wormarray[i/2+3]+_root.mpointarr[i+5];
ax2 = Math.sin((angle2+180)*Math.PI/180)*wormarray[i/2+3]+_root.mpointarr[i+4];
ay2 = Math.cos((angle2+180)*Math.PI/180)*wormarray[i/2+3]+_root.mpointarr[i+5];
_root.opointarr.push(ax1);
_root.opointarr.push(ax2);
_root.worm.lineStyle(1, 0, 50);
_root.worm.beginFill(wormcol, 100);
_root.worm.moveTo(ax1, ay1);
_root.worm.lineTo(ax0, ay0);
_root.worm.lineStyle(0, 0, 0);
_root.worm.curveTo(_root.mpointarr[i+2], _root.mpointarr[i+3], ax2, ay2);
_root.worm.lineStyle(1, 0, 50);
_root.worm.lineTo(ax3, ay3);
_root.worm.lineStyle(0, 0, 0);
_root.worm.curveTo(_root.mpointarr[i], _root.mpointarr[i+1], ax1, ay1);
_root.worm.endFill();
}
_root.worm.lineStyle(1, 0, 50);
};
|
|
|
|
|
|
#9 |
|
Addicted To FLASH
|
ehm
started feeling wormy heheheeeeee very cool one Mc
__________________
â€* GOD Is Near â€* Questions Don't PM for Questions An eye for an eye, make the whole world blind _____________________________________________GHANDI |
|
|
|
|
|
#10 |
|
Allez les Bleus!!!
Join Date: Oct 2002
Location: Paname
Posts: 2,495
|
I eventually managed to see your worm, Mc, and it's really good! I wanted to modify the code to make the change of direction a bit smoother, but it's too obfuscated for me
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|