00:00
00:00
Newgrounds Background Image Theme

Nue22 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Behold, I have created life!!!

6,087 Views | 75 Replies
New Topic Respond to this Topic

Behold, I have created life!!! 2008-03-01 03:55:14


Take a look at it. You may be thinking, "Well it's just an array. What's so special about it?". Well the fact is, it DNA (Kind of).

I took me about an hour of work, and It paid off. So what does it do? Well, it mimics natural selection.

Within each cell is an array, or "DNA" if you will. The DNA controls the cell's size, alpha, breed rate, life span, and movement speed. Each one of these determines how well it will survive and create a child.

You are the predator, simply clicking on the cell kills it, thus eliminating its chances of passing on it's genes. The cell spawns another cell with similar DNA.

Does it work? Why of course it does. After toying with it for about 5 minutes you may notice that the cells will become smaller, faster, and dimmer. I've even created an exact way to measure this. I added a

piece of the script that allows it to take the average of all the cells DNA.

Before Predation.

[1.474669232731685 ,2.845904463902116 ,137 ,137.63117529451847 ,0.3327539700549096]
[0.9836245548445731 ,2.0978369620162995 ,141.6 ,309.32201278591526 ,0.4108339709043505]
[0.9388599204986046 ,2.07245667312139 ,142.6 ,336.01265944987534 ,0.37586487626346465]
[0.8492967823068752 ,2.1645641694259314 ,136.6868686868686 ,369.6431425355582 ,0.36942785137492895]
[0.7653473002696409 ,2.222876532301307 ,134.33 ,398.6704018855188 ,0.3671380105968568]
[0.7174894966503453 ,2.3454245825877833 ,117.86734693877551 ,431.16441458188075 ,0.35961712562735704]

After Predation.

[0.7436614844272844 ,2.5163062159041876 ,104.91 ,467.1113160784869 ,0.4056801602789201]
[0.44020992366597056 ,2.712807661402039 ,55.35 ,523.4675777946459 ,0.39466535274544745]
[0.40022512410068883 ,2.8448938027000987 ,40.59 ,541.2977979342313 ,0.3946652915789749]
[0.32873030388262126 ,2.9693017766345293 ,26.55 ,561.1919197970303 ,0.415266771607567]
[0.3310742474603467 ,3.1435384194948712 ,13.55 ,570.9248711973149 ,0.460117161015049]
[0.2943195825838484 ,3.178501337370835 ,4.82 ,583.9013258700725 ,0.5005997988614255]
[0.23204775807913391 ,3.2680840010032988 ,1.12 ,598.3112366043217 ,0.5137212244248951]
[0.2121786629059352 ,3.2933589843381195 ,0 ,603.2740213429415 ,0.5167193985828198]
[0.1966122092306614 ,3.249354674380738 ,-0.56 ,608.7654778995364 ,0.5085924967420288]
[0.13454850030131638 ,3.286368337541353 ,-1.45 ,616.1810469966615 ,0.4986694704983383]
[0.12021581941284239 ,3.2749694645171985 ,-1.22 ,621.567563584121 ,0.491266982260626]
[0.07122604317963123 ,3.3480347882723436 ,0.59 ,633.716921256776 ,0.4904466022043488]

The gene that controll size drops from 1.5 all the way to .05, Speed goes from 2.8 to 3.4, breed rate plummets from 137 to .6, and life span soars to 633 frames. My removal of cells has made the cells

stronger.

I also tried letting the cells propagate without predation. Obviously, the only factions that would change are breed rate and life span. The cells bred for over 7 hours.

Begining...

[1.530007295543328,3.787272580782883,102 .5,169.49112610449083,0.2339601620566100 2]
[1.0825672084465623,3.7273768722079694,1 02,206.07285876804963,0.2045338894240558 7]
[1.2579387475270778,3.5530017025303096,9 2.13333333333334,239.73342795306817,0.20 837065533424426]
[1.2492524539516308,3.601782157656271,87 .81,270.70548023830634,0.218552806356456 13]
[1.320816197488457,3.638526942813769,81.
99,298.09045152280015,0.2074067045077681 9]
[1.1760452885041013,3.5770252447621895,7 1.3,324.4889749379596,0.1851644380046055 2]
[1.0118354496941901,3.4582938547781668,5 5.92,349.8691794113349,0.129299589278176 53]
[1.127776318253018,3.2301048750430343,33 .79,371.7566563213989,0.0378903872556984 9]
[1.3502308961749077,3.152440414270386,13 .19,390.9276788398251,-0.021900418109260 453]
[1.5124216491170228,3.1918537072930486,2 .61,407.6514052302297,-0.036766048204153 74]

End...

[4.965583989878651,2.9834561302955263,-0 .76,3697.7423830848143,0.465434645137282 55]
[4.980971449678764,3.0276264990493655,-0 .52,3698.7742001862034,0.458982656161299 46]
[4.947543821381405,3.074515298125334,-1.
05,3699.6520629651936,0.4546139568928612 7]
[4.922342830754351,3.042213344096672,-0.
66,3700.437108122036,0.45440934227173985 ]
[4.978031043543015,3.0298157997080124,-1 .05,3702.040093773934,0.4372694892701677 3]
[4.983746115211398,3.0202037557261066,-1 .09,3703.236686241012,0.4409239029036819 4]
[4.979713250799104,3.038325157689396,-1.
4,3704.16662720575,0.4381305619454928]

The breed rate goes from 102 to 1.4 (Absolute Value), and the average life span soars to 3700 frames!!!

Here is the flash. (Give the cells time to multiply before killing, and sometimes the breed rate is higher than the life span, so just reload the page.)

Continued...


[ Proxi ::: Life ::: AS3 ]

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 03:56:29


CODE: ( There's is only this code and one movie clip with instance name "cell_link")

/*Note: I could just say "Array", "Variable", and "Movie Clip" insted of "DNA", "Gene", and "Cell"; but that wouldn't sound nearly as awesome.*/

var cells:Array = new Array();
var average_DNA:Array = new Array();
var inc:int = 0;

// Initiatives, woo!!!

var right:Number = stage.stageWidth;
var bottom:Number = stage.stageHeight;

// Sets the original screen size, so rezising the window doesn't mess with anything.

function addCell(xcor:Number,ycor:Number,area:Number,speed:Number,breed_rate:Number,life_span:Number,visibility:Number) {

	var cell:cell_link = new cell_link();
	cells.push(cell);
	stage.addChild(cell);
	cell.x = xcor;
	cell.y = ycor;
	cell.scaleX = cell.scaleY = area;
	cell.alpha = visibility;
	cell.timer = 0;
	cell.DNA = new Array(area, speed, breed_rate,life_span, visibility);

}

// Sets a function for the addition of cells to reduce clutter.

addCell(Math.random()*right,Math.random()*bottom,Math.random()*1.5,Math.random()*5,Math.round(Math.random()*90)+70,Math.random()*50+100,Math.random()/2+.25);

// Adds the initial, "eve", cell.

stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);

function mouseDown(evnt:MouseEvent):void {

	for (inc = 0; inc<cells.length; inc++) {
		var cell:MovieClip = cells[inc] as MovieClip;
		if (cell.hitTestPoint(mouseX,mouseY,true)) {
			cells.splice(inc,1);
			cell.parent.removeChild(cell);
		}
	}

}

// After trying and failing to make a dynamic "press" event listener for each cell, I gave up and just used a hitTestPoint on every cell to see if they've been clicked.


stage.addEventListener(Event.ENTER_FRAME, enterFrame);

function enterFrame(evnt:Event):void {

	for (inc = 0; inc<cells.length; inc++) {
		var cell_cur:MovieClip = cells[inc] as MovieClip;

		// Specifying each cell for actions.

		cell_cur.timer++;

		// Timer increment.

		cell_cur.x += Math.random()*cell_cur.DNA[1]-cell_cur.DNA[1]/2;
		cell_cur.y += Math.random()*cell_cur.DNA[1]-cell_cur.DNA[1]/2;

		// Moves cell according to the speed gene in the individual cells DNA.

		if (cell_cur.timer%cell_cur.DNA[2]==0 && cells.length<100) {
			addCell(cell_cur.x,cell_cur.y,cell_cur.DNA[0]+Math.random()/2-.25,cell_cur.DNA[1]+Math.random()/2-.25,Math.round(cell_cur.DNA[2]+Math.random()*20-10),cell_cur.DNA

[3]+Math.random()+20-10,cell_cur.DNA[4]+Math.random()/10-.05);

			// Spawns a new cell at the rate the breed_rate gene allows with DNA similar to the mothers.
			// The "if" also checks if they're less than 100 cells on the stage so there isn't an overload.


		}
		if (cell_cur.timer>cell_cur.DNA[3]) {
			cells.splice(inc,1);
			cell_cur.parent.removeChild(cell_cur);

			// Kills cell when the life_span gene says so.


		}
		if (cell_cur.x<0) {
			cell_cur.x = right;
		}
		if (cell_cur.y<0) {
			cell_cur.y = bottom;
		}
		if (cell_cur.x<0) {
			cell_cur.x = right;
		}
		if (cell_cur.y>bottom) {
			cell_cur.y = 0;
		}
		//Makes sure the cells don't go out of reach and breed where they can't be killed.

	}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);

function keyDown(evnt:KeyboardEvent):void {

	if (evnt.keyCode == 32) {
		average_DNA = new Array(0,0,0,0,0);
		for (inc = 0; inc<cells.length; inc++) {
			var cell:MovieClip = cells[inc] as MovieClip;
			average_DNA[0] += cell.DNA[0];
			average_DNA[1] += cell.DNA[1];
			average_DNA[2] += cell.DNA[2];
			average_DNA[3] += cell.DNA[3];
			average_DNA[4] += cell.DNA[4];
		}
		average_DNA[0] /= cells.length;
		average_DNA[1] /= cells.length;
		average_DNA[2] /= cells.length;
		average_DNA[3] /= cells.length;
		average_DNA[4] /= cells.length;
		trace("["+average_DNA+"]");
	}

}

// Checks to see if you pressed space at which point it will gather the average of all the cells DNA to see how the species is doing as a whole.

I've never seen anything like this before, let alone by anyone my age. I'm so proud.


[ Proxi ::: Life ::: AS3 ]

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 04:16:50


uhh...looks kinda cool, you may want to speed it up a bit though...

...but nice work!


If you like, or dislike my comments, or submissions on this site...write about it in my forum/feedback page

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 04:17:40


That is some really neat scripting. And a damn nice idea.


BBS Signature

Response to Behold, I have created life!!! 2008-03-01 04:36:22


At 3/1/08 04:17 AM, Hoeloe wrote: That is some really neat scripting. And a damn nice idea.

Thanks. I'd like to think it was the first done with AS

At 3/1/08 04:16 AM, webcrawler559 wrote: uhh...looks kinda cool, you may want to speed it up a bit though...

...but nice work!

You mean speed up the "metabolism"?


[ Proxi ::: Life ::: AS3 ]

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 05:33:57


That's pretty awesome, actually. It's fun to specifically cull small or transparent or opaque or whatever ones and watch it as they all go to the opposite of the characteristic.

Very cool little thing you got there.

Now i challenge you to make it into a game, with perhaps objectives like "make them all over a certain size" or whatever :)


Just click the sig, idiot.

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 05:51:29


At 3/1/08 05:33 AM, Lard-lad wrote: That's pretty awesome, actually. It's fun to specifically cull small or transparent or opaque or whatever ones and watch it as they all go to the opposite of the characteristic.

Very cool little thing you got there.

Now i challenge you to make it into a game, with perhaps objectives like "make them all over a certain size" or whatever :)

Seems like it'd be boring, no matter how "action packed" I tried to make it. This was originally going to be a science project, but I changed my mind because I thought it was a waste of effort.


[ Proxi ::: Life ::: AS3 ]

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 06:17:03


Wow, this must be one of the most amazing things I've ever seen done in Flash. If only I had CS3 I could toy around with the code. At the moment I'm busy breeding my tiny 3 pixel cells :p .

May I suggest adding different colours to it next?


...

Response to Behold, I have created life!!! 2008-03-01 06:34:32


Wow, that seems impressive, but what am I meant to be seeing in the flash file? All I have is a white screen.

Response to Behold, I have created life!!! 2008-03-01 06:41:53


At 3/1/08 06:34 AM, Yhtomit wrote: Wow, that seems impressive, but what am I meant to be seeing in the flash file? All I have is a white screen.

Keep refreshing, sometimes the first cell dies before it can reproduce.


...

Response to Behold, I have created life!!! 2008-03-01 06:48:26


That is freaking awesome. I always love things like this. Like spore the game. keep it up.

Response to Behold, I have created life!!! 2008-03-01 07:23:19


Hm....That's very interesting, I mean I know just noting about programing even a button, and you've done something great, I think you could make a nice game of that, you can put it into a fighting game, like a hit that creates circles like that that damages the enemy, or small explotions, but just make the spawn rate higher. Anyway, that's terrific!javascript:MakeSmileySelection(
15);
Elated

Response to Behold, I have created life!!! 2008-03-01 07:32:10


Wow, that is really cool. :) I wonder if more advanced programming could produce more intelligent life that runs from the cursor. The possibilities....

Response to Behold, I have created life!!! 2008-03-01 07:43:49


At 3/1/08 07:32 AM, Yhtomit wrote: Wow, that is really cool. :) I wonder if more advanced programming could produce more intelligent life that runs from the cursor. The possibilities....

Of course it can, and your 6 responses have inspired me to make something better out of this.


[ Proxi ::: Life ::: AS3 ]

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 07:52:41


Hehe, I was planning on making something similar to this, but with bitmap data and different zones so you could see different areas of life adapting to different environments. Yours is really creative, though, and full gratz for actually doing it :)


BBS Signature

Response to Behold, I have created life!!! 2008-03-01 07:56:46


I'm stuck on one part. I'm trying to add a "color gene" where the color of the cell is determined by:

color_gene * 0xFFFFFF

But the color varies greatly just by the slightest change in the the color_gene, and I'm looking for a gradual change.

I'm sure the answer lies in hexadecimal and binary operators, but those are my weak spots. Help?


[ Proxi ::: Life ::: AS3 ]

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 08:21:00


At 3/1/08 07:56 AM, FiqStudios wrote: I'm stuck on one part. I'm trying to add a "color gene" where the color of the cell is determined by:

color_gene * 0xFFFFFF

But the color varies greatly just by the slightest change in the the color_gene, and I'm looking for a gradual change.

I'm sure the answer lies in hexadecimal and binary operators, but those are my weak spots. Help?

I don't know about the actual code, but you could have arrays of 'color families' say, one array of the hexadecimal values of greenish colors and when the gene changes just select a different color from that array. And maybe if you have like a dark green it could jump from the green array to the blue array and use a dark blue.

I dunno, good luck anyway with the coding.


...

Response to Behold, I have created life!!! 2008-03-01 08:43:34


I think I have two similar species co-existing on this simulation. Proof:

Behold, I have created life!!!

Response to Behold, I have created life!!! 2008-03-01 09:01:38


At 3/1/08 07:56 AM, FiqStudios wrote: I'm stuck on one part. I'm trying to add a "color gene" where the color of the cell is determined by:

color_gene * 0xFFFFFF

But the color varies greatly just by the slightest change in the the color_gene, and I'm looking for a gradual change.

I'm sure the answer lies in hexadecimal and binary operators, but those are my weak spots. Help?

You need 3 separate color genes for r, g, and b

gene1+gene2*0xFF+gene3*0xFFFF

cull the color gene to 0 to 256

Response to Behold, I have created life!!! 2008-03-01 09:07:12


At 3/1/08 09:01 AM, Glaiel-Gamer wrote: You need 3 separate color genes for r, g, and b

gene1+gene2*0xFF+gene3*0xFFFF

If you want to be cool (and probably more efficient), you can use bitwise operators instead of multiplying by hex values:

var red:uint = blah;
var green:uint = blah;
var blue:uint = blah;
var colour:uint = ((red << 16) + (green << 8) + blue);

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 13:18:51


world tycoon! Run your own world, choose your own species, see if they survive....

I dunno, only game I could come up with using these scripts :P


sig'd

Response to Behold, I have created life!!! 2008-03-01 13:31:19


I <3 evolution games.
You could try adding an "aggressive" variable - one extreme is timid, the other extreme is a predator itself.
Is there a randomness factor in there? Every so often something should breed another one with completely different values from itself.


____________________________Bel-Air remixes! You must listen!____________________________

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 13:34:42


This is a life simulation as I've never seen it before. Usually, I see life simulations as boxes that reproduce and die out or something. This is comparably intense.

Yes, it's boring. But evolution has a tendency to be boring. I suggest you make environmental variable, like a place where it's hot and a place where it's cold, make a DNA thing that gives the cell a preference to temperature. Also, though this is a bit advanced, make a multicellular being? But that's a bit ahead of thinking.

So far, the best evo-sim I've seen. Bravo.

Response to Behold, I have created life!!! 2008-03-01 13:40:35


you should have it mutate and evolve.

Response to Behold, I have created life!!! 2008-03-01 13:53:00


Not bad but you are definatelly not the first to use genetic algorithms in flash. I basically made some ants with a neural network and neural networks also make use of genetic algorithms (dna natural selection mutation ect.) to make the learning possible. Not to mention other similar things done.

cheers ^^

Response to Behold, I have created life!!! 2008-03-01 14:03:54


At 3/1/08 01:40 PM, willobeen wrote: you should have it mutate and evolve.

..... That's what he's doing....

Response to Behold, I have created life!!! 2008-03-01 14:42:43


Wow, I had and idea like this after re-learning about blood for midterms... My idea was to have white blood cells, viruses, antibodies, killer T's, various types of blood cells, and more. The blood cells were going to have the ability to mutate good or bad, and reproduce. White blood cells fighting off viruses, fighting with existences of killer T's... Etc, etc.

What you did seems pretty cool though, a great idea. I would love to see this made into a game, but it would be sorta hard to make it fun. Maybe then a gadget of some sort?


BBS Signature

Response to Behold, I have created life!!! 2008-03-01 15:31:58


At 3/1/08 08:43 AM, Yhtomit wrote: I think I have two similar species co-existing on this simulation. Proof:

No true to real life then. Lol.

Response to Behold, I have created life!!! 2008-03-01 15:57:46


maybe u could have this organism inside a blood vessel, and have the immune system try to fight it off, but have a very great chance of being over run. Like have blood and tissue cells float by and have this organism infect them, then have the macrophages come and eat a couple cells before the organism tries to fight it off. Then itd be an awesome fight, have a limit of like about 100,000,000,000 red blood cells lol. And see if the organism can survive long enough to face the deadliest thing to a virus; ANTIBODIES!!! Which would in turn practically annhialate the virus if its not strong enough. Meh, just a thought, sounds kind of hard though.


True story...

BBS Signature

Response to Behold, I have created life!!! 2008-03-01 16:08:39


March 1st, 2008, 1:04pm.

I have witnessed an uncommon phenomenon. The unspecified multi-cellular organism (UNSPEC 1) has devided into another multi-cellular organism (UNSPEC 2). Whether or not these Unspecified organisms will attempt to invade eachother is a complete mystery. But as of now the life span of the UNSPEC 2 seems surprisingly shorter, and is failing to reproduce as quickly as UNSPEC 1. As UNSPEC 2 continues to shrink in size and cell density, UNSPEC 1 continues to devide much quicker and into much, much larger cells. I fear the life of UNSPEC 2 is near an end.

Behold, I have created life!!!


True story...

BBS Signature