Example #1
0
  // From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135
  void drawArrow(
      Graphics2D g2d,
      int xCenter,
      int yCenter,
      int x,
      int y,
      float stroke,
      BasicStroke drawStroke) {
    double aDir = Math.atan2(xCenter - x, yCenter - y);
    // Line can be dashed.
    g2d.setStroke(drawStroke);
    g2d.drawLine(x, y, xCenter, yCenter);
    // make the arrow head solid even if dash pattern has been specified
    g2d.setStroke(lineStroke);
    Polygon tmpPoly = new Polygon();
    int i1 = 12 + (int) (stroke * 2);
    // make the arrow head the same size regardless of the length length
    int i2 = 6 + (int) stroke;
    tmpPoly.addPoint(x, y);
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);

    // Remove this line to leave arrow head unpainted:
    g2d.fillPolygon(tmpPoly);
  }
Example #2
0
 public static Complex log(double x_re, double x_im) {
   double h;
   /* #ifdef JAVA5 */
   // h = Math.hypot(x_re, x_im);
   /* #else */
   h = DComplex.hypot(x_re, x_im);
   /* #endif */
   return make(Math.log(h), Math.atan2(x_im, x_re));
 }
Example #3
0
 public static DComplex power(double x_re, double x_im, double y_re, double y_im) {
   double h;
   /* #ifdef JAVA5 */
   // h = Math.hypot(x_re, x_im);
   /* #else */
   h = DComplex.hypot(x_re, x_im);
   /* #endif */
   double logr = Math.log(h);
   double t = Math.atan2(x_im, x_re);
   double r = Math.exp(logr * y_re - y_im * t);
   t = y_im * logr + y_re * t;
   return Complex.polar(r, t);
 }
Example #4
0
  protected void recalcOutFreq() {
    if (inRate == 0f) return;

    double omegaIn, omegaOut, warp;
    ParamField ggOutFreq;

    omegaIn = pr.para[PR_INFREQ].val / inRate * Constants.PI2;
    warp = Math.max(-0.98, Math.min(0.98, pr.para[PR_WARP].val / 100)); // DAFx2000 'b'
    omegaOut = omegaIn + 2 * Math.atan2(warp * Math.sin(omegaIn), 1.0 - warp * Math.cos(omegaIn));

    ggOutFreq = (ParamField) gui.getItemObj(GG_OUTFREQ);
    if (ggOutFreq != null) {
      ggOutFreq.setParam(new Param(omegaOut / Constants.PI2 * inRate, Param.ABS_HZ));
    }
  }
 public void move() {
   objtimer++;
   // move
   if (xmot.random && objtimer % (int) (35 * xmot.randomchg) == 0) {
     xspeed = xmot.speed * random(-1, 1, 2);
   }
   if (ymot.random && objtimer % (int) (35 * ymot.randomchg) == 0) {
     yspeed = ymot.speed * random(-1, 1, 2);
   }
   if (player != null) {
     double playerdist =
         Math.sqrt((player.x - x) * (player.x - x) + (player.y - y) * (player.y - y))
             * 100.0
             / (pfWidth());
     if (xmot.toplayer && playerdist > xmot.toplayermin && playerdist < xmot.toplayermax) {
       xspeed = 0;
       x += xmot.speed * (player.x > x ? 1 : -1);
     } else if (xmot.frplayer
         && playerdist > xmot.frplayermin
         && playerdist < xmot.frplayermax) {
       xspeed = 0;
       x += xmot.speed * (player.x < x ? 1 : -1);
     }
     if (ymot.toplayer && playerdist > ymot.toplayermin && playerdist < ymot.toplayermax) {
       yspeed = 0;
       y += ymot.speed * (player.y > y ? 1 : -1);
     } else if (ymot.frplayer
         && playerdist > ymot.frplayermin
         && playerdist < ymot.frplayermax) {
       yspeed = 0;
       y += ymot.speed * (player.y < y ? 1 : -1);
     }
   }
   // react to background
   int bounces = 0;
   if (bouncesides.equals("any")) {
     bounces |= 15;
   } else if (bouncesides.equals("top")) {
     bounces |= 1;
   } else if (bouncesides.equals("bottom")) {
     bounces |= 2;
   } else if (bouncesides.equals("topbottom")) {
     bounces |= 3;
   } else if (bouncesides.equals("left")) {
     bounces |= 4;
   } else if (bouncesides.equals("right")) {
     bounces |= 8;
   } else if (bouncesides.equals("leftright")) {
     bounces |= 12;
   }
   if ((bounces & 1) != 0 && y < 0) {
     y = 0;
     if (yspeed < 0) yspeed = -yspeed;
   }
   if ((bounces & 2) != 0 && y > pfHeight() - 16) {
     y = pfHeight() - 16;
     if (yspeed > 0) yspeed = -yspeed;
   }
   if ((bounces & 4) != 0 && x < 0) {
     x = 0;
     if (xspeed < 0) xspeed = -xspeed;
   }
   if ((bounces & 8) != 0 && x > pfWidth() - 16) {
     x = pfWidth() - 16;
     if (xspeed > 0) xspeed = -xspeed;
   }
   // shoot
   if (shoot && shootfreq > 0.0 && objtimer % (int) (shootfreq * 35) == 0) {
     if (shootdir.equals("left")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, -shootspeed, 0);
     } else if (shootdir.equals("right")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, shootspeed, 0);
     } else if (shootdir.equals("up")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, 0, -shootspeed);
     } else if (shootdir.equals("down")) {
       new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, 0, shootspeed);
     } else if (shootdir.equals("player") && player != null) {
       double angle = Math.atan2(player.x - x, player.y - y);
       new AgentBullet(
           x,
           y,
           bullettype,
           sprite,
           diebgtype | blockbgtype,
           shootspeed * Math.sin(angle),
           shootspeed * Math.cos(angle));
     }
   }
 }
Example #6
0
 /** Calculates the outline of an arrow tip. */
 public Polygon outline(int x1, int y1, int x2, int y2) {
   double dir = Math.PI / 2 - Math.atan2(x2 - x1, y2 - y1);
   return outline(x1, y1, dir);
 }
Example #7
0
 // returns angle of dy/dx as a value from 0...2PI
 private double atan3(double dy, double dx) {
   double a = Math.atan2(dy, dx);
   if (a < 0) a = (Math.PI * 2.0) + a;
   return a;
 }