Hacker News new | ask | show | jobs
by jerojero 1195 days ago
Look at genetic algorithms to get an idea.

But basically say a color is #RRGGBB you could think of these as 3 genes (RR, GG, BB) each of these letters would have their own value. At the moment of reproduction say every "cell" will give half of their genetic material and the other "cell" will give the other half.

Cell 1 (f0, f0, f0): R11 R12, G11 G12, B11 B12

Cell 2 (e9, e9, e9): R21 R22, G21 G22, B21 B22

When they reproduce you might have 4 combinations of red, 4 combinations of blue, 4 combinations of green and all together a lot of combinations. (E.g. R11R21, G21G11, B12B22: fe, ef, 09).

The way this works in nature is that our sperm cells have half our genetic material (at random) and the oocite has another half. Which allele is chosen (R11 or R12) is random. There's more complicated processes but that's the basis of genetics.

In your case, I would initialise every cell with a random colour and then when two cells are going to reproduce you just choose one R, one G, one B from one of the cells and same for the other one... then just mix them and you have your "colour". Now, keep in mind that for RGB the first digit is much more important than the second one so #fff is very similar to #f9f9f9. That's something you might want to have in consideration.

Now, with this you will probably see a lot of fun interactions appear. But if you want to go further you can make certain "colors" lethal and you'd see how quickly they disappear out of your pool... :) I hope that gives a good idea.

1 comments

Wow thanks for this explanation. I'll look into it, might try to add some randomness to the cell behaviour based on genetics. Could make it even more interesting.