Skip to content

Instantly share code, notes, and snippets.

@gorborukov
Created April 16, 2021 04:10
Show Gist options
  • Save gorborukov/c5c870504504350e357a34ef4be5e34e to your computer and use it in GitHub Desktop.
Save gorborukov/c5c870504504350e357a34ef4be5e34e to your computer and use it in GitHub Desktop.
Pseudo quadtree base. Ported from some p5.js scripts
struct drawingLocation{
int x,y,w,h;
};
std::vector<drawingLocation> drawingLocations;
void recursion(int x, int y, int width) {
int index = 0;
int count = 2;
int size = width/count;
float upper_limit = 1.0;
float lower_limit = 0.1;
float randomValue = ((upper_limit-lower_limit)*rand())/RAND_MAX + lower_limit;
for(int i = 0; i < count; i++) {
for(int j = 0; j < count; j++) {
if(randomValue < 0.5 && size > 50) {
recursion(x + i * size, y + j * size, size);
} else {
drawingLocations.push_back({x+i*size, y+j*size, size, size});
/*index++;
if (index > 3) {
index = 0;
}*/
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment