Last active
January 8, 2016 07:44
-
-
Save alexanderbazo/fef749fab8dd96d58bb9 to your computer and use it in GitHub Desktop.
Grid-Erstellung in der Graphics-App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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