Skip to content

Instantly share code, notes, and snippets.

@ELI7VH
Created July 21, 2020 15:09
Show Gist options
  • Save ELI7VH/78d9af626c774c7eb6e3238ba41c04c8 to your computer and use it in GitHub Desktop.
Save ELI7VH/78d9af626c774c7eb6e3238ba41c04c8 to your computer and use it in GitHub Desktop.
class Agent {
float a;
float b;
Agent(float _a, float _b) {
a = _a;
b = _b;
}
void update(Agent other) {
println(other);
}
}
Agent[][] agents;
void setup() {
size(800, 800);
colorMode(HSB, 1);
agents = new Agent[width][height];
for (int y = 0; y < height; y ++) {
Agent[] row = new Agent[width];
for (int x = 0; x < width; x++) {
row[x] = new Agent((float)x/width, (float)y/height);
}
agents[y] = row;
}
loadPixels();
}
void draw() {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int i = x + y * width;
Agent agent = agents[x][y];
// get surrouding pixels
// do maffs
// set agent a and b
int w = 1;
int h = 1;
for (int ax = -w; ax <= w; ax++) {
for (int ay = -w; ay <= w; ay++) {
if (ax > 0 && ax < width - 1 && ay > 0 && ay < height -1) {
Agent other = agents[ax][ay];
int v = abs(ax) + abs(ay);
if (v == 2) {
// corners
} else if (v == 1) {
// nearest
} else {
// self
}
}
}
}
if (x > 0) {
Agent left = agents[x-1][y];
agent.a = doTheThing(agent.a, left.a);
}
if (x < width - 1) {
Agent right = agents[x+1][y];
agent.a = doTheThing(agent.a, right.a);
}
if (y > 0) {
Agent top = agents[x][y-1];
agent.a = doTheThing(agent.a, top.a);
}
if (y < height - 1) {
Agent bottom = agents[x][y+1];
agent.a = doTheThing(agent.a, bottom.a);
}
pixels[i] = color(agent.a % 1, agent.b, 0.5);
}
}
updatePixels();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment