A simple Game of Life implementation in Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
627 B

  1. public class Screen {
  2. private int width, height;
  3. public int[] pixels;
  4. private int[] _grid;
  5. public Screen(int width, int height) {
  6. this.width = width;
  7. this.height = height;
  8. pixels = new int[width * height];
  9. _grid = new int[width * height];
  10. }
  11. public void clear() {
  12. for (int x = 0; x < _grid.length; x++) {
  13. pixels[x] = 0;
  14. }
  15. }
  16. public void render() {
  17. for (int x = 0; x < width; x++) {
  18. for (int y = 0; y < height; y++) {
  19. pixels[x + y * width] = _grid[x + y * width];
  20. }
  21. }
  22. }
  23. public void draw(int x, int y, int color) {
  24. _grid[x + y * width] = color;
  25. }
  26. }