Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create the background of the canvas
- graphics.clearRect(0, 0, getHeight(), getWidth());
- graphics.setColor(Color.DARK_GRAY);
- graphics.fillRect(0, 0, getWidth(), getHeight());
- // Loop through height and width to create lines which are equally separated
- // Horizontal lines
- graphics.setColor(Color.BLACK);
- for(int horLines = 0; horLines < height; horLines++) {
- int yCoord = horLines * getHeight() / height;
- // Draw the line
- graphics.drawLine(0, yCoord, getWidth(), yCoord);
- }
- // Vertical lines
- for (int vertLines = 0; vertLines < width; vertLines++) {
- int xCoord = vertLines * getWidth() / width;
- // Draw the line
- graphics.drawLine(xCoord, 0, xCoord, getHeight());
- }
- // Loop through all the cells that will be alive next round
- for (Cell cell : GameOfLife.getCellManager().getNextAliveCells()) {
- // Get cell's location on JPanel
- int x = cell.getX() * getWidth() / width;
- int y = cell.getY() * getHeight() / height;
- // Set cell's color
- graphics.setColor(Color.RED);
- // Paint the cell
- graphics.fillRect(x, y, getWidth() / width, getHeight() / height);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement