Ejemplo n.º 1
0
 /** This method cannot be called directly. */
 public void mousePressed(MouseEvent e) {
   synchronized (mouseLock) {
     mouseX = StdDraw.userX(e.getX());
     mouseY = StdDraw.userY(e.getY());
     mousePressed = true;
   }
 }
Ejemplo n.º 2
0
  public void run() {
    MOVE_PREV = MOVE_DOWN;

    System.out.println("INIT!");
    map = new int[mapX][mapY];

    for (int i = 0; i < map.length; i++) {
      for (int j = 0; j < map[i].length; j++) {
        map[i][j] = 0;
      }
    }
    map[blockP.x][blockP.y] = 1;
    //    	map[0][20] = 1;

    StdDraw.setXscale(-1.0, 1.0);
    StdDraw.setYscale(-1.0, 1.0);

    // initial values

    // double vx = 0.015, vy = 0.023;     // velocity

    // main animation loop
    while (true) {

      drawGame();
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      movePrev();
    }
  }
Ejemplo n.º 3
0
  public void drawGame() {
    StdDraw.clear(StdDraw.GRAY);

    // Set Color
    StdDraw.setPenColor(StdDraw.YELLOW);
    // Set Font
    setFont(new Font("SansSerif", Font.PLAIN, 32));
    // X, Y, String, rotation degree
    // Write String
    this.text(1 - 0.3, 1 - 0.1, blockP.x + ", " + blockP.y, 0);
    // Set Color
    StdDraw.setPenColor(StdDraw.ORANGE);
    // Set Font
    setFont(new Font("SansSerif", Font.PLAIN, 50));
    // Write String
    this.text(1 - 0.3, 1 - 0.3, "START!", 20);

    StdDraw.setPenColor(StdDraw.BLACK);

    for (int i = 0; i < map.length; i++) {
      for (int j = 0; j < map[i].length; j++) {
        if (map[i][j] > 0) {
          Point2D vLoc = map2Visual(i, j);
          System.out.println(i + ", " + j + ", " + vLoc);
          StdDraw.filledCircle(vLoc.getX(), vLoc.getY(), radius);
        }
      }
    }
  }
Ejemplo n.º 4
0
 /** This method cannot be called directly. */
 public void mousePressed(MouseEvent e) {
   synchronized (mouseLock) {
     mouseX = StdDraw.userX(e.getX());
     mouseY = StdDraw.userY(e.getY());
     mousePressed = true;
     // System.out.println(mouseX+" ,"+mouseY);
   }
 }
Ejemplo n.º 5
0
  public static void main(String[] args) {

    // set the scale of the coordinate system
    StdDraw game = new StdDraw();
    game.start();

    // System.out.println(game.map2Visual(99, 99));

  }
Ejemplo n.º 6
0
 /** This method cannot be called directly. */
 public void actionPerformed(ActionEvent e) {
   FileDialog chooser =
       new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
   chooser.setVisible(true);
   String filename = chooser.getFile();
   if (filename != null) {
     StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
   }
 }
Ejemplo n.º 7
0
  /** Test client. */
  public static void main(String[] args) {
    // final int WINDOW_LENGTH = 600;
    // final int WINDOW_HEIGHT = 1200;
    // StdDraw.setCanvasSize(WINDOW_HEIGHT, WINDOW_LENGTH); //pixel size of window
    StdDraw.setXscale(0, 1.2);
    StdDraw.setYscale(0, 1.2);

    StdDraw.square(.2, .8, .1);
    StdDraw.filledSquare(.8, .8, .2);
    StdDraw.circle(.8, .2, .2);

    // draw a blue diamond, radius 0.1 (old method)
    StdDraw.setPenRadius(); // default radius
    StdDraw.setPenColor(Colors.BOOK_BLUE);
    double[] x = {.1, .2, .3, .2};
    double[] y = {.2, .3, .2, .1};
    StdDraw.filledPolygon(x, y);

    // draw a cyandiamond, radius 0.1 (new method)
    StdDraw.setPenColor(Colors.CYAN);
    StdDraw.filledDiamond(.45, .2, 0.1);

    // draw a magenta triangle, radius 0.1
    StdDraw.setPenColor(Colors.MAGENTA);
    StdDraw.filledTriangle(.45, 0.4, 0.1);

    // Green filled rectangle, rotated x degrees
    StdDraw.setPenColor(Colors.GREEN);
    StdDraw.filledAngledRectangle(.45, .8, .05, .2, 10);
    // StdDraw.filledAngledRectangle(0.2, 0.2, 0.2, 0.05, 90);
    // StdDraw.filledAngledRectangle(0, 0, 0.2, 0.05, 0);

    StdDraw.setPenColor(Colors.BOOK_RED);
    StdDraw.setPenRadius(.02);
    StdDraw.arc(.8, .2, .1, 120, 60);
    StdDraw.line(0.8, 0.2, 0.8, 0.3);

    // text
    StdDraw.setPenRadius();
    StdDraw.setPenColor(Colors.BLACK);
    StdDraw.text(0.2, 0.5, "black text");
    StdDraw.setPenColor(Colors.WHITE);
    StdDraw.text(0.8, 0.8, "white text");

    // Edge testing
    StdDraw.setPenColor(Colors.GRAY);
    // StdDraw.circle(0, 0, .2);
    StdDraw.line(0, 0, 0, 1);
  }
Ejemplo n.º 8
0
  /** Test client. */
  public static void main(String[] args) {
    StdDraw.square(.2, .8, .1);
    StdDraw.filledSquare(.8, .8, .2);
    StdDraw.circle(.8, .2, .2);

    StdDraw.setPenColor(StdDraw.BOOK_RED);
    StdDraw.setPenRadius(.02);
    StdDraw.arc(.8, .2, .1, 200, 45);

    // draw a blue diamond
    StdDraw.setPenRadius();
    StdDraw.setPenColor(StdDraw.BOOK_BLUE);
    double[] x = {.1, .2, .3, .2};
    double[] y = {.2, .3, .2, .1};
    StdDraw.filledPolygon(x, y);

    // text
    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.text(0.2, 0.5, "black text");
    StdDraw.setPenColor(StdDraw.WHITE);
    StdDraw.text(0.8, 0.8, "white text");
  }
Ejemplo n.º 9
0
  /** Test client. */
  public static void main(String[] args) {

    // set the scale of the coordinate system
    StdDraw.setXscale(0, 10);
    StdDraw.setYscale(0, 10);

    // Draw line
    StdDraw.line(1, 1, 8, 8);

    // Draw square
    StdDraw.setPenColor(StdDraw.RED);
    StdDraw.setPenRadius(.01);
    StdDraw.square(3, 3, 2);

    // Draw filled Square
    StdDraw.setPenColor(StdDraw.BLUE);
    StdDraw.filledSquare(5, 8, 2);

    // Draw Circle
    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.setPenRadius();
    StdDraw.circle(5, 5, 2);

    // text
    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.text(6, 1, "black text");
  }
Ejemplo n.º 10
-1
 /** This method cannot be called directly. */
 @Override
 public void mouseMoved(MouseEvent e) {
   synchronized (mouseLock) {
     mouseX = StdDraw.userX(e.getX());
     mouseY = StdDraw.userY(e.getY());
   }
 }