Exemplo 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);
  }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
0
 /** Set the pen size to the default (.002). */
 public static void setPenRadius() {
   setPenRadius(DEFAULT_PEN_RADIUS);
 }