Skip to content

Instantly share code, notes, and snippets.

@alexanderbazo
Last active January 8, 2016 07:44
Show Gist options
  • Save alexanderbazo/fef749fab8dd96d58bb9 to your computer and use it in GitHub Desktop.
Save alexanderbazo/fef749fab8dd96d58bb9 to your computer and use it in GitHub Desktop.
Grid-Erstellung in der Graphics-App
private void setupGrid() {
rows = (int) Math.sqrt(NUM_SQUARES);
columns = (int) Math.sqrt(NUM_SQUARES);
squareHeight = HEIGHT / rows;
squareWidth = WIDTH / columns;
}
private void drawGrid() {
for (int x = 0; x < rows; x++) {
for (int y = 0; y < columns; y++) {
Rect square = getRectangleForGrid(x, y);
square.draw();
}
}
}
private Rect getRectangleForGrid(int x, int y) {
Color squareColor = getRandomColor();
int xPos = x * squareWidth;
int yPos = y * squareHeight;
return new Rect(xPos, yPos, squareWidth, squareHeight, squareColor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment