Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
0
  private void renderBlackout(Graphics g, int x, int y, int radius) {
    if (radius > 320) return;

    int[] xp = new int[20];
    int[] yp = new int[20];
    for (int i = 0; i < 16; i++) {
      xp[i] = x + (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y + (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 240;
    xp[18] = 0;
    yp[18] = 240;
    xp[19] = 0;
    yp[19] = y;
    g.fillPolygon(xp, yp, xp.length);

    for (int i = 0; i < 16; i++) {
      xp[i] = x - (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y - (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 0;
    xp[18] = 0;
    yp[18] = 0;
    xp[19] = 0;
    yp[19] = y;

    g.fillPolygon(xp, yp, xp.length);
  }
  // -----------------------------------------------------------------
  //  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 );
    }
  }
Ejemplo n.º 4
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int xCenter = getSize().width / 2;
    int yCenter = getSize().height / 2;
    int radius = (int) (Math.min(getSize().width, getSize().height) * 0.4);

    // Create a Polygon object
    Polygon polygon = new Polygon();

    // Add points to the polygon
    polygon.addPoint(xCenter + radius, yCenter);
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(2 * Math.PI / 6)));
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(2 * 2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(2 * 2 * Math.PI / 6)));
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(3 * 2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(3 * 2 * Math.PI / 6)));
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(4 * 2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(4 * 2 * Math.PI / 6)));
    polygon.addPoint(
        (int) (xCenter + radius * Math.cos(5 * 2 * Math.PI / 6)),
        (int) (yCenter - radius * Math.sin(5 * 2 * Math.PI / 6)));

    // Draw the polygon
    g.drawPolygon(polygon);
  }
Ejemplo n.º 5
0
 private void drawArrow(Graphics2D g2, double theta, double x0, double y0) {
   double x = x0 - barb * Math.cos(theta + phi);
   double y = y0 - barb * Math.sin(theta + phi);
   g2.draw(new Line2D.Double(x0, y0, x, y));
   x = x0 - barb * Math.cos(theta - phi);
   y = y0 - barb * Math.sin(theta - phi);
   g2.draw(new Line2D.Double(x0, y0, x, y));
 }
Ejemplo n.º 6
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));
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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));
 }
Ejemplo n.º 9
0
 /**
  * Calculate great circle distance from country's capitolLocation to another MapPoint. Formula
  * from http://www.gcmap.com/faq/gccalc
  *
  * @param otherCapitol
  * @return great circle distance in km
  */
 public final double getShippingDistance(MapPoint otherCapitol) {
   double radianConversion = (Math.PI) / 180;
   double lon1 = getCapitolLocation().getLon() * radianConversion;
   double lat1 = capitolLocation.getLat() * radianConversion;
   double lon2 = otherCapitol.getLon() * radianConversion;
   double lat2 = otherCapitol.getLat() * radianConversion;
   double theta = lon2 - lon1;
   double dist =
       Math.acos(
           Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(theta));
   if (dist < 0) dist = dist + Math.PI;
   dist = dist * 6371.2;
   return dist;
 }
Ejemplo n.º 10
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());
  }
Ejemplo n.º 11
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);
    }
Ejemplo n.º 12
0
  // For now the final output is unusable.  The associated quantization step
  // needs some tweaking.  If you get this part working, please let me know.
  public double[][] forwardDCTExtreme(float[][] input) {
    double[][] output = new double[N][N];
    double tmp0;
    double tmp1;
    double tmp2;
    double tmp3;
    double tmp4;
    double tmp5;
    double tmp6;
    double tmp7;
    double tmp10;
    double tmp11;
    double tmp12;
    double tmp13;
    double z1;
    double z2;
    double z3;
    double z4;
    double z5;
    double z11;
    double z13;
    int i;
    int j;
    int v;
    int u;
    int x;
    int y;

    for (v = 0; v < 8; v++) {
      for (u = 0; u < 8; u++) {
        for (x = 0; x < 8; x++) {
          for (y = 0; y < 8; y++) {
            output[v][u] +=
                (((double) input[x][y])
                    * Math.cos(((double) ((2 * x) + 1) * (double) u * Math.PI) / (double) 16)
                    * Math.cos(((double) ((2 * y) + 1) * (double) v * Math.PI) / (double) 16));
          }
        }

        output[v][u] *=
            ((double) (0.25)
                * ((u == 0) ? ((double) 1.0 / Math.sqrt(2)) : (double) 1.0)
                * ((v == 0) ? ((double) 1.0 / Math.sqrt(2)) : (double) 1.0));
      }
    }

    return output;
  }
Ejemplo n.º 13
0
 /**
  * Rotates a two-dimensional vector by the angle alpha.
  *
  * @param p Point
  * @param alpha double
  * @return q Point
  */
 public static Point rotate(Point p, double alpha) {
   double sina = Math.sin(alpha);
   double cosa = Math.cos(alpha);
   Point q = new Point();
   q.setLocation(p.getX() * cosa - p.getY() * sina, p.getX() * sina + p.getY() * cosa);
   return q;
 }
Ejemplo n.º 14
0
  public static void main(String[] args) {
    Plot2DPanel p2 = new Plot2DPanel();

    double[][] XYZ = new double[100][2];
    for (int j = 0; j < XYZ.length; j++) {
      XYZ[j][0] = 2 * Math.PI * (double) j / XYZ.length;
      XYZ[j][1] = Math.sin(XYZ[j][0]);
    }
    double[][] XYZ2 = new double[100][2];
    for (int j = 0; j < XYZ2.length; j++) {
      XYZ2[j][0] = 2 * Math.PI * (double) j / XYZ.length;
      XYZ2[j][1] = Math.sin(2 * XYZ2[j][0]);
    }

    p2.addLinePlot("sin", Color.RED, AbstractDrawer.DOTTED_LINE, XYZ);
    p2.setBackground(new Color(200, 0, 0));
    p2.addLinePlot("sin2", Color.BLUE, AbstractDrawer.CROSS_DOT, XYZ2);

    p2.setLegendOrientation(PlotPanel.SOUTH);
    new FrameView(p2).setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    Plot3DPanel p = new Plot3DPanel();

    XYZ = new double[100][3];
    for (int j = 0; j < XYZ.length; j++) {
      XYZ[j][0] = 2 * Math.PI * (double) j / XYZ.length;
      XYZ[j][1] = Math.sin(XYZ[j][0]);
      XYZ[j][2] = Math.sin(XYZ[j][0]) * Math.cos(XYZ[j][1]);
    }
    p.addLinePlot("toto", XYZ);

    p.setLegendOrientation(PlotPanel.SOUTH);
    new FrameView(p).setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  }
Ejemplo n.º 15
0
  /**
   * Draws an open star with a specified number of points.<br>
   * The center of this star is specified by centerX,centerY and its size is specified by radius
   * <br>
   * (As in the radius of the circle the star would fit inside). <br>
   * Precondition: points >= 2 <br>
   * Example: <br>
   * Expo.drawStar(g,300,200,100,8); <br>
   * Draws an open star with 8 points and a radius of 100 pixels whose center is located at the
   * coordinate (300,200).
   */
  public static void drawStar(Graphics g, int centerX, int centerY, int radius, int points) {
    int halfRadius = getHalfRadius(radius, points);
    int p = points;
    points *= 2;

    int xCoord[] = new int[points];
    int yCoord[] = new int[points];

    int currentRadius;

    for (int k = 0; k < points; k++) {
      if (k % 2 == 0) currentRadius = radius;
      else currentRadius = halfRadius;

      xCoord[k] = (int) Math.round(Math.cos(twoPI * k / points - halfPI) * currentRadius) + centerX;
      yCoord[k] = (int) Math.round(Math.sin(twoPI * k / points - halfPI) * currentRadius) + centerY;
    }

    int x = (p - 5) / 2 + 1;
    if (p >= 5 && p <= 51)
      switch (p % 4) {
        case 1:
          yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x];
          break;
        case 2:
          yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x];
          yCoord[x + 3] = yCoord[x + 4] = yCoord[points - x - 4] = yCoord[points - x - 3];
          break;
        case 3:
          yCoord[x + 2] = yCoord[x + 3] = yCoord[points - x - 3] = yCoord[points - x - 2];
      }
    g.drawPolygon(xCoord, yCoord, points);
  }
Ejemplo n.º 16
0
  void act() {
    if (crashed) return;

    if (missionBuffer == 0) setMissions();

    playerZ += SPEED * Math.cos(turn);
    playerX += SPEED * Math.sin(turn);

    if (!region(1).contains(playerX, playerZ)) {
      for (int i = 0; i < NUM_TURNS - 1; i++) centerHinges[i] = centerHinges[i + 1];
      createTurn(NUM_TURNS - 1);

      if (!region(1).contains(playerX, playerZ)) crash();

      turnIndex++;
      if (missionBuffer > 0) missionBuffer--;
      if (barrierBuffer > 0) barrierBuffer--;
    }
    if (playerY + 100 >= centerHinges[3].barrierY
        && playerY + 100 <= centerHinges[3].barrierY + BARRIER_HEIGHT) {
      crash();
    }

    if (up && playerY > START_Y + 50) playerY--;
    if (down && playerY < START_Y + HEIGHT - 150) playerY++;
    if (left) turn -= .005;
    if (right) turn += .005;
  }
Ejemplo n.º 17
0
  protected double read(boolean first) {
    Point2D centre = new Point2D.Double(localPosition.getX(), localPosition.getY());
    Point2D front =
        new Point2D.Double(
            localPosition.getX() + range * Math.cos(localPosition.getT()),
            localPosition.getY() + range * Math.sin(localPosition.getT()));
    robot.readPosition(robotPosition);
    robotPosition.rotateAroundAxis(centre);
    robotPosition.rotateAroundAxis(front);

    double minDistance = -1.0;
    for (int i = 0; i < environment.getObstacles().size(); i++) {
      Obstacle obstacle = environment.getObstacles().get(i);
      if (obstacle.getOpaque()) {
        double dist = pointToObstacle(obstacle.getPolygon(), centre, front, first);
        if (minDistance == -1.0 || (dist > 0 && dist < minDistance)) {
          minDistance = dist;
          if (minDistance > -1 && first) {
            return minDistance;
          }
        }
      }
    }
    if (minDistance > 0) {
      return minDistance;
    }
    return -1.0;
  }
Ejemplo n.º 18
0
  public void method352(
      int i, int j, int ai[], int k, int ai1[], int i1, int j1, int k1, int l1, int i2) {
    try {
      int j2 = -l1 / 2;
      int k2 = -i / 2;
      int l2 = (int) (Math.sin((double) j / 326.11000000000001D) * 65536D);
      int i3 = (int) (Math.cos((double) j / 326.11000000000001D) * 65536D);
      l2 = l2 * k >> 8;
      i3 = i3 * k >> 8;
      int j3 = (i2 << 16) + (k2 * l2 + j2 * i3);
      int k3 = (i1 << 16) + (k2 * i3 - j2 * l2);
      int l3 = k1 + j1 * DrawingArea.width;
      for (j1 = 0; j1 < i; j1++) {
        int i4 = ai1[j1];
        int j4 = l3 + i4;
        int k4 = j3 + i3 * i4;
        int l4 = k3 - l2 * i4;
        for (k1 = -ai[j1]; k1 < 0; k1++) {
          DrawingArea.pixels[j4++] = myPixels[(k4 >> 16) + (l4 >> 16) * myWidth];
          k4 += i3;
          l4 -= l2;
        }

        j3 += l2;
        k3 += i3;
        l3 += DrawingArea.width;
      }

    } catch (Exception _ex) {
    }
  }
Ejemplo n.º 19
0
 /**
  * Translate a point in the direction specified by an angle.
  *
  * @param apt Point2D
  * @param alpha double
  * @param dist double
  * @return Point2D
  */
 public static Point2D translateByAngle(Point2D apt, double alpha, double dist) {
   double dx = dist * Math.cos(alpha);
   double dy = dist * Math.sin(alpha);
   if (Math.abs(dx) < 0.000000001) dx = 0;
   if (Math.abs(dy) < 0.000000001) dy = 0;
   return new Point2D.Double(apt.getX() + dx, apt.getY() + dy);
 }
Ejemplo n.º 20
0
    @Override
    public void paint(Graphics2D g2, State s, float cWidth, float cHeight) {

      InvertedPendulumState is = (InvertedPendulumState) s;
      double x = is instanceof CartPoleState ? ((CartPoleState) is).x : 0.;

      double a = is.angle;

      double xmin = -2.4;
      double xmax = 2.4;
      double xrange = xmax - xmin;

      // manage cart rendering
      float nx = (float) ((x - xmin) / xrange);

      float cartRadius = 0.05f * cWidth;

      float scx = nx * cWidth;
      float scy = cHeight - cartRadius;

      g2.setColor(Color.black);
      g2.fill(
          new Rectangle2D.Float(
              scx - cartRadius, scy - cartRadius, 2 * cartRadius, 2 * cartRadius));

      // manage pole rendering
      float poleLength = 0.5f * cHeight;
      float poleTipX = poleLength * (float) Math.sin(a) + scx;
      float poleTipY = -poleLength * (float) Math.cos(a) + (scy - cartRadius);

      g2.setColor(Color.gray);
      g2.setStroke(new BasicStroke(10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
      g2.draw(new Line2D.Float(scx, scy - cartRadius, poleTipX, poleTipY));
    }
Ejemplo n.º 21
0
 public void enemyPosition(ScannedRobotEvent e, double x, double y) {
   // poll subtargetters for their opinions
   virtualBulletTick++;
   lastEnemyScanTime = owner.getTime();
   // only log it when we actually fire: the enemy may respond to that
   if (owner.shouldFireShot(e)) {
     double bulletPower = e.getDistance() > 500.0 ? 2.0 : 3.0;
     for (int i = 0; i < numVirtualGuns; i++) {
       double angle = targetters[i].target(e, bulletPower);
       VirtualBullet bullet = new VirtualBullet();
       bullet.targetter = i;
       bullet.x = owner.getX();
       bullet.y = owner.getY();
       bullet.velX = Targetting.bulletSpeed(bulletPower) * Math.sin(angle);
       bullet.velY = Targetting.bulletSpeed(bulletPower) * Math.cos(angle);
       bullet.lastUpdateTime = lastEnemyScanTime;
       virtualBullets.add(bullet);
     }
   }
   for (int i = 0; i < numVirtualGuns; i++) {
     targetters[i].enemyPosition(e, x, y);
   }
   enemyX = x;
   enemyY = y;
 }
Ejemplo n.º 22
0
 void draw(Graphics2D g) {
   g.setColor(darkColor);
   int x = (int) (center_x + distance * Math.sin(-unit * current / num));
   int y = (int) (center_y + distance * Math.cos(-unit * current / num));
   Area area = new Area(new Ellipse2D.Double(x, y, ball_r, ball_r));
   g.fill(area);
 }
Ejemplo n.º 23
0
  @Override
  public void dessiner(Graphics2D g2) {
    double xAttaquant = attaquant.getCenterX();
    double yAttaquant = attaquant.getCenterY();

    // calcul de l'angle entre la cible et la tour
    // /!\ Math.atan2(y,x) /!\
    double angle = Math.atan2(cible.getCenterY() - yAttaquant, cible.getCenterX() - xAttaquant);

    // calcul de la tete et de la queue de la fleche
    xCentreBoule = Math.cos(angle) * distanceCentreBoule + xAttaquant; // x
    yCentreBoule = Math.sin(angle) * distanceCentreBoule + yAttaquant; // y

    int diametre = 0;
    // on ne tire pas en cloche tout le temps
    // si l'ennemi est trop proche on tire normal
    if (distanceMaxInitiale > 100.0) {
      double p = distanceCentreBoule / (distanceMax / 2.0);

      if (distanceCentreBoule > distanceMax / 2.0) p = 1 - (p - 1);

      diametre = (int) (p * DIAMETRE_BOULE_MAX + DIAMETRE_BOULE);
    } else {
      diametre = DIAMETRE_BOULE;
    }

    // dessin de la boule de feu
    g2.drawImage(
        IMAGE_BOULE,
        (int) xCentreBoule - diametre / 2,
        (int) yCentreBoule - diametre / 2,
        diametre,
        diametre,
        null);
  }
Ejemplo n.º 24
0
  public BPRadSprite(float rad) {
    super(null, null);

    int per = Math.max(24, (int) (2 * Math.PI * (double) rad / 11.0D));
    FloatBuffer pa = Utils.mkfbuf(per * 3 * 2);
    FloatBuffer na = Utils.mkfbuf(per * 3 * 2);
    ShortBuffer sa = Utils.mksbuf(per * 6);

    for (int i = 0; i < per; ++i) {
      float s = (float) Math.sin(2 * Math.PI * (double) i / (double) per);
      float c = (float) Math.cos(2 * Math.PI * (double) i / (double) per);
      pa.put(i * 3 + 0, c * rad).put(i * 3 + 1, s * rad).put(i * 3 + 2, 10.0F);
      pa.put((per + i) * 3 + 0, c * rad)
          .put((per + i) * 3 + 1, s * rad)
          .put((per + i) * 3 + 2, -10.0F);
      na.put(i * 3 + 0, c).put(i * 3 + 1, s).put(i * 3 + 2, 0.0F);
      na.put((per + i) * 3 + 0, c).put((per + i) * 3 + 1, s).put((per + i) * 3 + 2, 0.0F);
      int v = i * 6;
      sa.put(v + 0, (short) i).put(v + 1, (short) (i + per)).put(v + 2, (short) ((i + 1) % per));
      sa.put(v + 3, (short) (i + per))
          .put(v + 4, (short) ((i + 1) % per + per))
          .put(v + 5, (short) ((i + 1) % per));
    }

    this.posa = new VertexArray(pa);
    this.nrma = new NormalArray(na);
    this.sidx = sa;
  }
Ejemplo n.º 25
0
 // calculate the radius of a given ellipse with give angle
 private double getEllipseRadius(double a, double b, double theta) {
   double d =
       Math.pow(a, 2) * Math.pow(Math.cos(theta), 2)
           + Math.pow(b, 2) * Math.pow(Math.sin(theta), 2);
   double sd = Math.sqrt(d);
   return a * b / sd;
 }
Ejemplo n.º 26
0
 Point2D rightHinge(int index) {
   Turn turn = centerHinges[index];
   double angle = (turn.angle + turn.prevAngle) / 2 + Math.PI / 2;
   double x = turn.x + WIDTH / 2 * Math.sin(angle);
   double z = turn.z + WIDTH / 2 * Math.cos(angle);
   return new Point2D(x, z);
 }
Ejemplo n.º 27
0
  static Rgb hisToRgb(double h, double i, double s) {
    double m1, m2, i1;

    m1 = s * Math.sin(h * Math.PI / 180);
    m2 = s * Math.cos(h * Math.PI / 180);
    i1 = i / Math.sqrt(3);

    Rgb rgb = new Rgb();

    rgb.r = m1 * 2 / Math.sqrt(6) + i1 / Math.sqrt(3);
    rgb.g = -m1 / Math.sqrt(6) + m2 / Math.sqrt(2) + i1 / Math.sqrt(3);
    rgb.b = -m1 / Math.sqrt(6) - m2 / Math.sqrt(2) + i1 / Math.sqrt(3);

    rgb.r = rgb.r / 2 + 0.5;
    rgb.g = rgb.g / 2 + 0.5;
    rgb.b = rgb.b / 2 + 0.5;
    if (rgb.r > 1) rgb.r = 1;
    if (rgb.r < 0) rgb.r = 0;
    if (rgb.g > 1) rgb.g = 1;
    if (rgb.g < 0) rgb.g = 0;
    if (rgb.b > 1) rgb.b = 1;
    if (rgb.b < 0) rgb.b = 0;

    return rgb;
  }
Ejemplo n.º 28
0
 void createEllipse(ImagePlus imp) {
   IJ.showStatus("Fitting ellipse");
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Fit Ellipse");
     return;
   }
   if (roi.isLine()) {
     IJ.error("Fit Ellipse", "\"Fit Ellipse\" does not work with line selections");
     return;
   }
   ImageProcessor ip = imp.getProcessor();
   ip.setRoi(roi);
   int options = Measurements.CENTROID + Measurements.ELLIPSE;
   ImageStatistics stats = ImageStatistics.getStatistics(ip, options, null);
   double dx = stats.major * Math.cos(stats.angle / 180.0 * Math.PI) / 2.0;
   double dy = -stats.major * Math.sin(stats.angle / 180.0 * Math.PI) / 2.0;
   double x1 = stats.xCentroid - dx;
   double x2 = stats.xCentroid + dx;
   double y1 = stats.yCentroid - dy;
   double y2 = stats.yCentroid + dy;
   double aspectRatio = stats.minor / stats.major;
   imp.killRoi();
   imp.setRoi(new EllipseRoi(x1, y1, x2, y2, aspectRatio));
 }
Ejemplo n.º 29
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
Ejemplo n.º 30
0
 @Override
 public void decelerate(float s) {
   setSpeed(body.getVelocity().length());
   s = Math.max(s, 0);
   float dx = (float) (s * (float) Math.cos(body.getRotation() - Math.PI / 2));
   float dy = (float) (s * (float) Math.sin(body.getRotation() - Math.PI / 2));
   body.adjustVelocity(new Vector2f(-dx, -dy));
 }