Пример #1
0
  public void placeCell(int x, int y) {

    if (t != null) return;

    x = x / cellSize;
    y = y / cellSize;

    if (cell[x][y] == 0) {
      cell[x][y] = 1;
      offScrGraphics.setColor(Color.red);
      offScrGraphics.fillOval(x * cellSize + 1, y * cellSize + 1, cellSize - 2, cellSize - 2);
    } else {
      cell[x][y] = 0;
      offScrGraphics.setColor(Color.black);
      offScrGraphics.fillRect(x * cellSize + 1, y * cellSize + 1, cellSize - 2, cellSize - 2);
    }

    canvas.repaint();
  }
Пример #2
0
  public synchronized void nextGeneration() {
    int x, y;

    offScrGraphics.setColor(Color.red);

    CellCoordinate cellCoordinate;

    while (!nextLive.isEmpty()) {
      cellCoordinate = nextLive.removeFromHead();
      x = cellCoordinate.x;
      y = cellCoordinate.y;

      if (cell[x][y] == 0 && cellNeighbours[x][y] == 3) {
        cell[x][y] = 1;
        offScrGraphics.fillOval(x * cellSize + 1, y * cellSize + 1, cellSize - 2, cellSize - 2);
        live.addToTail(new CellCoordinate(x, y));
      }
      cellCoordinate = null;
    }

    offScrGraphics.setColor(Color.black);

    while (!nextDie.isEmpty()) {
      cellCoordinate = nextDie.removeFromHead();
      x = cellCoordinate.x;
      y = cellCoordinate.y;

      if ((cell[x][y] == 1) && (cellNeighbours[x][y] != 2) && (cellNeighbours[x][y] != 3)) {
        cell[x][y] = 0;
        offScrGraphics.fillRect(x * cellSize + 1, y * cellSize + 1, cellSize - 2, cellSize - 2);
        die.addToTail(new CellCoordinate(x, y));
      }
      cellCoordinate = null;
    }
    canvas.repaint();
    notifyAll();
  }
Пример #3
0
  private void initialize() {
    panel = new JPanel();
    frame = new JFrame();
    can.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            PointerInfo a = MouseInfo.getPointerInfo();
            Point b = a.getLocation();
            double x = b.getX();
            double y = b.getY();
            System.out.println("Entered x: " + x);
            System.out.println("Entered y: " + y);

            if (x == 950) {
              x = 0;
            } else if (x < 950) {
              x = (x / 950) - 1;
            } else if (x > 950) {
              x = (x / 950) - 1;
            }

            if (y == 563) {
              y = 0;
            } else if (y < 563) {
              y = 1 - (y / 563);
            } else if (y > 563) {
              y = 1 - (y / 563);
            }

            System.out.println("NEW NEW NEW NEW x: " + x);
            System.out.println("NEW NEW NEW NEW y: " + y);

            double inc = -2;
            var = new ArrayList<Double>();
            for (int i = -200; i < 200; i++) {
              var.add(new Equation(x, y).setEquationReturn(inc));
              inc = inc + .01;
            }

            double paintInc = -2;
            for (int dx = 0; dx < 200; dx++) {
              double dy = var.get(dx);
              theG.add(new Ellipse2D.Double(0 + paintInc, 540 - dy, 10, 10));
              paintInc = paintInc + 10;
            }

            /*This is to display the Y values for testing purposes
            Iterator<Double> it = var.iterator();
            while (it.hasNext()){
            	System.out.println(it.next());
            }*/

            can.repaint();
          }
        });
    JLabel xL = new JLabel();
    JLabel yL = new JLabel();
    JTextArea a = new JTextArea();
    a.setLocation(540, 540);
    a.setText("FFFFFFFFFFFUCK");
    a.setBackground(Color.white);
    yL.setText("Y");
    xL.setText("X");
    yL.setLocation(930, 10);
    yL.setSize(10, 10);
    yL.setBackground(Color.black);
    xL.setLocation(1900, 550);
    xL.setSize(10, 10);
    xL.setBackground(Color.black);
    xL.setOpaque(true);
    yL.setOpaque(true);

    panel.setBackground(Color.darkGray);
    can.setBackground(Color.black);
    can.setForeground(Color.black);
    frame.getContentPane().add(can);
    panel.setLayout(new GridLayout(1, 0, 0, 0));

    frame.add(xL);
    frame.add(yL);
    frame.add(can);
    frame.setBounds(0, 0, 1920, 1080);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }