At this moment I am working on a program to show an emergent system like The Game of Life from Conway. I want each hexagon to follow 3 different rules, causing an emergent behaviour.
I managed to make a hexagonal grid, but now I want to add 3 rules, where all units should listen to:
1. your color should be the average color (grayscale) of your neighbors (the 6 adjacent cells have a colorvalue, so the colorvalue of this hexagon should be the sum allcolorvalues/6.
2 if the colorvalues of your neigbors are to close to eachother, your value should rise to the maximum colorvalue (with RGB this is 255 (white), when the average colorvalue of your neighbors is LOWER then 127 (half of 255).
3. if the colorvalues of your neigbors are to close to eachother, your value should rise to the minimum colorvalue (with RGB this is 0 (black), when the average colorvalue of your neighbors is HIGHER then 127 (half of 255).
In this way there is no form of saturation and all units should behave emergent.
Does anyone know how I can give those rules to all the hexagons?
Bellow you will find the code for the hexagongrid.
Code:
Hexagon[][] hexagon;
int rad = 15;
int hexcountx, hexcounty;
void setup()
{
size(1200, 800);
smooth();
frameRate(50);
hexcountx = (height/(rad));
hexcounty = (width/(rad)*2);
hexagon = new Hexagon [hexcountx][hexcounty];
for (int i = 0; i < hexcountx; i++){
for (int j = 0; j < hexcounty; j++){
if ((j % 2) == 0) {
hexagon[i][j] = new Hexagon((3 * rad * i), (.866 * rad * j), rad);
} else {
hexagon[i][j] = new Hexagon(3 * rad * (i + .5), .866 * rad * j, rad);