Skip to content

Instantly share code, notes, and snippets.

@margnus1
Created October 29, 2013 14:01
Show Gist options
  • Select an option

  • Save margnus1/7215226 to your computer and use it in GitHub Desktop.

Select an option

Save margnus1/7215226 to your computer and use it in GitHub Desktop.
Box Packing ASCII art illustration
int n = this->x.size() + 1; // + 1 is used if the 1x1 box is excluded
int s = this->s.val();
std::vector<std::vector<char> > buffer(s, std::vector<char>(s, ' '));
for (int i = 0; i < n - 1; i++) {
int size = this->size(n, i); // Size of box i
int x = this->x[i].val();
int y = this->y[i].val();
if (size > 1) {
for (int xl = x; xl < x + size; xl++) {
buffer[y] [xl] = '_';
buffer[y+size-1][xl] = '^';
}
for (int yl = y; yl < y + size; yl++) {
buffer[yl][x] = '|';
buffer[yl][x+size-1] = '|';
}
buffer[y] [x] = '\\';
buffer[y] [x+size-1] = '/';
buffer[y+size-1][x] = '/';
buffer[y+size-1][x+size-1] = '\\';
if (size > 2) {
std::stringstream ss; ss << size;
std::string s = ss.str();
for (int i = 0; i < s.size(); i++)
buffer[y+size/2][x+(size-s.size())/2+i] = s[i];
}
} else buffer[y][x] = '#';
}
for (int line = s-1; line >= 0; line--) {
for (int chr = 0; chr < s; chr++)
os << buffer[line][chr];
os << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment