Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Community Boards > Just for Kicks Challenges

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-18-2004, 06:18 PM   #1
joca
Registered User
 
joca's Avatar
 
Join Date: Apr 2004
Location: Portugal
Posts: 2
Smile Worm

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

Last edited by joca; 04-22-2004 at 03:10 AM.. Reason: Add a link
joca is offline   Reply With Quote
Old 04-22-2004, 02:54 PM   #2
pom
Allez les Bleus!!!
 
pom's Avatar
 
Join Date: Oct 2002
Location: Paname
Posts: 2,495
Default

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;
pom is offline   Reply With Quote
Old 04-22-2004, 03:43 PM   #3
joca
Registered User
 
joca's Avatar
 
Join Date: Apr 2004
Location: Portugal
Posts: 2
Default

Cool...

joca
joca is offline   Reply With Quote
Old 05-16-2004, 08:08 AM   #4
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: EGYPT
Posts: 12,439
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

POM
what's the problem??
copied/pasted the code
seen nothing??
__________________
â€* GOD Is Near â€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 05-16-2004, 09:19 AM   #5
McGiver
Goldmember
 
McGiver's Avatar
 
Join Date: Feb 2003
Location: bavaria in germany
Posts: 1,627
Default

@faffy: works fine in flash 6.
You just have to wait some time
McGiver is offline   Reply With Quote
Old 05-16-2004, 09:33 AM   #6
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: EGYPT
Posts: 12,439
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

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 . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 05-16-2004, 12:34 PM   #7
McGiver
Goldmember
 
McGiver's Avatar
 
Join Date: Feb 2003
Location: bavaria in germany
Posts: 1,627
Default

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 is offline   Reply With Quote
Old 05-16-2004, 12:59 PM   #8
McGiver
Goldmember
 
McGiver's Avatar
 
Join Date: Feb 2003
Location: bavaria in germany
Posts: 1,627
Default

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);
};
McGiver is offline   Reply With Quote
Old 05-17-2004, 02:21 AM   #9
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: EGYPT
Posts: 12,439
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

ehm
started feeling wormy
heheheeeeee

very cool one Mc
__________________
â€* GOD Is Near â€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
farafiro is offline   Reply With Quote
Old 05-22-2004, 07:21 AM   #10
pom
Allez les Bleus!!!
 
pom's Avatar
 
Join Date: Oct 2002
Location: Paname
Posts: 2,495
Default

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
pom is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:17 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.