Esempio n. 1
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);
        }
      }
    }
  }
Esempio n. 2
0
 /**
  * Get the bounds for this <code>MetSymbol</code> relative to the point specified.
  *
  * @param loc Java coordinates to draw at
  * @return Rectangle based on that point, the offset and the width and height of the symbol.
  */
 public Rectangle getBounds(Point2D loc) {
   if (offset != null) {
     bounds.x = offset.x + (int) loc.getX() - bounds.width / 2;
     bounds.y = offset.y + (int) loc.getY() - bounds.height / 2;
   } else {
     bounds.x = (int) loc.getX();
     bounds.y = (int) loc.getY();
   }
   return bounds;
 }
Esempio n. 3
0
  /**
   * Zoom, preserving the center point on the screen. (When we draw, the center point may be moved
   * in order to maximize the amount of image seen on screen.) *
   */
  void adjustZoom(double z, Point2D cp) {
    if (cp == null) cp = new Point2D.Double(getWidth() / 2, getHeight() / 2);

    Point2D cxt = componentToImage(cp);
    double tx = cp.getX() - cxt.getX() * z;
    double ty = cp.getY() - cxt.getY() * z;

    t = new AffineTransform();
    t.translate(tx, ty);
    t.scale(z, z);

    fit = false;
    repaint();
  }
Esempio n. 4
0
  public synchronized void paint(Graphics gin) {
    Graphics2D g = (Graphics2D) gin;

    if (im == null) return;

    int height = getHeight();
    int width = getWidth();

    if (fit) {
      t = new AffineTransform();
      double scale = Math.min(((double) width) / im.getWidth(), ((double) height) / im.getHeight());
      // we'll re-center the transform in a moment.
      t.scale(scale, scale);
    }

    // if the image (in either X or Y) is smaller than the view port, then center
    // the image with respect to that axis.
    double mwidth = im.getWidth() * t.getScaleX();
    double mheight = im.getHeight() * t.getScaleY();
    if (mwidth < width)
      t.preConcatenate(
          AffineTransform.getTranslateInstance((width - mwidth) / 2.0 - t.getTranslateX(), 0));
    if (mheight < height)
      t.preConcatenate(
          AffineTransform.getTranslateInstance(0, (height - mheight) / 2.0 - t.getTranslateY()));

    // if we're allowing panning (because only a portion of the image is visible),
    // don't allow translations that show less information that is possible.
    Point2D topleft = t.transform(new Point2D.Double(0, 0), null);
    Point2D bottomright = t.transform(new Point2D.Double(im.getWidth(), im.getHeight()), null);

    if (mwidth > width) {
      if (topleft.getX() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(-topleft.getX(), 0));
      if (bottomright.getX() < width)
        t.preConcatenate(AffineTransform.getTranslateInstance(width - bottomright.getX(), 0));
      //		    t.translate(width-bottomright.getX(), 0);
    }
    if (mheight > height) {
      if (topleft.getY() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, -topleft.getY()));
      if (bottomright.getY() < height)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, height - bottomright.getY()));
    }

    g.drawImage(im, t, null);
  }
Esempio n. 5
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.translate(x, y);

    g2.setStroke(new BasicStroke(BORDER_WIDTH));
    g2.setPaint(LINE_COLOR);
    g2.draw(BORDER);

    g2.setStroke(new BasicStroke(SLIT_WIDTH));
    g2.setColor(UIManager.getColor("Panel.background"));

    int n = SLIT_NUM + 1;
    int v = ICON_SIZE / n;
    int m = n * v;
    for (int i = 1; i < n; i++) {
      int a = i * v;
      g2.drawLine(a, 0, a, m);
      g2.drawLine(0, a, m, a);
    }

    // g2.drawLine(1 * v, 0 * v, 1 * v, 4 * v);
    // g2.drawLine(2 * v, 0 * v, 2 * v, 4 * v);
    // g2.drawLine(3 * v, 0 * v, 3 * v, 4 * v);
    // g2.drawLine(0 * v, 1 * v, 4 * v, 1 * v);
    // g2.drawLine(0 * v, 2 * v, 4 * v, 2 * v);
    // g2.drawLine(0 * v, 3 * v, 4 * v, 3 * v);

    g2.setPaint(LINE_COLOR);
    Rectangle2D b = ARROW.getBounds();
    Point2D p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d);
    AffineTransform toCenterAT =
        AffineTransform.getTranslateInstance(ICON_SIZE / 2d - p.getX(), ICON_SIZE / 2d - p.getY());
    g2.fill(toCenterAT.createTransformedShape(ARROW));
    g2.dispose();
  }
  private void drawArrow(Graphics2D g, double fx, double fy, double tx, double ty) {
    double d = Point2D.distance(fx, fy, tx, ty);

    if (d == 0) return;

    double t = arrow_size / d;
    double cx0 = tx + 2 * t * (fx - tx);
    double cy0 = ty + 2 * t * (fy - ty);
    double cx1 = cx0 + t * (fy - ty);
    double cy1 = cy0 - t * (fx - tx);
    double cx2 = cx0 - t * (fy - ty);
    double cy2 = cy0 + t * (fx - tx);

    g.setStroke(arrow_stroke);
    Line2D.Double l2 = new Line2D.Double(cx1, cy1, tx, ty);
    g.draw(l2);
    l2.setLine(cx2, cy2, tx, ty);
    g.draw(l2);
  }
Esempio n. 7
0
  /*
   *  Uses linear interpolation to translate a 3D Window Point
   *  Into a 2D Viewport point
   */
  public static Point2D WindowToViewPort(Point3D point) {
    Point2D tmpCoordinate = new Point2D(0, 0);

    tmpCoordinate.x =
        LinearInterpolation(curVP.LeftX, curVP.RightX, curWin.LeftX, curWin.RightX, point.x);
    if (tmpCoordinate.x < curVP.LeftX) {
      tmpCoordinate.x = curVP.LeftX;
    } else if (tmpCoordinate.x > curVP.RightX) {
      tmpCoordinate.x = curVP.RightX;
    }
    tmpCoordinate.y =
        LinearInterpolation(curVP.BotY, curVP.TopY, curWin.BotY, curWin.TopY, point.y);
    if (tmpCoordinate.y < curVP.BotY) {
      tmpCoordinate.y = curVP.BotY;
    } else if (tmpCoordinate.y > curVP.TopY) {
      tmpCoordinate.y = curVP.TopY;
    }

    return tmpCoordinate;
  }
Esempio n. 8
0
 /**
  * Paint a rectangle point
  *
  * @param g Graphics to use for painting
  * @param c DisplayCanvas to paint on
  */
 private void paintRectPoint(Graphics g, DisplayCanvas c) {
   Rectangle nb = transformOutput(c, getBounds());
   g.setColor(Color.red);
   Point2D rp = getPointOnRect(rectPoint, nb);
   g.fillRect((int) rp.getX() - 3, (int) rp.getY() - 3, 6, 6);
 }
Esempio n. 9
0
    public void paintComponent(final Graphics g) {
      final Graphics2D g2 = (Graphics2D) g;
      g2.setBackground(backgroundColor);
      g2.clearRect(0, 0, frameWidth, overViewHeight);

      if (this.points.size() > 0) {
        g2.setColor(Color.blue);
        // draw the lines
        g2.setStroke(stroke);
        if (points.size() > frameWidth) { // draw contour
          // g2.setStroke(thickerStroke);
          for (int i = 0; i < this.points.size() - 1; i += 4) {
            Point2D.Float pt1 = points.get(i).getDispPoint();
            // Point2D.Float pt2  = new Point2D.Float(pt1.x, pt1.y/2);
            Point2D.Float pt2 = points.get(i + 1).getDispPoint();
            Point2D.Float pt3 = points.get(i + 2).getDispPoint();
            Point2D.Float pt4 = points.get(i + 3).getDispPoint();

            //						//Point2D.Float pt4  = new Point2D.Float(pt2.x, pt2.y/2);
            g2.draw(new Line2D.Float(pt1, pt2));
            // g2.setColor(waveLiteColor);
            g.setColor(waveLiteColor);
            g2.draw(new Line2D.Float(pt2, pt3));
            g2.setColor(waveColor);
            g2.draw(new Line2D.Float(pt3, pt4));
            //						g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
            //								this.points.get(i+1).getDispPoint()));
            //						g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
            //								this.points.get(i+1).getDispPoint()));
            //						g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
            //								this.points.get(i+1).getDispPoint()));
          }

        } else {
          for (int i = 0; i < this.points.size() - 1; i++) {
            g2.draw(
                new Line2D.Float(
                    this.points.get(i).getDispPoint(), this.points.get(i + 1).getDispPoint()));
          }
        }
      }

      // draw the selection if it exists
      if (viewBeginX != 0 && viewEndX != 0) {
        g2.setColor(overViewSelectionColor);
        g2.fillRect(viewBeginX, 0, viewEndX - viewBeginX + 1, overViewHeight);
      }

      final double totalTimeInSec = data.size() / myHelper.getSamplingRate();
      final int mainTickDist = (int) Math.floor(frameWidth / totalTimeInSec);
      final int smallTickDist = (int) Math.floor(mainTickDist / (numOfSmallTicks + 1));

      // draw the base line;
      g2.setColor(Color.black);
      g2.setStroke(thickerStroke);
      final Point2D base = new Point2D.Double(0, this.baseLineLocY);
      Point2D pt = new Point2D.Double(frameWidth, this.baseLineLocY);
      g2.draw(new Line2D.Double(base, pt));

      // draw the ticks
      pt = new Point2D.Double(0, baseLineLocY - this.mainTickHeight);
      // show text for main ticks
      g2.setFont(textFont2);
      for (int i = 0; i <= totalTimeInSec; i++) {
        g2.setStroke(thickerStroke);
        g2.draw(new Line2D.Double(base, pt));

        g2.drawString(i + "", (float) base.getX(), (float) base.getY() + textHeightFromBase);

        for (int j = 0; j < numOfSmallTicks; j++) {
          g2.setStroke(stroke);
          base.setLocation(base.getX() + smallTickDist, baseLineLocY);
          pt.setLocation(pt.getX() + smallTickDist, baseLineLocY - this.smallTickHeight);

          if (smallTickDist > 100) {
            g2.drawString(
                (j + 1) * 0.2 + 1 + "",
                (float) base.getX(),
                (float) base.getY() + textHeightFromBase);
          }

          if (base.getX() > frameWidth) {
            break;
          }
          g2.draw(new Line2D.Double(base, pt));
        }
        base.setLocation(base.getX() + smallTickDist, baseLineLocY);
        pt.setLocation(pt.getX() + smallTickDist, baseLineLocY - mainTickHeight);
      }
    }