Пример #1
0
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
Пример #2
0
 public static LatLonPoint getLatLonForPixel(
     double startLat, double startLon, double differenceX, double differenceY, float scale) {
   double startY = 20925.5249D * Math.toRadians(startLat);
   double startX = 20925.5249D * Math.cos(Math.toRadians(startLat)) * Math.toRadians(startLon);
   differenceX /= scale;
   differenceY /= scale;
   double endX = differenceX / 1000D + startX;
   double endY = (differenceY / 1000D - startY) * -1D;
   double endLat = Math.toDegrees(endY / 20925.5249D);
   double endLon = Math.toDegrees(endX / (20925.5249D * Math.cos(Math.toRadians(startLat))));
   return new LatLonPoint(endLat, endLon);
 }
Пример #3
0
 public void loseCoins() {
   int x = player1.getX();
   int y = player1.getY();
   double losePercentage = 0.1;
   for (int i = 0;
       i < (int) coins * losePercentage;
       i++) { // makes the user lose 10 percent of the coin and draws them in a circle
     // System.out.println(i);
     int xPos = x + (int) (100 * Math.cos(Math.toRadians((360 / (coins * losePercentage)) * i)));
     int yPos = y - (int) (100 * Math.sin(Math.toRadians((360 / (coins * losePercentage)) * i)));
     coinList.add(new Coin(xPos, yPos, 3));
   }
   coins -= (int) (coins * losePercentage);
 }
Пример #4
0
  /* CALCULATE COORDINATES: Determine new x-y coords given a start x-y and
  a distance and direction */
  public static void calcCoords(int index, int x, int y, double dist, double dirn) {
    while (dirn < 0.0) dirn = 360.0 + dirn;
    while (dirn > 360.0) dirn = dirn - 360.0;
    // System.out.println("dirn = " + dirn);

    // North-East
    if (dirn <= 90.0) {
      xValues[index] = x + (int) (Math.sin(Math.toRadians(dirn)) * dist);
      yValues[index] = y - (int) (Math.cos(Math.toRadians(dirn)) * dist);
      return;
    }
    // South-East
    if (dirn <= 180.0) {
      xValues[index] = x + (int) (Math.cos(Math.toRadians(dirn - 90)) * dist);
      yValues[index] = y + (int) (Math.sin(Math.toRadians(dirn - 90)) * dist);
      return;
    }
    // South-West
    if (dirn <= 90.0) {
      xValues[index] = x - (int) (Math.sin(Math.toRadians(dirn - 180)) * dist);
      yValues[index] = y + (int) (Math.cos(Math.toRadians(dirn - 180)) * dist);
    }
    // Nort-West
    else {
      xValues[index] = x - (int) (Math.cos(Math.toRadians(dirn - 270)) * dist);
      yValues[index] = y - (int) (Math.sin(Math.toRadians(dirn - 270)) * dist);
    }
  }
Пример #5
0
  @Override
  public void draw(GFX gfx) {
    float[] curr = toHSB(color);
    float[] start = toHSB(startColor);

    // hue, vertical
    gfx.translate(centerPoint.getX(), centerPoint.getY());
    for (double i = 0; i < 200; i++) {
      FlatColor c = FlatColor.hsb(i / 200 * 360.0, curr[1], curr[2]);
      gfx.setPaint(c);
      double y = start[0] * 200;
      gfx.drawLine(-5, i - y, +5, i - y);
    }
    gfx.translate(-centerPoint.getX(), -centerPoint.getY());

    // saturation, 30 degrees
    gfx.translate(centerPoint.getX(), centerPoint.getY());
    for (double i = 0; i < 200; i++) {
      FlatColor c = FlatColor.hsb(curr[0] * 360, i / 200.0, curr[2]);
      gfx.setPaint(c);
      double sin = Math.sin(Math.toRadians(30));
      double cos = Math.cos(Math.toRadians(30));
      double x = cos * i - cos * start[1] * 200 + 0;
      double y = sin * i - sin * start[1] * 200 + 0;
      // tx = cos(30)*i
      // tx/cos(30) = i
      gfx.drawLine(x, y - 5, x, y + 5);
    }
    gfx.translate(-centerPoint.getX(), -centerPoint.getY());

    // brightness, 150 degrees
    gfx.translate(centerPoint.getX(), centerPoint.getY());
    for (double i = 0; i < 200; i++) {
      FlatColor c = FlatColor.hsb(curr[0] * 360, curr[1], i / 200.0);
      gfx.setPaint(c);
      double sin = Math.sin(Math.toRadians(150));
      double cos = Math.cos(Math.toRadians(150));
      double x = cos * i - cos * start[2] * 200;
      double y = sin * i - sin * start[2] * 200;
      gfx.drawLine(x, y - 5, x, y + 5);
    }
    gfx.translate(-centerPoint.getX(), -centerPoint.getY());

    gfx.setPaint(color);
    double s = 16;
    gfx.fillOval(centerPoint.getX() - s / 2, centerPoint.getY() - s / 2, s, s);
    gfx.setPaint(FlatColor.BLACK);
    gfx.drawOval(centerPoint.getX() - s / 2, centerPoint.getY() - s / 2, s, s);
    gfx.drawRect(0, 0, getWidth(), getHeight());
  }
Пример #6
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image, (int) Math.round(xs - ws / 2.0), (int) Math.round(ys - hs / 2.0), null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
Пример #7
0
  public static void renderAngleRotatedTexturedRect(
      Vector3 renderOffset,
      Vector3 axis,
      double angleRad,
      double scale,
      double u,
      double v,
      double uLength,
      double vLength,
      float partialTicks) {
    GL11.glPushMatrix();
    removeStandartTranslationFromTESRMatrix(partialTicks);

    Vector3 renderStart = axis.clone().perpendicular().rotate(angleRad, axis).normalize();
    Tessellator tes = Tessellator.getInstance();
    VertexBuffer buf = tes.getBuffer();

    buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);

    Vector3 vec =
        renderStart
            .clone()
            .rotate(Math.toRadians(90), axis)
            .normalize()
            .multiply(scale)
            .add(renderOffset);
    buf.pos(vec.getX(), vec.getY(), vec.getZ()).tex(u, v + vLength).endVertex();

    vec = renderStart.clone().multiply(-1).normalize().multiply(scale).add(renderOffset);
    buf.pos(vec.getX(), vec.getY(), vec.getZ()).tex(u + uLength, v + vLength).endVertex();

    vec =
        renderStart
            .clone()
            .rotate(Math.toRadians(270), axis)
            .normalize()
            .multiply(scale)
            .add(renderOffset);
    buf.pos(vec.getX(), vec.getY(), vec.getZ()).tex(u + uLength, v).endVertex();

    vec = renderStart.clone().normalize().multiply(scale).add(renderOffset);
    buf.pos(vec.getX(), vec.getY(), vec.getZ()).tex(u, v).endVertex();

    tes.draw();

    GL11.glPopMatrix();
  }
Пример #8
0
  public void createPolygonRenderer() {
    // make the view window the entire screen
    viewWindow =
        new ViewWindow(0, 0, screen.getWidth(), screen.getHeight(), (float) Math.toRadians(75));

    Transform3D camera = new Transform3D();
    polygonRenderer = new BSPRenderer(camera, viewWindow);
  }
Пример #9
0
  public Image rotateImage(Image tilePiece, int degree) {

    ImageIcon icon = new ImageIcon(tilePiece);
    BufferedImage blankCanvas = new BufferedImage(80, 80, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) blankCanvas.getGraphics();
    g2.rotate(Math.toRadians(degree), 40, 40);
    g2.drawImage(tilePiece, 0, 0, this);
    return blankCanvas;
  }
Пример #10
0
  /**
   * Called back immediately after the OpenGL context is initialized. Can be used to perform
   * one-time initialization. Run only once.
   */
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
    glu = new GLU(); // get GL Utilities
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f); // set clear depth value to farthest
    gl.glEnable(GL_DEPTH_TEST); // enables depth testing
    gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
    gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting

    // Load the texture image
    try {
      // Create a OpenGL Texture object from (URL, mipmap, file suffix)
      // Use URL so that can read from JAR and disk file.
      texture =
          TextureIO.newTexture(
              this.getClass().getResource(textureFileName), false, textureFileType);
    } catch (GLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Use linear filter for texture if image is larger than the original texture
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // Use linear filter for texture if image is smaller than the original texture
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    // Texture image flips vertically. Shall use TextureCoords class to retrieve
    // the top, bottom, left and right coordinates, instead of using 0.0f and 1.0f.
    TextureCoords textureCoords = texture.getImageTexCoords();
    textureTop = textureCoords.top();
    textureBottom = textureCoords.bottom();
    //      textureLeft = textureCoords.left();
    //      textureRight = textureCoords.right();

    // Enable the texture
    texture.enable(gl);
    // gl.glEnable(GL_TEXTURE_2D);

    // we want back facing polygons to be filled completely and that we want front
    // facing polygons to be outlined only.
    gl.glPolygonMode(GL_BACK, GL_FILL); // Back Face Is Filled In
    gl.glPolygonMode(GL_FRONT, GL_LINE); // Front Face Is Drawn With Lines

    for (int x = 0; x < numPoints; x++) { // Loop Through The Y Plane
      for (int y = 0; y < numPoints; y++) {
        // Apply The Wave To Our Mesh
        // xmax is 45. Get 9 after dividing by 5. Subtract 4.5 to centralize.
        points[x][y][0] = (float) x / 5.0f - 4.5f;
        points[x][y][1] = (float) y / 5.0f - 4.5f;
        // Sine wave pattern
        points[x][y][2] = (float) (Math.sin(Math.toRadians(x / 5.0f * 40.0f)));
      }
    }
  }
Пример #11
0
 private void loopRotation() {
   if (previewRotation < 0) {
     previewRotation = Math.toRadians(270);
   } else if (previewRotation >= 2 * Math.PI) {
     previewRotation = 0;
   }
   if (structurePreview.getWidth() == 1 && structurePreview.getHeight() == 1) {
     previewRotation = 0;
   }
 }
Пример #12
0
 public BufferedImage rotate90(BufferedImage img) {
   int w = img.getWidth();
   int h = img.getHeight();
   BufferedImage dimg = new BufferedImage(h, w, img.getType());
   Graphics2D g = dimg.createGraphics();
   g.translate((h - w) / 2, (w - h) / 2);
   g.rotate(Math.toRadians(90), w / 2, h / 2);
   g.drawImage(img, null, 0, 0);
   g.dispose();
   return dimg;
 }
Пример #13
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees, rescaled
   * to w-by-h.
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param w the width of the image
   * @param h the height of the image
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws RuntimeException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double w, double h, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    double ws = factorX(w);
    double hs = factorY(h);
    if (ws < 0 || hs < 0) throw new RuntimeException("image " + s + " is corrupt");
    if (ws <= 1 && hs <= 1) pixel(x, y);

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image,
        (int) Math.round(xs - ws / 2.0),
        (int) Math.round(ys - hs / 2.0),
        (int) Math.round(ws),
        (int) Math.round(hs),
        null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
Пример #14
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   RenderingHints hints = new RenderingHints(null);
   hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
   g2.setRenderingHints(hints);
   g2.rotate(-Math.toRadians(degrees), w / 2, h / 2);
   g2.drawImage(dimg, 0, 0, this);
   g2.dispose();
 }
  // -----------------------------------------------------------------
  //  Draws the fractal recursively. Base case is an order of 1 for
  //  which a simple straight line is drawn. Otherwise three
  //  intermediate points are computed, and each line segment is
  //  drawn as a fractal.
  // -----------------------------------------------------------------
  public void branch(Graphics2D g2, Double x, Double y, Double length, Double angle, int order) {
    // g2.draw(Line2D.Double() line = new Line2D.Double());
    double angle1 = angle + bangle;
    double angle2 = angle - bangle;
    double angle3 = angle + 180;
    length = length * bfrac;

    double endX1 = (x - length * Math.sin(Math.toRadians(angle1)));
    double endY1 = (y - length * Math.cos(Math.toRadians(angle1)));
    double endX2 = (x - length * Math.sin(Math.toRadians(angle2)));
    double endY2 = (y - length * Math.cos(Math.toRadians(angle2)));
    double endX3 = (x - length * Math.sin(Math.toRadians(angle3)));
    double endY3 = (y - length * Math.cos(Math.toRadians(angle3)));

    g2.draw(new Line2D.Double(x, y, endX1, endY1));
    g2.draw(new Line2D.Double(x, y, endX2, endY2));
    g2.draw(new Line2D.Double(x, y, endX3, endY3));
    if (order == 1) g2.draw(new Line2D.Double(x, y, x, y - length));
    else {

      branch(g2, endX1, endY1, length, angle1, order - 1);
      branch(g2, endX2, endY2, length, angle2, order - 1);
      // branch (g2, endX3, endY3, length, angle3, order-1 );
    }
  }
Пример #16
0
  @Override
  public void draw(Graphics2D g) {
    AffineTransform save = g.getTransform();
    super.draw(g);

    int localx = -width / 2;
    int localy = -height / 2;

    if (isPlayer) g.setColor(Color.BLUE);
    if (isSelected) {
      g.fillRect(localx, localy, width, height);
    } else {
      g.drawRect(localx, localy, width, height);
    }
    int direction = this.getDirection();
    g.setColor(Color.RED);
    g.drawOval(0 - (size / 2), 0 - (size / 2), (int) size, (int) size);
    dx = ((double) Math.cos(Math.toRadians(90 - direction)) * width);
    dy = ((double) Math.sin(Math.toRadians(90 - direction)) * height);
    g.setColor(Color.black);
    g.drawLine(0, 0, 0, 20);
    g.setTransform(save);
  }
Пример #17
0
    void draw(Graphics2D g) {

      // toX/toY is tip of arrow and fx/fy is a point on the line -
      // fx/fy is used to determine direction & angle

      AffineTransform at = AffineTransform.getTranslateInstance(toX, toY);
      int b = 9;
      double theta = Math.toRadians(20);
      // The idea of using a GeneralPath is so we can
      // create the (three lines that make up the) arrow
      // (only) one time and then use AffineTransform to
      // place it anywhere we want.
      GeneralPath path = new GeneralPath();

      // distance between line and the arrow mark <** not **
      // Start a new line segment from the position of (0,0).
      path.moveTo(0, 0);
      // Create one of the two arrow head lines.
      int x = (int) (-b * Math.cos(theta));
      int y = (int) (b * Math.sin(theta));
      path.lineTo(x, y);

      // distance between line and the arrow mark <** not **
      // Make the other arrow head line.
      int x2 = (int) (-b * Math.cos(-theta));
      int y2 = (int) (b * Math.sin(-theta));
      // path.moveTo(0,0);
      path.lineTo(x2, y2);
      path.closePath();

      // theta is in radians
      double s, t;
      s = toY - fy; // calculate slopes.
      t = toX - fx;
      if (t != 0) {
        s = s / t;
        theta = Math.atan(s);
        if (t < 0) theta += Math.PI;
      } else if (s < 0) theta = -(Math.PI / 2);
      else theta = Math.PI / 2;

      at.rotate(theta);
      // at.rotate(theta,toX,toY);
      Shape shape = at.createTransformedShape(path);
      if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK);
      else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN);
      else g.setColor(ORANGE_RED);
      g.fill(shape);
      g.draw(shape);
    }
Пример #18
0
  private static LinkedList<Point2D> getCirclePoints(
      double centerLat, double centerLong, int numberOfPoints, double radius) {

    LinkedList<Point2D> Point2Ds = new LinkedList<Point2D>();

    double lat1, long1;
    double d_rad;
    double delta_pts;
    double radial, lat_rad, dlon_rad, lon_rad;

    // convert coordinates to radians
    lat1 = Math.toRadians(centerLat);
    long1 = Math.toRadians(centerLong);

    // radius is in meters
    d_rad = radius / 6378137;

    // loop through the array and write points
    for (int i = 0; i <= numberOfPoints; i++) {
      delta_pts = 360 / (double) numberOfPoints;
      radial = Math.toRadians((double) i * delta_pts);

      // This algorithm is limited to distances such that dlon < pi/2
      lat_rad =
          Math.asin(
              Math.sin(lat1) * Math.cos(d_rad)
                  + Math.cos(lat1) * Math.sin(d_rad) * Math.cos(radial));
      dlon_rad =
          Math.atan2(
              Math.sin(radial) * Math.sin(d_rad) * Math.cos(lat1),
              Math.cos(d_rad) - Math.sin(lat1) * Math.sin(lat_rad));
      lon_rad = ((long1 + dlon_rad + Math.PI) % (2 * Math.PI)) - Math.PI;

      Point2Ds.add(new Point2D.Double(Math.toDegrees(lat_rad), Math.toDegrees(lon_rad)));
    }
    return Point2Ds;
  }
  public void flecha(Graphics papel, int x1, int y1, int x2, int y2) {
    double ang = 0.0, angSep = 0.0;
    double tx = 0, ty = 0;
    int dist = 0;
    Point punto1 = null, punto2 = null;

    punto2 = new Point(x1, y1);
    punto1 = new Point(x2, y2);

    dist = 15;

    ty = -(punto1.y - punto2.y) * 1.0;
    tx = (punto1.x - punto2.x) * 1.0;
    ang = Math.atan(ty / tx);

    if (tx < 0) ang += Math.PI;
    Point p1 = new Point(), p2 = new Point(), punto = punto2;
    angSep = 25.0;

    p1.x = (int) (punto.x + dist * Math.cos(ang - Math.toRadians(angSep)));
    p1.y = (int) (punto.y - dist * Math.sin(ang - Math.toRadians(angSep)));
    p2.x = (int) (punto.x + dist * Math.cos(ang + Math.toRadians(angSep)));
    p2.y = (int) (punto.y - dist * Math.sin(ang + Math.toRadians(angSep)));

    Graphics2D g2D = (Graphics2D) papel;
    papel.setColor(Color.black);
    g2D.setStroke(new BasicStroke(1.2f));
    papel.drawLine(punto1.x, punto1.y, punto.x, punto.y);

    int x[] = {p1.x, punto.x, p2.x};
    int y[] = {p1.y, punto.y, p2.y};
    Polygon myTri = new Polygon(x, y, 3);
    papel.setColor(Color.BLACK);
    papel.drawPolygon(myTri);
    papel.fillPolygon(myTri);
  }
Пример #20
0
    public void paintLogo(Component c, Graphics g, int x, int y, int w, int h) {
      if (hasLogo(c)) {
        Graphics2D g2D = (Graphics2D) g;

        Font savedFont = g2D.getFont();
        g.setFont(logoFont);
        FontMetrics fm = JTattooUtilities.getFontMetrics((JComponent) c, g, c.getFont());
        String logo =
            JTattooUtilities.getClippedText(
                AbstractLookAndFeel.getTheme().getLogoString(), fm, h - 16);

        AffineTransform savedTransform = g2D.getTransform();

        Color fc = getLogoColorHi();
        Color bc = getLogoColorLo();

        if (JTattooUtilities.isLeftToRight(c)) {
          g2D.translate(fm.getAscent() + 1, h - shadowSize - 4);
          g2D.rotate(Math.toRadians(-90));
          g2D.setColor(bc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 0, 1);
          g2D.setColor(fc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 1, 0);
        } else {
          g2D.translate(w - shadowSize - 4, h - shadowSize - 4);
          g2D.rotate(Math.toRadians(-90));
          g2D.setColor(bc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 0, 1);
          g2D.setColor(fc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 1, 0);
        }

        g2D.setTransform(savedTransform);
        g2D.setFont(savedFont);
      }
    }
Пример #21
0
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2d = (Graphics2D)g;
   AffineTransform origXform = g2d.getTransform();
   AffineTransform newXform = (AffineTransform)(origXform.clone());
   //center of rotation is center of the panel
   int xRot = this.getWidth()/2;
   int yRot = this.getHeight()/2;
   newXform.rotate(Math.toRadians(currentAngle), xRot, yRot);
   g2d.setTransform(newXform);
   //draw image centered in panel
   int x = (getWidth() - image.getWidth(this))/2;
   int y = (getHeight() - image.getHeight(this))/2;
   g2d.drawImage(image, x, y, this);
   g2d.setTransform(origXform);
 }
Пример #22
0
 public static java.awt.geom.Point2D.Float getPixelsBetweenPoints(
     double startLat, double startLon, double endLat, double endLon, float scale) {
   double startY = 20925.5249D * Math.toRadians(startLat);
   double endY = 20925.5249D * Math.toRadians(endLat);
   double differenceY = (startY - endY) * 1000D;
   double startX = 20925.5249D * Math.cos(Math.toRadians(startLat)) * Math.toRadians(startLon);
   double endX = 20925.5249D * Math.cos(Math.toRadians(startLat)) * Math.toRadians(endLon);
   double differenceX = (endX - startX) * 1000D;
   return new java.awt.geom.Point2D.Float(
       (float) differenceX * scale, (float) (differenceY * (double) scale));
 }
Пример #23
0
 public static double getDistanceBetweenLatLons(
     double lat1, double lon1, double lat2, double lon2) {
   double dLat = lat2 - lat1;
   double dLon = lon2 - lon1;
   double a =
       Math.sin(Math.toRadians(dLat) / 2D) * Math.sin(Math.toRadians(dLat) / 2D)
           + Math.cos(Math.toRadians(lat1))
               * Math.cos(Math.toRadians(lat2))
               * Math.sin(Math.toRadians(dLon) / 2D)
               * Math.sin(Math.toRadians(dLon) / 2D);
   return 12742D * Math.atan2(Math.sqrt(a), Math.sqrt(1.0D - a));
 }
Пример #24
0
 public static java.awt.geom.Point2D.Float rotatePoint(
     java.awt.geom.Point2D.Float centerPoint, java.awt.geom.Point2D.Float point, float angle) {
   double radius =
       Math.sqrt(Math.pow(point.x - centerPoint.x, 2D) + Math.pow(point.y - centerPoint.y, 2D));
   double angleB1 = Math.toDegrees(Math.acos((double) (point.x - centerPoint.x) / radius));
   double x;
   double y;
   if (point.x <= centerPoint.x && point.y <= centerPoint.y) {
     x = (double) centerPoint.x + radius * Math.cos(Math.toRadians(angleB1 - (double) angle));
     y = (double) centerPoint.y - radius * Math.sin(Math.toRadians(angleB1 - (double) angle));
   } else if (point.x > centerPoint.x && point.y <= centerPoint.y) {
     x = (double) centerPoint.x + radius * Math.cos(Math.toRadians(angleB1 - (double) angle));
     y = (double) centerPoint.y - radius * Math.sin(Math.toRadians(angleB1 - (double) angle));
   } else if (point.x > centerPoint.x && point.y > centerPoint.y) {
     x = (double) centerPoint.x + radius * Math.cos(Math.toRadians(angleB1 + (double) angle));
     y = (double) centerPoint.y + radius * Math.sin(Math.toRadians(angleB1 + (double) angle));
   } else {
     x = (double) centerPoint.x + radius * Math.cos(Math.toRadians(angleB1 + (double) angle));
     y = (double) centerPoint.y + radius * Math.sin(Math.toRadians(angleB1 + (double) angle));
   }
   return new java.awt.geom.Point2D.Float((float) x, (float) y);
 }
Пример #25
0
  public Enemy(int type, int rank) {
    this.type = type;
    this.rank = rank;
    switch (rank) {
      case (1):
        color = Color.GREEN;
        switch (rank) {
          case (1):
            x = Math.random() * GamePanel.WIDTH;
            y = 0;
            r = 7;

            speed = 2;
            health = 2;

            double angle = Math.toRadians(Math.random() * 360);
            dx = Math.sin(angle) * speed;
            dy = Math.cos(angle) * speed;
        }
    }
  }
Пример #26
0
  private Tile[] rotate(int angle) {
    Tile[] newTiles = new Tile[4 * 4];
    int offsetX = 3, offsetY = 3;
    if (angle == 90) {
      offsetY = 0;
    } else if (angle == 270) {
      offsetX = 0;
    }

    double rad = Math.toRadians(angle);
    int cos = (int) Math.cos(rad);
    int sin = (int) Math.sin(rad);
    for (int x = 0; x < 4; x++) {
      for (int y = 0; y < 4; y++) {
        int newX = (x * cos) - (y * sin) + offsetX;
        int newY = (x * sin) + (y * cos) + offsetY;
        newTiles[(newX) + (newY) * 4] = tileAt(x, y);
      }
    }
    return newTiles;
  }
  /**
   * Paint the component.
   *
   * @param g The graphics context for painting
   * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
   */
  protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    fRenderer.paintComponent(g2, fButtonDelegate, this, 0, 0, getWidth(), getHeight(), true);

    ButtonModel model = getModel();
    boolean doOffset = model.isPressed() && model.isArmed();
    int offsetAmount = UIManager.getInt("Button.textShiftOffset");
    double degrees = Math.toRadians(-90);

    if (fRotation == LEFT) {
      int h = getHeight();
      g2.translate(0, h);
      g2.rotate(degrees);
      if (doOffset) {
        g2.translate(-offsetAmount, offsetAmount);
      }

      fRenderer.paintComponent(g2, fLabelDelegate, this, 0, 0, getHeight(), getWidth(), true);
      if (doOffset) {
        g2.translate(offsetAmount, -offsetAmount);
      }
      g2.rotate(-degrees);

      g2.translate(0, -h);
    } else {
      int w = getWidth();
      g2.translate(w, 0);
      g2.rotate(-degrees);
      if (doOffset) {
        g2.translate(offsetAmount, -offsetAmount);
      }
      fRenderer.paintComponent(g2, fLabelDelegate, this, 0, 0, getHeight(), getWidth(), true);
      if (doOffset) {
        g2.translate(-offsetAmount, offsetAmount);
      }
      g2.rotate(degrees);
      g2.translate(-w, 0);
    }
  }
Пример #28
0
  @Override
  public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) {
    Painter painter = null;
    if (context != null) {
      painter = (Painter) context.getStyle().get(context, key);
    }
    if (painter == null) {
      painter = (Painter) UIManager.get(prefix + "[Enabled]." + key);
    }

    if (painter != null && context != null) {
      JComponent c = context.getComponent();
      boolean rotate = false;
      boolean flip = false;
      // translatex and translatey are additional translations that
      // must occur on the graphics context when rendering a toolbar
      // icon
      int translatex = 0;
      int translatey = 0;
      if (c instanceof JToolBar) {
        JToolBar toolbar = (JToolBar) c;
        rotate = toolbar.getOrientation() == JToolBar.VERTICAL;
        flip = !toolbar.getComponentOrientation().isLeftToRight();
        Object o = NimbusLookAndFeel.resolveToolbarConstraint(toolbar);
        // we only do the +1 hack for UIResource borders, assuming
        // that the border is probably going to be our border
        if (toolbar.getBorder() instanceof UIResource) {
          if (o == BorderLayout.SOUTH) {
            translatey = 1;
          } else if (o == BorderLayout.EAST) {
            translatex = 1;
          }
        }
      }
      if (g instanceof Graphics2D) {
        Graphics2D gfx = (Graphics2D) g;
        gfx.translate(x, y);
        gfx.translate(translatex, translatey);
        if (rotate) {
          gfx.rotate(Math.toRadians(90));
          gfx.translate(0, -w);
          painter.paint(gfx, context.getComponent(), h, w);
          gfx.translate(0, w);
          gfx.rotate(Math.toRadians(-90));
        } else if (flip) {
          gfx.scale(-1, 1);
          gfx.translate(-w, 0);
          painter.paint(gfx, context.getComponent(), w, h);
          gfx.translate(w, 0);
          gfx.scale(-1, 1);
        } else {
          painter.paint(gfx, context.getComponent(), w, h);
        }
        gfx.translate(-translatex, -translatey);
        gfx.translate(-x, -y);
      } else {
        // use image if we are printing to a Java 1.1 PrintGraphics as
        // it is not a instance of Graphics2D
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D gfx = img.createGraphics();
        if (rotate) {
          gfx.rotate(Math.toRadians(90));
          gfx.translate(0, -w);
          painter.paint(gfx, context.getComponent(), h, w);
        } else if (flip) {
          gfx.scale(-1, 1);
          gfx.translate(-w, 0);
          painter.paint(gfx, context.getComponent(), w, h);
        } else {
          painter.paint(gfx, context.getComponent(), w, h);
        }
        gfx.dispose();
        g.drawImage(img, x, y, null);
        img = null;
      }
    }
  }
Пример #29
0
  /**
   * Draws the stars on the flag. Two integer arrays are used to store the x-coordinates and
   * y-coordinates of a star (a total of 10 points for each of the 10 vertices). The outer radius is
   * then calculated by multiplying the actual height by the star diameter ratio then dividing by 2.
   * The inner radius is then calculated using trigonometric relationships between the first point
   * (outer right most point) and the point directly to the left of it (the inner right most point),
   * based on the assumption that the y-coordinates of these points are the same. The method then
   * uses a series of for loops to draw the stars, drawing them row by row and 1 by 1 across each
   * row. The outer most for loop increments each row while also determining the number of stars in
   * each row and the initial x offset for the first star, both of which vary depending on the row
   * number. The intermediate for loop increments each column while also determining the X and Y
   * coordinate centers for each star. The inner most for loop generates the x and y coordinates for
   * each of the 10 vertices for each star and stores them in their respective arrays to be used by
   * the fillPolygon method to draw each star.
   *
   * @param g The graphics component on which to draw the stars
   * @param initialWidthOffset The initial width offset towards the right from the left side of the
   *     frame
   * @param initialHeightOffset The initial height offset towards the bottom from the top of the
   *     frame
   * @param actualWidth The actual width of the window, not including the frame border
   * @param actualHeight The actual height of the window, not including the frame border
   */
  public void drawStars(
      Graphics g,
      int initialWidthOffset,
      int initialHeightOffset,
      int actualWidth,
      int actualHeight) {

    g.setColor(Color.WHITE);

    int[] xPoints = new int[10];
    int[] yPoints = new int[10];

    // outer radius
    double r1 = actualHeight * (STAR_DIAMETER / 2);

    // inner radius
    double r2 = r1 * Math.sin(Math.toRadians(18)) / Math.sin(Math.toRadians(54));

    for (int row = 0; row < 9; row++) {

      /* The number of stars per row initially begin at 6 for the first row and alternate between
       * 5 and 6 for each successive row.
       */
      int starsPerRow = (row % 2 == 0) ? 6 : 5;

      /* The initial star x offset is initially 1 for the first row, but alternates between 2
       * and 1 for each successive row.
       */
      int initialStarXOffset = (row % 2 == 0) ? 1 : 2;

      for (int col = 0; col < starsPerRow; col++) {

        /* The x-coordinate center is calculated based on the initial width offset and the star x
         * offset proportional to the actual height, in addition to the initial star x offset and the
         * column number. The x-coordinate center is incremented by the 2 times the star x offset in
         * proportion to the actual height for each iteration of the intermediate for loop. The
         * y-coordinate center is calculated based on the initial height offset and the star y offset
         * proportional to the actual height, in addition to the row number. The y-coordinate center is
         * incremented by the star y offset in proportion to the actual height for each iteration of the
         * outer most for loop.
         */
        int starCenterX =
            (initialWidthOffset)
                + (int) ((actualHeight * STAR_X_OFFSET) * (initialStarXOffset + 2 * col));
        int starCenterY =
            (initialHeightOffset) + (int) ((actualHeight * STAR_Y_OFFSET) * (1 + row));

        for (int i = 0; i < 10; i++) {

          /* Assigns different x and y coordinates for each of the 10 points on a star depending on
           * whether the point is an even/outer point (i % 2) == 0, or an odd/inner point. Points are
           * calculated based on the center x and y coordinates and with the trigonometric sin and cos
           * functions. The angle measure is incremented by 36 degrees for each iteration of the for loop, for
           * use in the cos and sin functions.
           */
          xPoints[i] =
              (i % 2) == 0
                  ? starCenterX + (int) (r1 * Math.cos(Math.toRadians(18 + 36 * i)))
                  : starCenterX + (int) (r2 * Math.cos(Math.toRadians(54 + 36 * (i - 1))));
          yPoints[i] =
              (i % 2) == 0
                  ? starCenterY - (int) (r1 * Math.sin(Math.toRadians(18 + 36 * i)))
                  : starCenterY - (int) (r2 * Math.sin(Math.toRadians(54 + 36 * (i - 1))));
        }

        g.fillPolygon(xPoints, yPoints, 10);
      }
    }
  }
Пример #30
0
public class VJYbar implements GraphSeries {
  public int dataSize;
  public int capacity;
  public int lineWidth;
  public int pX, pY, pWidth, pHeight; // container's boundary
  public int[] xPoints;
  public int[] yPoints;
  public Color fgColor;
  public float alphaSet;
  public Color bgColor;
  public boolean bValid = false;
  public boolean bXorMode = false;
  public boolean bTopLayer = false;
  public Rectangle clipRect;
  private static double deg90 = Math.toRadians(90.0);

  public VJYbar() {
    this.dataSize = 0;
    this.capacity = 0;
    this.lineWidth = 1;
    this.pWidth = 100;
    this.pHeight = 100;
    this.pX = 0;
    this.pY = 0;
    this.alphaSet = 1.0f;
  }

  public int[] getXPoints() {
    return xPoints;
  }

  public void setXPoints(int[] pnts) {
    xPoints = pnts;
  }

  public int[] getYPoints() {
    return yPoints;
  }

  public void setYPoints(int[] pnts) {
    yPoints = pnts;
  }

  public void setColor(Color c) {
    fgColor = c;
  }

  public Color getColor() {
    return fgColor;
  }

  public void setBgColor(Color c) {
    bgColor = c;
  }

  public Color getBgColor() {
    return bgColor;
  }

  public void setSize(int s) {
    dataSize = s;
    setCapacity(s);
  }

  public int getSize() {
    return dataSize;
  }

  public void setLineWidth(int n) {
    lineWidth = n;
    if (lineWidth < 1 || lineWidth > 50) lineWidth = 1;
  }

  public int getLineWidth() {
    return lineWidth;
  }

  public void setCapacity(int s) {
    if (capacity >= s) return;
    if (s < 4) s = 4;
    capacity = s;
    xPoints = new int[s];
    yPoints = new int[s];
  }

  public boolean isValid() {
    return bValid;
  }

  public void setValid(boolean s) {
    bValid = s;
  }

  public void setXorMode(boolean b) {
    bXorMode = b;
  }

  public boolean isXorMode() {
    return bXorMode;
  }

  public void setTopLayer(boolean b) {
    bTopLayer = b;
  }

  public boolean isTopLayer() {
    return bTopLayer;
  }

  public void setAlpha(float n) {
    alphaSet = n;
  }

  public float getAlpha() {
    return alphaSet;
  }

  public boolean intersects(int x, int y, int x2, int y2) {
    if (!bValid || capacity <= 0) return false;
    if (x2 < xPoints[0] || x > xPoints[dataSize - 1]) return false;
    if (y2 < yPoints[0] || y > yPoints[0]) return false;
    return true;
  }

  public void setConatinerGeom(int x, int y, int w, int h) {
    pX = x;
    pY = y;
    pWidth = w;
    pHeight = h;
  }

  public void draw(Graphics2D g, boolean bVertical, boolean bRight) {
    if (!bValid || dataSize < 1) return;
    int tx = pX;
    int ty = pY;

    g.setColor(fgColor);
    if (bVertical) {
      if (bRight) {
        tx = pX + pWidth;
        ty = pY;
        g.translate(tx, ty);
        g.rotate(deg90);
      } else {
        tx = pX;
        ty = pY + pHeight;
        g.translate(tx, ty);
        g.rotate(-deg90);
      }
    } else {
      if (tx != 0 || ty != 0) g.translate(tx, ty);
    }

    if (dataSize > 1) g.drawPolyline(xPoints, yPoints, dataSize);
    else g.drawLine(xPoints[0], yPoints[0], xPoints[0], yPoints[0]);

    if (bVertical) {
      if (bRight) {
        g.rotate(-deg90);
      } else g.rotate(deg90);
    }
    if (tx != 0 || ty != 0) g.translate(-tx, -ty);
  }
}