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.

38 lines
732 B

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