Skip to content

Instantly share code, notes, and snippets.

@aman-tiwari
Last active March 16, 2016 22:12
Show Gist options
  • Save aman-tiwari/79046b50667d2a5b9883 to your computer and use it in GitHub Desktop.
Save aman-tiwari/79046b50667d2a5b9883 to your computer and use it in GitHub Desktop.
Finds best (closest to square) grid sides for a number of square tiles
int n_tiles; //number of tiles
int grid_x = 0;
int grid_y = 0;
for(int n = 1; n < ceil(sqrt(n_tiles) + 1); n++) {
if(n_tiles%n == 0) {
grid_y = n;
grid_x = n_tiles/n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment