public static void main(String[] args) {
    double T;
    double dt;
    String filename;
    int numberOfPlanets;
    double universeRadius;
    int i;
    Planet[] list;
    double time = 0;
    T = Double.parseDouble(args[0]);
    dt = Double.parseDouble(args[1]);
    filename = args[2];
    In in = new In(filename);
    numberOfPlanets = in.readInt();
    universeRadius = in.readDouble();
    i = 0;

    StdDraw.setScale(-universeRadius, universeRadius);
    StdDraw.picture(0, 0, "images/starfield.jpg");
    list = new Planet[numberOfPlanets];
    int j = 0;
    while (j < numberOfPlanets) {
      list[j] = getPlanet(in);
      j = j + 1;
    }

    while (time <= T) {
      int n = 0;
      StdDraw.setScale(-universeRadius, universeRadius);
      StdDraw.picture(0, 0, "images/starfield.jpg");
      while (n < numberOfPlanets) {

        list[n].setNetForce(list);
        list[n].update(dt);
        list[n].xNetForce = 0;
        list[n].yNetForce = 0;
        list[n].draw();
        n = n + 1;
      }
      StdDraw.show(1);
      time = time + dt;
    }

    StdOut.printf("%d\n", numberOfPlanets);
    StdOut.printf("%.2e\n", universeRadius);
    for (int q = 0; q < numberOfPlanets; q++) {
      StdOut.printf(
          "%11.4e %11.4e %11.4e %11.4e %11.4e %12s\n",
          list[q].x, list[q].y, list[q].xVelocity, list[q].yVelocity, list[q].mass, list[q].img);
    }
  }
示例#2
0
  public void run() {
    StdDraw.setCanvasSize(512, 512);
    StdDraw.setScale(0, 100);
    Bird flappy = new Bird();
    long upThen = System.currentTimeMillis() / 10;
    int score = 0;

    boolean running = true;
    while (running) {
      // Þarf að bæta við pixlum efst í bakgrunninn
      StdDraw.show(5);
      StdDraw.picture(50, 30, "../Myndir/background.jpg", 110 * 1.6, 110);
      //////////////////////////////////////////

      flappy.draw();

      //////////////////
      // Takkaskipanir
      //////////////////

      // Hömlur á það hversu oft má ýta á up með vissu tímabili
      if (StdDraw.isKeyPressed(38))
        flappy.up(System.currentTimeMillis() / 10); // Er verið að ýta á upp örvalykil?
      if (StdDraw.isKeyPressed(27)) close(); // Er verið að ýta á Escape?

      //////////////
      // Stigagjöf
      //////////////

      //////////////////////////////////////////
      StdDraw.show();
    }
  }