View Full Version : Artificial life
McGiver
06-13-2003, 06:59 PM
Ok: new task!
the title tells what to do!
Create artificial life! (or at least something that looks or behaves like AL (artificial life))
every idea is welcome: simple or complicated!
the rules:
same rules as ever!
with one exeption: a 40 line maximum (I think this is should be enough to create something useful)
anyone something to add? No?
then let's play god :D
senocular
06-16-2003, 06:43 PM
this one really shot off didnt it :D
McGiver
06-16-2003, 08:08 PM
Pom forced me to do.... :(
hmm, i do not know, what you want!
4 Days of contest, and 1 reply! Seems this theme is really popular:D :D :D
senocular
06-16-2003, 08:31 PM
well I think
1) AL is intimidating enough as it is on its own
and
2) 40 lines for anything AL is pretty minimal and intimidating for that matter.
;)
McGiver
06-16-2003, 08:38 PM
come on guys, is this really too untintresting or complicated for you? Ok, I'll create something till tomorrow (or till wednesday)
and you think about it too!? is that a deal?
senocular
06-16-2003, 08:43 PM
3) wheres yours... oh ok, tomorrow or wednesday huh? ok ok ok ;)
senocular
06-17-2003, 02:24 AM
ok, here's one for me. Whipped it up tonight - a respectable 14 lines :D
this.onEnterFrame = function(){
for(var i=1;i<=10;i++) this["weed "+i].addRoot(i);
};
this.addWeed = function(i, k){
this.createEmptyMovieClip("weed "+i,i).lineStyle(k, Math.random()*0xff << 8, 25+random(65));
this["weed "+i].pos = {x:random(10)*30, y:random(10)*30};
};
for (i=1;i<=10;i++) this.addWeed(i);
MovieClip.prototype.addRoot = function(i){
this.moveTo(this.pos.x,this.pos.y);
this.lineTo((x=random(10)*30), (y=random(10)*30));
trace((i==1) ? "------------------\n"+this._name+" lifespan: "+(++this.life)+", kills: "+this.kills : this._name+" lifespan: "+(++this.life)+", kills: "+this.kills);
for (var i=1;i<=10;i++) if (this != this._parent["weed "+i] && this._parent["weed "+i].pos.x == x && this._parent["weed "+i].pos.y == y) this._parent.addWeed(i, this.kills++);
};
meant for a 300x300 movie.
What it does is creates 10 plants (weeds) or root systems. They start out as nothing and branch off adding roots with each frame. If that root added extends to the position of another weed, it kills that weed and the dead weed has to be reborn in a random position starting over again with no roots. Color is random but the root thickness is based on the amount of kills the killing weed has. In other words a really thick rooted weed was killed by a weed with a lot of kills - a kind of helper to the underdog ;) though, functionally, theres no difference in having big roots vs small except they're more easily seen on the screen. Every frame there is also an output of each plants lifespan in frames and kills.
Your typical predator/prey kind of thing.
:D
Colin Campbell
06-17-2003, 02:28 AM
good god. Am I ever supposed to do that? :eek: somebody help me! EEEEEEEEEEE
Timmee_3Styler
06-17-2003, 03:31 AM
just cover ur eyes n dont like @ the code colin
COVER THEM!!!!!!!! :p
McGiver
06-17-2003, 11:39 AM
nice one @ seno :)
McGiver
06-17-2003, 10:12 PM
Ok, you show me your's I show you mine :D
function createlife(n, arr) {
_root.createEmptyMovieClip("al"+n, n);
_root["al"+n].beginFill(0x999900, 30);
_root["al"+n].curveTo(5, 0, 5, -5);
_root["al"+n].curveTo(5, -10, 0, -10);
_root["al"+n].curveTo(-5, -10, -5, -5);
_root["al"+n].curveTo(-5, 0, 0, 0);
_root["al"+n].endFill();
arr.push(_root["al"+n]);
arr[n-1].age = 10;}
function live(arr) {
for (count=0; count<arr.length; count++) {
agecolor = new Color(arr[count]);
agecolor.setRGB(("0x9999"+arr[count].age));
arr[count]._xscale = arr[count]._xscale+1;
arr[count]._yscale = arr[count]._yscale+1;
for (bcount=0; bcount<arr.length; bcount++) {
if (arr[count] != arr[bcount]) {
if (arr[count].hitTest(arr[bcount])) {
arr[bcount]._x = arr[bcount]._x+(arr[bcount]._x-arr[count]._x)/20;
arr[bcount]._y = arr[bcount]._y+(arr[bcount]._y-arr[count]._y)/20;}}}
if (arr[count]._xscale>=200) {
createlife((arr.length+1), arr);
arr[count]._xscale = 120;
arr[count]._yscale = 120;
ychange = (Math.random()*16)-8;
arr[arr.length-1]._y = arr[count]._y+ychange;
arr[count]._y = arr[count]._y-ychange;
arr[arr.length-1]._x = arr[count]._x+Math.sqrt((8*8)-(ychange*ychange));
arr[count]._x = arr[count]._x-Math.sqrt((8*8)-(ychange*ychange));
arr[count].age = arr[count].age+17;
if (arr[count].age>99) {
arr[count].removeMovieClip();
arr.splice(count, 1);}}}}
_root.ALarr = [];
createlife(1, _root.ALarr);
_root["al"+1]._x = 275;
_root["al"+1]._y = 200;
this.onEnterFrame = function() {
live(_root.ALarr);};
It!s a simple cell growing, and dividing to 2 if it's big enough.
I got some additional lines I didn't use, so I made the cells get older (and turn gray) and die.
It's simple and a very easy code, so do not expect too much ;) !
Edit: changed it to make it smoother.
Enjoyed best with a Frame Rate of 24 fps and a cool beer :D
I hope the ice is broken now, and many other ideas will follow ;)
Colin Campbell
06-17-2003, 10:22 PM
Ok, I spent all night thinking of this code, and I think its pretty good!
gotoAndPlay ("RUN!", 1);
//this is where I run like HELL!
senocular
06-18-2003, 12:12 AM
cool McGiver :)
Colin Campbell
06-18-2003, 01:12 AM
nobody likes mine?! I spent hours on that! tisk tisk!
Timmee_3Styler
06-18-2003, 02:43 AM
removeMovieClip(this)
heheh no pt in running their too good :rolleyes: :p :D
just gonna remove myself haaha
McGiver
06-18-2003, 10:35 AM
@colin: maybe noone honers you for yours, because they don't understand it! its too ... comlicated :D
And you say you created it in ONE NIGHT?
think i would need at least two weaks for reading through it! ;)
McGiver
06-18-2003, 02:54 PM
changed a little bit, think it looks better this way! (still exactly 40 lines)
looks best with 30 fps
function createlife(n, arr) {
_root.createEmptyMovieClip("al"+n, n);
_root["al"+n].lineStyle(1, 0xffffff, 80);
_root["al"+n].beginFill(0x009900, 30);
_root["al"+n].curveTo(5, 0, 5, -5);
_root["al"+n].curveTo(5, -10, 0, -10);
_root["al"+n].curveTo(-5, -10, -5, -5);
_root["al"+n].curveTo(-5, 0, 0, 0);
_root["al"+n].endFill();
arr.push(_root["al"+n]);}
function live(arr) {
for (count=0; count<arr.length; count++) {
agecolor = new Color(arr[count]);
agecolor.setRGB(("0x00"+(99-arr[count].age)+"00"));
arr[count]._xscale = arr[count]._xscale+1;
arr[count]._yscale = arr[count]._yscale+1;
for (bcount=0; bcount<arr.length; bcount++) {
if (arr[count] != arr[bcount]) {
if (arr[count].hitTest(arr[bcount])) {
arr[bcount]._x = arr[bcount]._x+(arr[bcount]._x-arr[count]._x)/20;
arr[bcount]._y = arr[bcount]._y+(arr[bcount]._y-arr[count]._y)/20;}}}
if (arr[count]._xscale>=200) {
createlife((arr.length+1), arr);
arr[count]._xscale = 120;
arr[count]._yscale = 120;
ychange = (Math.random()*16)-8;
arr[arr.length-1]._y = arr[count]._y+ychange;
arr[count]._y = arr[count]._y-ychange;
arr[arr.length-1]._x = arr[count]._x+Math.sqrt((8*8)-(ychange*ychange));
arr[count]._x = arr[count]._x-Math.sqrt((8*8)-(ychange*ychange));
arr[count].age = arr[count].age+17;
if (arr[count].age>99) {
arr[count].removeMovieClip();
arr.splice(count, 1);}}}}
_root.ALarr = [];
createlife(1, _root.ALarr);
_root["al"+1]._x = 275;
_root["al"+1]._y = 200;
this.onEnterFrame = function() {
live(_root.ALarr);};
Look it under the microskope... :(
online demo (http://nobodyxxl58.port5.com/Justforkicks/life_031.html)
for t>500, it slows down!
Colin Campbell
06-18-2003, 02:57 PM
Hahahha, good one mcgiver. :p
If I ever have time now, I'll give it an actual shot, just for fun.
senocular
06-18-2003, 03:08 PM
too bad it gets so slow so fast :) I want it to fill my screen :(
littleRichard
06-19-2003, 01:15 AM
well, i tried to do this last night and failed miserably, so today i thought about it a bit and here's what i've got.
1) you have boys & you have girls. when a boy and girl share the same space they make a baby.
2) all units have a life span and an age. when age == lifesapn the unit dies.
3) if 3 or more units occupy the same space they all die from over population
4) if there are 100 or more units then a plague occurs and every unit has about a 1 in 20 chance over living through it.
MovieClip.prototype.drawShape = function(p, f)
{
this.beginFill(f[0], f[1]);
for(var c = 0; c < p.length; c++) !c ? this.moveTo(p[0][0], p[0][1]) : this.lineTo(p[c][0], p[c][1]);
};
this.drawShape([[0,0],[300, 0],[300,300],[0,300],[0,0]],[0x99FFCC,10]);
people = [];
for(var c = 0; c < 10; c++) createPerson();
this.onEnterFrame = function()
{
location = {};
for(var c = 0; c < people.length; c++) location["cell_" + people[c].x + "_" + people[c].y] == undefined ? location["cell_" + people[c].x + "_" + people[c].y] = [people[c]] : location["cell_" + people[c].x + "_" + people[c].y].push(people[c]);
var x, y, p;
for(var c in location)
{
p = 0;
for(var cc = 0; cc < location[c].length; cc++)
{
if((x = location[c][cc].x + Math.round(Math.random() * 2 - 1)) <= 29 && x >= 0) location[c][cc].x = x;
if((y = location[c][cc].y + Math.round(Math.random() * 2 - 1)) <= 29 && y >= 0) location[c][cc].y = y;
location[c][cc]._x = location[c][cc].x * 10;
location[c][cc]._y = location[c][cc].y * 10;
p += location[c][cc].gender;
if(++location[c][cc].age > location[c][cc].life) if(location[c][cc]._x != undefined) killPerson(location[c][cc], " has died from old age.");
if(location[c].length > 2) killPerson(location[c][cc], " has died from over population.");
}
if(people.length > 100) for(var i = 0; i < people.length; i++) if(Math.round(Math.random() * 20)) killPerson(people[i], " has died from plague");
if(p > 0 && p < location[c].length) createPerson(location[c][cc].x, location[c][cc].y);
}
if(!people.length)
{
trace("The world has ended.");
this.onEnterFrame = undefined;
}
}
function createPerson(x, y)
{
people.push(this.createEmptyMovieClip("person_" + (++this.HL), this.HL));
people[people.length - 1]._x = (x == undefined ? people[people.length - 1].x = Math.round(Math.random() * 29) : people[people.length - 1].x = x) * 10;
people[people.length - 1]._y = (y == undefined ? people[people.length - 1].y = Math.round(Math.random() * 29) : people[people.length - 1].y = y) * 10;
(people[people.length - 1].life = Math.round(Math.random() * 500 + 100)) + (people[people.length - 1].gender = Math.round(Math.random() * 1)) + (people[people.length - 1].age = 0);
people[people.length - 1].gender == 0 ? people[people.length - 1].drawShape([[0,0],[10, 0],[10,10],[0,10],[0,0]],[0xFFCCCC,100]) : people[people.length - 1].drawShape([[0,0],[10, 0],[10,10],[0,10],[0,0]],[0x66CCFF,100]);
trace(people[people.length - 1] + " has been born.");
}
function killPerson(o, m)
{
trace(o + m);
for(var c = 0; c < people.length; c++) if(people[c] == o) people.splice(c, 1);
o.removeMovieClip();
delete o;
}
cheers,
rich
McGiver
06-19-2003, 01:29 PM
wow! really impressing!
Nice job everyone :) McGiver, I had the same idea as yours... Guess I'll have to fing something else :|
McGiver
06-20-2003, 02:30 PM
:D !
Maybe you can improve my one!
You can take my code ... for a little fee! think 500euros would be a fair price!
no seriously, improve it if you like.
McGiver
06-20-2003, 02:42 PM
The speed decrease symbolizes the lack of food appearing with the big number of cells, which makes them grow slower :D
Fugee
06-20-2003, 02:49 PM
McGiver i have to say i really love what you did here! :)
Just wanted to let you know it's an appreciated piece of work ;)
P.S. btw Senocular, i remember something you made, where you had animals, herbivores and carnivores, and plants, poisonous and not, but can't seem to find it anymore! It was wonderful (and i had downloaded the fla but my old HD overheated the other day... :(...ah well) so if you could tell me where it was, if you remember! ;)
McGiver
06-20-2003, 03:01 PM
wow, thanks! :D
padnpen
06-20-2003, 09:54 PM
McGiver, I loved your AI and wanted give it a little American touch... although it really just reflects my poor humor. I didn't follow the rules one bit because I stole your code and it's longer then 40 lines.
Think of it this way, I took your living things to be like people and tweaked it American-like to show what happens when there are too many people(more then 32 in this case)... All changes are at the bottom.
function createlife(n, arr) {
_root.createEmptyMovieClip("al"+n, n);
_root["al"+n].lineStyle(1, 0xffffff, 80);
_root["al"+n].beginFill(0x009900, 30);
_root["al"+n].curveTo(5, 0, 5, -5);
_root["al"+n].curveTo(5, -10, 0, -10);
_root["al"+n].curveTo(-5, -10, -5, -5);
_root["al"+n].curveTo(-5, 0, 0, 0);
_root["al"+n].endFill();
arr.push(_root["al"+n]);
}
function live(arr) {
for (count=0; count<arr.length; count++) {
agecolor = new Color(arr[count]);
agecolor.setRGB(("0x00"+(99-arr[count].age)+"00"));
arr[count]._xscale = arr[count]._xscale+1;
arr[count]._yscale = arr[count]._yscale+1;
for (bcount=0; bcount<arr.length; bcount++) {
if (arr[count] != arr[bcount]) {
if (arr[count].hitTest(arr[bcount])) {
arr[bcount]._x = arr[bcount]._x+(arr[bcount]._x-arr[count]._x)/20;
arr[bcount]._y = arr[bcount]._y+(arr[bcount]._y-arr[count]._y)/20;
}
}
}
if (arr[count]._xscale>=200) {
createlife((arr.length+1), arr);
arr[count]._xscale = 120;
arr[count]._yscale = 120;
ychange = (Math.random()*16)-8;
arr[arr.length-1]._y = arr[count]._y+ychange;
arr[count]._y = arr[count]._y-ychange;
arr[arr.length-1]._x = arr[count]._x+Math.sqrt((8*8)-(ychange*ychange));
arr[count]._x = arr[count]._x-Math.sqrt((8*8)-(ychange*ychange));
arr[count].age = arr[count].age+17;
if (arr[count].age>99) {
arr[count].removeMovieClip();
arr.splice(count, 1);
}
}
}
}
_root.ALarr = [];
createlife(1, _root.ALarr);
_root["al"+1]._x = 275;
_root["al"+1]._y = 200;
tooManyNonAmericans = 32;
electBush = function () {
for (i=0; i<tooManyNonAmericans+5; ++i) {
otherPeople = _root["al"+i];
removeMovieClip(otherPeople);
delete _root.ALarr;
_root.createTextField("victory", 1, 100, 100, 300, 100);
tFormat = new TextFormat();
tFormat.color = 0x000000;
victory.text = "Bush Wins!";
victory.setTextFormat(tFormat);
}
};
this.onEnterFrame = function() {
live(_root.ALarr);
if (_root.ALarr.length>tooManyNonAmericans) {
electBush();
}
};
:D :D Nice coding skills! I like those lines in particular:
if (_root.ALarr.length>tooManyNonAmericans) {
electBush();
}
McGiver
06-21-2003, 12:32 AM
Inspired by padnpen:
my newest stupid idea:
Did you never wanted your own colony of saddams?
here you get it! let them grow. when you got enough, erase a few, by clicking on the floor.
set fps to 100
function createlife(n, arr) {
_root.createEmptyMovieClip("al"+n, n);
_root["al"+n].lineStyle(1.8, 0x000000, 80);
_root["al"+n].beginFill(0xcc9900, 30);
_root["al"+n].curveTo(5, 0, 5, -5);
_root["al"+n].curveTo(5, -10, 0, -10);
_root["al"+n].curveTo(-5, -10, -5, -5);
_root["al"+n].curveTo(-5, 0, 0, 0);
_root["al"+n].moveTo(-1, -2);
_root["al"+n].lineTo(1, -2);
_root["al"+n].moveTo(-2.5, -6);
_root["al"+n].lineTo(-1.5, -6);
_root["al"+n].moveTo(2.5, -6);
_root["al"+n].lineTo(1.5, -6);
_root["al"+n].moveTo(-1.2, -4);
_root["al"+n].lineStyle(2.5, 0x000000, 80);
_root["al"+n].lineTo(1.2, -4);
_root["al"+n].moveTo(1.0, -8);
_root["al"+n].lineTo(2.5, -8);
_root["al"+n].moveTo(-1.0, -8);
_root["al"+n].lineTo(-2.5, -8);
_root["al"+n].endFill();
arr.push(_root["al"+n]);}
function live(arr) {
for (count=0; count<arr.length; count++) {
arr[count]._xscale = arr[count]._xscale+1;
arr[count]._yscale = arr[count]._yscale+1;
for (bcount=0; bcount<arr.length; bcount++) {
if (arr[count] != arr[bcount]) {
if (arr[count].hitTest(arr[bcount])) {
arr[bcount]._x = arr[bcount]._x+(arr[bcount]._x-arr[count]._x)/20;
arr[bcount]._y = arr[bcount]._y+(arr[bcount]._y-arr[count]._y)/20;}}}
if (arr[count]._xscale>=200) {
createlife((arr.length+1), arr);
arr[count]._xscale = 120;
arr[count]._yscale = 120;
ychange = (Math.random()*16)-8;
arr[arr.length-1]._y = arr[count]._y+ychange;
arr[count]._y = arr[count]._y-ychange;
arr[arr.length-1]._x = arr[count]._x+Math.sqrt((8*8)-(ychange*ychange));
arr[count]._x = arr[count]._x-Math.sqrt((8*8)-(ychange*ychange));
arr[count].age = arr[count].age+17;
if (arr[count].age>99) {
arr[count].removeMovieClip();
arr.splice(count, 1);}}}}
function blast(radius, alpha) {
Alarr[0].removeMovieClip();
Alarr.splice(0, 1);
_root.createEmptyMovieClip("blast"+1, 100);
_root["blast"+1].lineStyle(1.8, 0x000000, alpha);
_root["blast"+1].beginFill(0xff9900, alpha);
_root["blast"+1].curveTo(radius, 0, radius, -radius);
_root["blast"+1].curveTo(radius, -2*radius, 0, -2*radius);
_root["blast"+1].curveTo(-radius, -2*radius, -radius, -radius);
_root["blast"+1].curveTo(-radius, 0, 0, 0);
_root["blast"+1].endFill();
_root["blast"+1]._x = _xmouse;
_root["blast"+1]._y = _ymouse+radius;}
_root.ALarr = [];
createlife(1, _root.ALarr);
_root["al"+1]._x = 275;
_root["al"+1]._y = 200;
this.onEnterFrame = function() {
live(_root.ALarr);
if (blasted == 1) {
radius = radius+10;
blast(radius, 100-(radius)/2);}
if(100-(radius)/2<=0){
radius=0
blasted=0}
_root.onMouseDown = function() {
blasted = 1;
trace("S-W-U-S-C-H");};};
Sorry, code is much too long, but i had noone to spend the night with, and time, so i wrote this one. :D
Hmm, seems many bad guys in history have beards!
padnpen
06-21-2003, 12:35 AM
HAhahaha, I just laughed out loud!
*wiping forehead* I was a little worried my humor wouldn't be taken well but I'm glad to see there are others just as sick as I am!
I think I just came up with my signature...
"If you can't code better than the next guy make fun of someone else to divert attention"
McGiver
06-21-2003, 12:38 AM
I fell inlove with the last line
( trace("S-W-U-S-C-H") )
padnpen
06-21-2003, 12:45 AM
Actually, I'm a little sorry that your fantastic idea for a competition has been lowered to a political joke... but I'm still laughing at the faces you drew. You paid great attention to detail! Imagine the fun Bush would have if he were able to play this game.
Still laughing.... the eyebrows
Still laughing.... the mustache
... too funny
McGiver
06-21-2003, 12:49 AM
hmm, i first wanted to create bush-faces.
padnpen
06-21-2003, 12:54 AM
Bush would be a good one... taking orders? How about a Martha Stewart face?
Mike Tyson?
Harry Potter?
How about the AOL man icon?
McGiver
06-22-2003, 12:20 PM
ok, back to serious
Feed the fish, but do not let him die of hunger, or of too much fat. <edit: or let him die if you like>
Enjoyed best with 24 fps, (and much time)
function swimto(arr, mc) {
mc._x = mc._x+(arr[0]._x-mc._x)/10;
mc._y = mc._y+(arr[0]._y-mc._y)/10;
angle = Math.atan((arr[0]._y-mc._y)/(arr[0]._x-mc._x))/(Math.PI/180);
if ((arr[0]._x-mc._x)<0) {
angle += 180;}
fat -= 0.05;
if ((fat<=-14) || (fat>=12)) {
fish.removeMovieClip();
_root.createTextField("message", 1, 200, 200, 300, 100);
_root.message.text = "Your fish died!";}
createfish(fat);
mc._rotation = angle+180;
if (mc.hitTest(arr[0])) {
arr[0].removeMovieClip();
arr.splice(0, 1);
fat += 1.5;}}
function createfish(fat) {
_root.fish.clear();
_root.fish.lineStyle(1, 0xff9900);
_root.fish.beginFill(0xffcc00);
_root.fish.curveTo(15, fat+25, 40, -10);
_root.fish.lineTo(40, 10);
_root.fish.curveTo(15, -fat-25, 0, 0);}
function createfood(arr, n) {
_root.createEmptyMovieClip("food"+n, n);
_root["food"+n].beginFill(0x009900, 30);
_root["food"+n].curveTo(10, -5, 0, 10);
_root["food"+n].curveTo(-10, -5, 0, 0);
_root["food"+n]._x = _xmouse;
_root["food"+n]._y = _ymouse;
arr.push(_root["food"+n]);}
_root.createEmptyMovieClip("fish", 1);
foodarr = [];
createfish(fat);
this.onEnterFrame = function() {
swimto(foodarr, _root.fish);
_root.onMouseDown = function() {
createfood(foodarr, n);
n += 2;};};
The fish grows, if he has eaten something, and get's smaller if he does not get food for some time
beautiful online demo (http://de.geocities.com/roland_plass/fish_008.html)
Esquared
06-23-2003, 08:13 AM
I'm not fully satisfied yet. I plan on making the RGBeings more self sufficient and on making the reproduction process more dynamic than it is presently.
We shall see. It looks long, but I believe it's actually 34 lines here. I have 3 notes:
1. The initial environment as specified is best suited to a 200 x 200 stage.
2. Multiple simulations are required to see full effect, as in many of them
the RGBeings will die off before a self sufficient colony is produced.
3. Give it time...eventually a single dominant species will prevail.
HOPE YOU LIKE IT!
//|||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||\\
// \\
//____________________________RGBeings Simulation_______________________________\\
// \\
// This simulation is designed to represent the evolution of primitive \\
// organisms, or RGBeings, through reproduction and natural selection. Color \\
// itself is used to represent the varied species of these RGBeings. The \\
// largely unintelligent RGBeings wander aimlessly, reproducing when coming \\
// into contact with others. Several probabilities are taken into account \\
// for reproduction. First, the RGBeings show a preference to mate with other \\
// RGBeings of a similar species (color). If, however, the total number of \\
// potential mates is limited, chances that RGBeings will mate regardless of \\
// species is increased due to desire for self preservation. Finally, all have \\
// a prespecified age of fertility at which they may concieve. \\
// \\
//|||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||\\
// \\
//__NAME____________DESCRIPTION_____________________ __________________DATE______\\
// \\
// Eben Eliason Initial Release 6.21.03 \\
// \\
//|||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||\\
//
//initialize global constants (NOT IN LINE COUNT: could be hard coded)
lifespan = 15000;
radius = 15;
//initialize collision data
cells = new Array(Xcells = Stage.width/10);
for(i = 0; i < Xcells; i++) cells[i] = new Array(Ycells = Stage.height/10);
//birth function
birth = function(x, y, Vx, Vy, R, G, B) {
//frame function
(RGBeing = _root.createEmptyMovieClip("RGBeing" + ++z, z)).onEnterFrame = function() {
//living
cells[Math.floor(this._x/Xcells)][Math.floor(this._y/Ycells)] = null; //clear collision point
if((this._x += this.Vx) < 0 || this._x > Stage.width) this.Vx *= -1; //perimeter detection
if((this._y += this.Vy) < 0 || this._y > Stage.height) this.Vy *= -1; //perimeter detection
//conceiving (collision detection)
if((mate = cells[Math.floor(this._x/Xcells)][Math.floor(this._y/Ycells)]) != null) {
cells[Math.floor(this._x/Xcells)][Math.floor(this._y/Ycells)] = null //clear collision point
if((Stage.width*Stage.height/(4*radius*radius) - population) > Math.random()*(Stage.width*Stage.height/(4*radius*radius)) //self preservation...
&& Math.random()*0xFFFFFF > (this.RGB.getRGB() - mate.RGB.getRGB()) //show species preference...
&& this._alpha < 90 //check fertility...
&& mate._alpha < 90) { //check fertility
birth((this._x + mate._x)/2, //...
(this._y + mate._y)/2, //...
Math.random()*6-3, //...
Math.random()*6-3, //...
(this.RGBtransform.rb + mate.RGBtransform.rb)/2, //...
(this.RGBtransform.gb + mate.RGBtransform.gb)/2, //...
(this.RGBtransform.bb + mate.RGBtransform.bb)/2); }}
else cells[Math.floor(this._x/Xcells)][Math.floor(this._y/Ycells)] = this; //set collision point
//aging
this._xscale = this._yscale = 130-this._alpha; //growth
this._alpha = 100*(1-(((time = getTimer()) - this.conception)/lifespan)); //fade
//death
if(this._alpha <= 0) {
cells[Math.floor(this._x/Xcells)][Math.floor(this._y/Ycells)] = null; //clear collision point
population--;
removeMovieClip(this); }}
//initialize a new RGBeing
++population;
RGBeing.conception = getTimer();
RGBeing.lifespan = lifespan;
RGBeing.RGBtransform = new Object();
RGBeing.RGBtransform.ra = RGBeing.RGBtransform.ga = RGBeing.RGBtransform.ba = 255
RGBeing.RGBtransform.rb = R;
RGBeing.RGBtransform.gb = G;
RGBeing.RGBtransform.bb = B;
(RGBeing.RGB = new Color(RGBeing)).setTransform(RGBeing.RGBtransform) ;
RGBeing.lineStyle((RGBeing.radius = radius)*2,RGB,100);
RGBeing.lineTo(.15,.45);
RGBeing._x = x;
RGBeing._y = y;
RGBeing._xscale = RGBeing._yscale = 25
RGBeing.Vx = Vx;
RGBeing.Vy = Vy; }
//
//initialize RGBeings (NOT IN LINE COUNT: initial environment theoreticaly left to user)
birth(Math.random()*Stage.width, Math.random()*Stage.height, Math.random()*10-5, Math.random()*10-5, 255, 0, 0); //R
birth(Math.random()*Stage.width, Math.random()*Stage.height, Math.random()*10-5, Math.random()*10-5, 0, 255, 0); //G
birth(Math.random()*Stage.width, Math.random()*Stage.height, Math.random()*10-5, Math.random()*10-5, 0, 0, 255); //B
padnpen
06-23-2003, 04:15 PM
That is very cool! I had a hard time getting the 'mating' process to get going with only three 'births' so I decided to copy the three initial births to have the movie start with six, two from each color. When I did that the movie worked every time and actually produced even more interesting fights to be the remaining, dominant color.
Just for fun I decided to include a snapshot of six movies together. It was kind of like watching a gold-fish, pretty fun to sit there and stare.
McGiver
06-23-2003, 05:46 PM
wow, it really looks cool!
pic (http://nobodyxxl58.port5.com/Justforkicks/experiment.jpg) (I ncreased the field size, and the number of start creatures)
but:
1. it's longer than 40 lines (that's ok ;) )
2. It's really hard to make them meet! you should double the number of start colors
3. I really enjoyed your little genetics lession :D :D :D
littleRichard
06-23-2003, 05:59 PM
props to Esquared, that's really cool:)
Esquared
06-23-2003, 11:16 PM
I like the screenshots. In particular, I enjoy the effect you achieved in the larger "perti dish." Did you experience slowup with such a large colony?
Also....it IS less than 40 lines. I disregard the 2 lines for the constants at the top, since they could be hard coded. I also disregard the initialization of the colony at the bottom, since as you've mentioned, it may be better for you to set up yourself.
Finally, you should notice that the entire block of code under "conceiving" is really only 5 lines of code. The if() statement and birth() function are broken up for display reasons...
Perhaps if I get time over the next week I'll make it more dynamic, passing lifespan and size genetically too...
McGiver
06-24-2003, 01:14 PM
Just for Kicks Challenges rules:
RulesDon’t abuse the line limit by using really long infix IF-ELSE statements or anything like that
if(a<b){
a+c}
not really important, just wanted to show why there are more than 40 lines if you use normal linecount, youget more than 40 lines!:D
But don't be influenced by that! still wayting for your next one :D
the big one really slowed down my pc to ~2 fps:rolleyes:
I experienced the best results with 300x300 and 15fps
Jesse
06-27-2003, 01:37 PM
Wow everyone. I just found this one. Fantastic stuff going down in this thread. Keep it coming. More challenges like this! More I say! :) I'm on holidays now so I promise to contribute to challenges more.
McGiver
06-27-2003, 04:44 PM
Again, a change of my first idea! Looks like I am an 1hit-wonder:D
I had some time, before going out today, so I took a look at my code again. Now, they are eating!
if the mould cells get enough food, they grow and duplicate themselves! if they have to hunger, they die and become food for the other cells!
Sorry, 45 lines :(
but i think this may be interesting.
Set Framerate to 24fps
function createfood(x, y, n, arr) {
_root.createEmptyMovieClip("food"+n, n+200).lineStyle(5, 0xffcc00, 80);
_root["food"+n].lineTo(1, 1);
_root["food"+n]._x = x;
_root["food"+n]._y = y;
arr.push(_root["food"+n]);}
function createlife(n, arr) {
_root.createEmptyMovieClip("al"+n, n).lineStyle(10, 0xdddddd, 80);
_root["al"+n].lineTo(1, 1);
arr.push(_root["al"+n]);}
function live(arr, foodarr) {
for (count=0; count<arr.length; count++) {
for (fcount=0; fcount<foodarr.length; fcount++) {
if ((arr[count].hitTest(foodarr[fcount])) && (arr[count].grow>-100)) {
arr[count].grow = arr[count].grow-50;
foodarr[fcount].removeMovieClip();
foodarr.splice(fcount, 1);}}
if (arr[count].grow<50) {
arr[count]._yscale = arr[count]._xscale = arr[count]._yscale+1-arr[count].grow/50;
arr[count].grow = arr[count].grow+1-arr[count].grow/50;}
for (bcount=0; bcount<arr.length; bcount++) {
if ((arr[count] != arr[bcount])&&(arr[count].hitTest(arr[bcount]))) {
arr[bcount]._x = arr[bcount]._x+(arr[bcount]._x-arr[count]._x)/20;
arr[bcount]._y = arr[bcount]._y+(arr[bcount]._y-arr[count]._y)/20;}}
if (arr[count].grow>=45) {
arr[count].t = arr[count].t+1;
if (arr[count].t == 25) {
for (a=1; a<=5; a++) {
createfood(((Math.random()*60)+arr[count]._x-30), ((Math.random()*60)+arr[count]._y-30), foodarr.length+1, _root.foodarr);}
arr[count].removeMovieClip();
arr.splice(count, 1);}
} else {
arr[count].t = 0;}
if (arr[count]._xscale>=200) {
createlife((arr.length+1), arr);
arr[count]._xscale = arr[count]._yscale = 120;
ychange = (Math.random()*16)-8;
arr[arr.length-1]._y = arr[count]._y+ychange;
arr[count]._y = arr[count]._y-ychange;
arr[arr.length-1]._x = arr[count]._x+Math.sqrt((8*8)-(ychange*ychange));
arr[count]._x = arr[count]._x-Math.sqrt((8*8)-(ychange*ychange));}}}
_root.ALarr = [];
_root.foodarr = [];
this.onEnterFrame = function() {
live(_root.ALarr, _root.foodarr);};
//initialize life and set food (NOT IN LINE COUNT: initial environment theoreticaly left to user)
for (a=1; a<=70; a++) {
createfood(((Math.random()*200)+175), ((Math.random()*200)+100), a, _root.foodarr);}
createlife(1, _root.ALarr);
_root["al"+1]._x = 275;
_root["al"+1]._y = 200;
If someone sees a chance to reduce linecount feel free to tell me
Online Demo (http://de.geocities.com/roland_plass/life_b_demo_001.html)
webguy
07-07-2003, 02:18 PM
RatTrap. Thought of it after I found a dead rat in my crappy apartment last week. Sorry I exceeded the line limit, my coding skills are just developing, surely some of the guru's can clean it up to make it shorter. There are of course a couple flaws that I couldn't add due to the already inflated line count. All rats can spawn for one, and my hitTest code sucks, seems like it hits it even when it is like 10pixels out from the trap/rat and traps are sometimes created outside the stage area and rats never go outside the box. Anyway here it is, a reinactment of my crappy apartment.
_global.levelCount = 10;
trapArray = new Array();
adultRatArray = new Array();
MovieClip.prototype.drawRat = function(targetX, targetY, baby) {
newRat = _root.createEmptyMovieClip("rat"+levelCount, levelCount++);
newRat.lineStyle(1, 0x666666);
newRat.beginFill(0xCCCCCC, 100);
newRat.curveTo(20, 40, 0, 40);
newRat.curveTo(-20, 40, 0, 0);
newRat.endFill();
newRat.moveTo(0, 40);
newRat.curveTo(-5, 50, 0, 50);
newRat._x = targetX;
newRat._y = targetY;
if (baby == true) {
newRat._xscale = 40;
newRat._yscale = 40;} else {
_root.adultRatArray.push(newRat);}
newRat.onEnterFrame = function() {
this.timeToGetPregnant--;
this.age++;
trace(_root.adultRatArray.length);
if(this.age == 400) {this.removeMovieClip();}
if (this.timeToGetPregnant == 1) {_root.adultRatArray.push(this);}
if (this._xscale<100) {
this._xscale+=.5;
this._yscale+=.5;}
if (this._xscale == 99) {_root.adultRatArray.push(this);}
if (Math.ceil(this._x) == Math.ceil(targetX) || Math.ceil(this._y) == Math.ceil(targetY)) {
targetX = Math.random()*Stage.width;
targetY = Math.random()*Stage.height;} else {
this._x += (targetX-this._x)/8;
this._y += (targetY-this._y)/8;
for (i=0; i<=_root.trapArray.length; ++i) {
if (this.hitTest(trapArray[i])) {
this.removeMovieClip();}}
for (i=0; i<=_root.adultRatArray.length; ++i) {
if (this.hitTest(adultRatArray[i]) && this != adultRatArray[i]) {
for (r=0; r<=1; ++r) {
drawRat(this._x, this._y, true);}
_root.adultRatArray.splice(i);
this.timeToGetPregnant = 100;}}}};};
function drawTrap(x, y) {
newTrap = _root.createEmptyMovieClip("trap"+levelCount, levelCount++);
newTrap.lineStyle(1);
newTrap.beginFill(0xCC9933, 100);
newTrap.lineTo(30, 0);
newTrap.lineTo(30, 60);
newTrap.lineTo(0, 60);
newTrap.lineTo(0, 0);
newTrap.endFill();
newTrap.moveTo(5, 30);
newTrap.lineTo(5, 55);
newTrap.lineTo(25, 55);
newTrap.lineTo(25, 30);
newTrap._x = x;
newTrap._y = y;
_root.trapArray.push(newTrap);}
drawTrap(Math.random()*Stage.width-30, Math.random()*Stage.height-30);
for (i=0; i<=2; i++) {drawRat(Math.random()*Stage.width, Math.random()*Stage.height);}
stop();
web
red penguin
07-09-2003, 08:12 AM
Righto....I guess I'd call this AI of some sort. It was a cool 25 lines following the initial rules but I did notice that 40 lines is allowed here. Added a simple screenwrap which brings me to 29 lines. Perhaps I will expand a bit??
// Intended on a stage of 500x500
// I worked with an orange background (but that is of little importance)
// 20-30 fps
_quality='LOW';
depth=0;
max_len=15; //maximum length of lines
v=3; // velocity (how 'fast' the little bugger moves)
d=.9;
x=y=250;
this.onEnterFrame=function(){
vx+=Math.random()*v-v/2;
vy+=Math.random()*v-v/2;
vx*=d;
vy*=d;
x+=vx;
y+=vy;
if(x>500) x=0;
else if(x<0) x=500;
if(y>500) y=0;
else if(y<0) y=500;
blob=createEmptyMovieClip("line_"+depth, ++depth);
if(depth>5) depth=0;
blob._x=x;
blob._y=y;
blob.lineStyle(20,0xffffff,3);
for (i=0;i<20;i++){
a=Math.random()*(Math.PI*2);
len=max_len*Math.random();
blob.moveTo(Math.cos(a)*len, Math.sin(a)*len);
blob.lineTo(Math.cos(a)*-len, Math.sin(a)*-len);
}
};
Plenty of things to play with in this one. Have fun!
online version0.2 (http://www.komielan.com/lab/view/life_02.html)
McGiver
07-09-2003, 01:47 PM
hmm, looks like an an artificil undead! nice ghost :)
subquark
02-20-2004, 08:44 AM
The fish grows, if he has eaten something, and get's smaller if he does not get food for some time
beautiful online demo :( boohoo, the fish is always floating belly up at the top when the game starts! makes me sad, I need a drink . . .
McGiver
02-20-2004, 02:48 PM
nooooo, it's just looking outside of his aquarium to check where the food is. ;)
subquark
02-20-2004, 03:03 PM
he he! thanks for making my day! :)
deadlydentures
05-25-2004, 01:47 AM
var count:Number = 0 ;
var LifeArray = new Array() ;
function NewLife(){
count ++ ;
LifeArray[count] = _root.attachMovie( "Life", String(count), count ) ;
}
_root.onEnterFrame = function(){
//DEATHTOCAPITALISTPIGS
for( Life in LifeArray ){
LifeArray[Life]._x += 10 - random(20) ;
LifeArray[Life]._y += 10 - random(20) ;
for( Life2 in LifeArray ){
if( Life != Life2 ) {
if( LifeArray[Life2].hitTest( LifeArray[Life] )){
if( LifeArray[Life2] > LifeArray[Life] ){
LifeArray[Life2]._height += 1 ;
LifeArray[Life2]._width += 1 ;
if( LifeArray[Life]._width < 4 ){
LifeArray[Life].removeMovieClip() ;
}
else{
LifeArray[Life]._width -= 1 ;
LifeArray[Life]._height -= 1 ;
}
}
else{
LifeArray[Life]._height += 1 ;
LifeArray[Life]._width += 1 ;
if( LifeArray[Life]._width < 4 ){
LifeArray[Life].removeMovieClip() ;
}
else{
LifeArray[Life2]._width -= 1 ;
LifeArray[Life2]._height -= 1 ;
}
}
}
}
}
if( Math.random() > .9 ){
if( LifeArray[Life]._width > 20 ){
LifeArray[Life]._width -= 10 ;
LifeArray[Life]._height -= 10 ;
NewLife() ;
LifeArray[count]._width = 5 ;
LifeArray[count]._height = 5 ;
}
}
if( Math.random() > .9 ){
LifeArray[Life]._width += 2 ;
LifeArray[Life]._height += 2 ;
}
if( Math.random() > .992 ){
LifeArray[Life].removeMovieClip() ;
}
}
}
NewLife() ; NewLife() ;
Its 59 lines, and with it I have a rectangle graphic that is called 'Life' with a width of 30 and a height of 29
It was smaller but i kept adding stuff
Basically, its a bunch of squares that run around randomly and when they bump into each other, the larger one wins and becomes bigger, and the other smaller, unless its really small and then it dies. There is a 10% chance that a square will give birth to another square, and there is a 10% chance a square will just grow. There is also a 8 in 1000 chance that a square will die, which seems to be the magic number in controlling the population.
deadlydentures
05-25-2004, 01:54 AM
BTW, If you have advice for me (for instance a better way), it would greatly be appretiated.
For instance, the movie gets slower and slower as it progresses, even if there are only a few boxes on the screen
littleRichard
05-25-2004, 09:14 AM
It gets slower because when a life dies you remove the movieclip but leave it in the LifeArray. So as time goes on your for loop is having to do more and more work.
McGiver
05-25-2004, 12:31 PM
brr, I guess I found a kind of subliminal message
//DEATHTOCAPITALISTPIGS
pHrOsT
06-11-2004, 10:04 AM
that is always an encouraging message to find
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.