Last active
October 5, 2023 19:45
-
-
Save ker2x/4cfe74ff500ec1b0ef5f92511094bfeb to your computer and use it in GitHub Desktop.
voronoi ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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