PDA

View Full Version : Worm


joca
04-18-2004, 05:18 PM
Theme : WORM

My code (ftp://217.129.27.250/Worm5.html)...(set Stage to 40 fps, black background)...


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();
}
}


joca :)

pom
04-22-2004, 01:54 PM
Long live the worm!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;

joca
04-22-2004, 02:43 PM
Cool... :)

joca

farafiro
05-16-2004, 07:08 AM
POM
what's the problem??
copied/pasted the code
seen nothing??

McGiver
05-16-2004, 08:19 AM
@faffy: works fine in flash 6.
You just have to wait some time

farafiro
05-16-2004, 08:33 AM
wooooooooooooooh
this is very cool POM

but why didn't work in Flash Player 7??
now this is the question

McGiver
05-16-2004, 11:34 AM
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 :)

McGiver
05-16-2004, 11:59 AM
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.


///////////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);
};

farafiro
05-17-2004, 01:21 AM
ehm
started feeling wormy
heheheeeeee

very cool one Mc

pom
05-22-2004, 06:21 AM
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 :D

McGiver
05-22-2004, 07:21 AM
hehee the original code is from my entry to the fish contest at Kirupa long time ago, and when I modified it even I had probems reading my old script, so maybe the code is really a little messed up. :D