Esempio n. 1
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);
  }
Esempio n. 2
0
  public Environment() {
    StdDraw.setCanvasSize(WINDOW_HEIGHT, WINDOW_LENGTH); // pixel size of window

    // Determines how the maze scales within the window
    StdDraw.setXscale(0, MAZE_SIZE + 2);
    StdDraw.setYscale(0, MAZE_SIZE + 2);

    validMaze = false;

    maze = new Maze(MAZE_SIZE); // create a new maze object

    StdDraw.show(0); // Show the maze window we have just created
    maze.draw(); // Draw the maze
    StdDraw.show(200); // Show this for 200 ms

    // pass the argument "true" to see the maze solve
    validMaze = solve(false); // solve the maze, but don't draw it
  }
Esempio n. 3
0
  // init
  private static void init() {
    if (frame != null) frame.setVisible(false);

    frame = new JFrame();
    offscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    onscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    offscreen = offscreenImage.createGraphics();
    onscreen = onscreenImage.createGraphics();
    setXscale();
    setYscale();
    offscreen.setColor(DEFAULT_CLEAR_COLOR);
    offscreen.fillRect(0, 0, width, height);
    setPenColor();
    setPenRadius();
    setFont();
    clear();

    // add anti-aliasing
    RenderingHints hints =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    offscreen.addRenderingHints(hints);

    // frame stuff
    ImageIcon icon = new ImageIcon(onscreenImage);
    JLabel draw = new JLabel(icon);

    draw.addMouseListener(std);
    draw.addMouseMotionListener(std);

    frame.setContentPane(draw);
    frame.addKeyListener(std); // JLabel cannot get keyboard focus
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // closes all windows
    // frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // closes only current window
    frame.setTitle("Standard Draw");
    frame.setJMenuBar(createMenuBar());
    frame.pack();
    frame.requestFocusInWindow();
    frame.setVisible(true);
  }
Esempio n. 4
0
 /**
  * Set the x-scale and y-scale (a 10% border is added to the values)
  *
  * @param min the minimum value of the x- and y-scales
  * @param max the maximum value of the x- and y-scales
  */
 public static void setScale(double min, double max) {
   setXscale(min, max);
   setYscale(min, max);
 }
Esempio n. 5
0
 /** Set the x-scale to be the default (between 0.0 and 1.0). */
 public static void setXscale() {
   setXscale(DEFAULT_XMIN, DEFAULT_XMAX);
 }