コード例 #1
0
ファイル: MaxiCode.java プロジェクト: Jakel2006/jZintRep
  @Override
  public void plotSymbol() {
    int row, col;
    Hexagon thisHex;
    Ellipse2D.Double thisEllipse;
    double x, y;
    int i;
    double[] radii = {10.85, 8.97, 7.10, 5.22, 3.31, 1.43};

    // Hexagons
    for (row = 0; row < 33; row++) {
      for (col = 0; col < 30; col++) {
        if (grid[row][col]) {
          thisHex = new Hexagon();

          x = (2.46 * col) + 1.23;
          if ((row & 1) != 0) {
            x += 1.23;
          }
          y = (2.135 * row) + 1.43;

          thisHex.setCentre(x, y);
          hex.add(thisHex);
        }
      }
    }

    // Circles
    for (i = 0; i < 6; i++) {
      thisEllipse = new Ellipse2D.Double();
      thisEllipse.setFrameFromCenter(35.76, 35.60, 35.76 + radii[i], 35.60 + radii[i]);
      target.add(thisEllipse);
    }
  }
コード例 #2
0
ファイル: ClockIcon.java プロジェクト: jiajiewu1988/151OO_HW2
  /**
   * Paint the clock
   *
   * @param c a component
   * @param g graphic object
   * @param x
   * @param y
   */
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g;
    Ellipse2D.Double circle = new Ellipse2D.Double();
    circle.setFrameFromCenter(250, 250, 400, 400);
    g2.draw(circle);

    Line2D.Double hHand =
        new Line2D.Double(
            250,
            250,
            250 + HOUR_HAND_LENGTH * Math.sin(Math.PI * (double) hour / 6),
            250 - HOUR_HAND_LENGTH * Math.cos(Math.PI * (double) hour / 6));
    Line2D.Double mHand =
        new Line2D.Double(
            250,
            250,
            250 + MIN_HAND_LENGTH * Math.sin(Math.PI * (double) min / 30),
            250 - MIN_HAND_LENGTH * Math.cos(Math.PI * (double) min / 30));
    Line2D.Double sHand =
        new Line2D.Double(
            250,
            250,
            250 + SEC_HAND_LENGTH * Math.sin(Math.PI * (double) sec / 30),
            250 - SEC_HAND_LENGTH * Math.cos(Math.PI * (double) sec / 30));
    g2.draw(hHand);
    g2.draw(mHand);
    g2.draw(sHand);
  }