Skip to content

Instantly share code, notes, and snippets.

@ker2x
Last active October 5, 2023 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ker2x/4cfe74ff500ec1b0ef5f92511094bfeb to your computer and use it in GitHub Desktop.
Save ker2x/4cfe74ff500ec1b0ef5f92511094bfeb to your computer and use it in GitHub Desktop.
voronoi ?
// create cells with random positions and colors
for (auto i = 0; i < 2000; i++) {
Cell cell;
cell.position.x = ofRandom(0, ofGetWidth());
cell.position.y = ofRandom(0, ofGetHeight());
cell.color = ofColor(ofRandom(0, 255), ofRandom(0, 255), ofRandom(0, 255));
cells.push_back(cell);
}
// loop through all the cells and compare them to each other to see if they are close enough to change color
// effectively, this creates a "neighborhood" of cells that are close to each other
for (auto &cell : cells) {
for (auto &otherCell : cells) {
if (&cell != &otherCell) {
float distance = ofDist(cell.position.x, cell.position.y, otherCell.position.x, otherCell.position.y);
if (distance < 100) {
cell.color = otherCell.color;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment