コード例 #1
0
 public static void main(String[] args) throws Exception {
   skel = loadRawInteger("data/skeleton.dat");
   vec = loadRawDouble("data/vectorsCorrected.dat");
   pos = new int[2000];
   int seek = 0;
   int frame = 0;
   while (frame < pos.length) {
     pos[frame++] = seek;
     seek += (skel[seek] * 2) + 1;
   }
   StdDraw.setCanvasSize(512, 512);
   StdDraw.setXscale(-128, 128);
   StdDraw.setYscale(-128, 128);
   StdDraw.show(100);
   StdDraw.setPenRadius(0.005);
   int f = 0;
   while (true) {
     if (StdDraw.isKeyPressed(KeyEvent.VK_Q)) {
       break;
     }
     if (StdDraw.isKeyPressed(KeyEvent.VK_RIGHT)) {
       if (StdDraw.isKeyPressed(KeyEvent.VK_SHIFT)) {
         f += 10;
         draw(f);
       } else draw(f++);
     }
     if (StdDraw.isKeyPressed(KeyEvent.VK_LEFT)) {
       if (StdDraw.isKeyPressed(KeyEvent.VK_SHIFT)) {
         f -= 10;
         draw(f);
       } else draw(f--);
     }
     StdDraw.show(100);
   }
 }
コード例 #2
0
  public static void main(String[] args) {

    Random random = new Random();
    Point start = new Point(random.nextInt(3), random.nextInt(3));
    System.out.print("How many steps: ");
    int n = new In().readInt();
    RandomWalker walker = new RandomWalker(start.x, start.y);

    StdDraw.setScale(-100, 100);
    StdDraw.show();

    System.out.println("Start: x=" + walker.getInitX() + " y=" + walker.getInitY());
    int oldX, oldY;
    for (int i = 0; i < n; i++) {
      oldX = walker.getX();
      oldY = walker.getY();

      walker.step();

      StdDraw.line(oldX, oldY, walker.getX(), walker.getY());
    }

    System.out.println("End: x=" + walker.getX() + " y=" + walker.getY());
  }