Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. // Create the background of the canvas
  2. graphics.clearRect(0, 0, getHeight(), getWidth());
  3. graphics.setColor(Color.DARK_GRAY);
  4. graphics.fillRect(0, 0, getWidth(), getHeight());
  5.  
  6. // Loop through height and width to create lines which are equally separated
  7. // Horizontal lines
  8. graphics.setColor(Color.BLACK);
  9. for(int horLines = 0; horLines < height; horLines++) {
  10. int yCoord = horLines * getHeight() / height;
  11.  
  12. // Draw the line
  13. graphics.drawLine(0, yCoord, getWidth(), yCoord);
  14. }
  15.  
  16. // Vertical lines
  17. for (int vertLines = 0; vertLines < width; vertLines++) {
  18. int xCoord = vertLines * getWidth() / width;
  19.  
  20. // Draw the line
  21. graphics.drawLine(xCoord, 0, xCoord, getHeight());
  22. }
  23.  
  24. // Loop through all the cells that will be alive next round
  25. for (Cell cell : GameOfLife.getCellManager().getNextAliveCells()) {
  26. // Get cell's location on JPanel
  27. int x = cell.getX() * getWidth() / width;
  28. int y = cell.getY() * getHeight() / height;
  29.  
  30. // Set cell's color
  31. graphics.setColor(Color.RED);
  32.  
  33. // Paint the cell
  34. graphics.fillRect(x, y, getWidth() / width, getHeight() / height);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement