Skip to content

Instantly share code, notes, and snippets.

@chausen
Created April 9, 2025 05:40
Show Gist options
  • Save chausen/2d081c5bbca1bdf57352cd6b5b1cbdb4 to your computer and use it in GitHub Desktop.
Save chausen/2d081c5bbca1bdf57352cd6b5b1cbdb4 to your computer and use it in GitHub Desktop.
// Instead of 4 loops, do 2 loops per diagonal direction.
// For "/" diagonals, let's start from:
// - The bottom edge (y = bounds.y + bounds.height), x from bounds.x..bounds.x + width
// - The left edge (x = bounds.x), y from bounds.y..bounds.y + height
// For "\" diagonals, let's start from:
// - The top edge (y = bounds.y), x from bounds.x..bounds.x + width
// - The left edge (x = bounds.x), y from bounds.y..bounds.y + height
// Example for "/" diagonals:
for (int x = bounds.x; x <= bounds.x + bounds.width; x += spacing) {
drawOneDiagonalLine(g, pixels, x, bounds, +1);
}
for (int y = bounds.y + bounds.height; y >= bounds.y; y -= spacing) {
drawOneDiagonalLine(g, pixels, y, bounds, +1);
}
// Then do similarly for "\" diagonals, but pick top and left edges, for instance:
for (int x = bounds.x; x <= bounds.x + bounds.width; x += spacing) {
drawOneDiagonalLine(g, pixels, x, bounds, -1);
}
for (int y = bounds.y; y <= bounds.y + bounds.height; y += spacing) {
drawOneDiagonalLine(g, pixels, y, bounds, -1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment