예제 #1
0
  private void spawnRandomers() {
    for (int i = 0; i < randomN; i++) {
      float x = (float) Math.random() * width;
      float y = (float) Math.random() * height;
      float r =
          (float)
              Math.sqrt(
                  Math.pow(((Player) players.get(0)).getX() - x, 2)
                      + Math.pow(((Player) players.get(0)).getY() - x, 2));

      while (r < distanceLimit) {
        x = (float) Math.random() * width;
        y = (float) Math.random() * height;
        r =
            (float)
                Math.sqrt(
                    Math.pow(((Player) players.get(0)).getX() - x, 2)
                        + Math.pow(((Player) players.get(0)).getY() - y, 2));
      }

      enemies.add(new EnemyTypes.Random(x, y, 0.5f, borders));
    }

    spawnRandomersB = false;
  }
예제 #2
0
  public void mouseDragged(MouseEvent evt) {
    Graphics g = canvas.getGraphics();
    g.setColor(color);

    if (type == 0) {
      g.setXORMode(canvas.getBackground());
      g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y);
      end = evt.getPoint();
      g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y);
    } else if (type == 1) {
      int radius;

      g.setXORMode(canvas.getBackground());

      radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));

      g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius);
      end = evt.getPoint();

      radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));

      g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius);
    } else if (type == 2) {
      g.setXORMode(canvas.getBackground());
      g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y);
      end = evt.getPoint();
      g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y);
    }
  }
 private static int adjust(int expectedOnMyMachine, long thisTiming, long ethanolTiming) {
   // most of our algorithms are quadratic. sad but true.
   double speed = 1.0 * thisTiming / ethanolTiming;
   double delta = speed < 1 ? 0.9 + Math.pow(speed - 0.7, 2) : 0.45 + Math.pow(speed - 0.25, 2);
   expectedOnMyMachine *= delta;
   return expectedOnMyMachine;
 }
예제 #4
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;
 }
  public void paint(Graphics g) {
    level = level_in;
    left_width_factor = (float) Math.pow(2.0, -1 / left_alpha);
    right_width_factor = (float) Math.pow(2.0, -1 / right_alpha);
    left_height_factor = (float) Math.pow(2.0, -2 / (3 * left_alpha));
    right_height_factor = (float) Math.pow(2.0, -2 / (3 * right_alpha));

    x = (float) 600 / 2.0f;
    y = (float) 500 / 10.0f;

    x1 = x;
    y01 = y + height;

    drawbranch(g, width, (int) x, 500 - (int) y, (int) x1, 500 - (int) y01);
    turtle_r = height;
    turtle_theta = point(x, y, x1, y01);
    turtle_x = x;
    turtle_y = y;
    turn(left_angle);
    generate(g, x1, y01, left_width_factor * width, left_height_factor * height, left_angle, level);
    turtle_theta = point(x, y, x1, y01);
    turn(-right_angle);
    generate(g, x1, y01, width, left_height_factor * height, right_angle, level);
    g.drawString("Fractal.java", 10, 10);
  }
예제 #6
0
파일: Caixeiro.java 프로젝트: rwesz/maxwell
 public double distanciaEuclidiana(int x1, int x2, int y1, int y2) {
   double a, b, c;
   a = Math.pow(x2 - x1, 2);
   b = Math.pow(y2 - y1, 2);
   c = Math.sqrt(a + b);
   return (c);
 }
예제 #7
0
  public void mouseReleased(MouseEvent evt) {
    Graphics g = canvas.getGraphics();
    g.setColor(color);
    g.setPaintMode();
    end = evt.getPoint();

    if (type == 0) {
      g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y);

      if (filled.getState() == true) g.fillRect(start.x, start.y, end.x - start.x, end.y - start.y);

      status.setText("2. Ecke des Rechtecks festgelegt");
    } else if (type == 1) {
      int radius;

      radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));

      g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius);

      if (filled.getState() == true)
        g.fillOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius);

      status.setText("Radius des Kreises festgelegt");
    } else if (type == 2) {
      g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y);

      if (filled.getState() == true) g.fillOval(start.x, start.y, end.x - start.x, end.y - start.y);

      status.setText("Radius der Ellipse festgelegt");
    }
  }
예제 #8
0
 /**
  * 2. For every point (x, y) calculate differences between the not overlapping neighborhoods on
  * opposite sides of the point in horizontal direction.
  *
  * @param x
  * @param y
  * @return
  */
 public double differencesBetweenNeighborhoodsHorizontal(int x, int y, int k) {
   double result = 0;
   result =
       Math.abs(
           this.averageOverNeighborhoods(x + (int) Math.pow(2, k - 1), y, k)
               - this.averageOverNeighborhoods(x - (int) Math.pow(2, k - 1), y, k));
   return result;
 }
예제 #9
0
 /**
  * 2. For every point (x, y) calculate differences between the not overlapping neighborhoods on
  * opposite sides of the point in vertical direction.
  *
  * @param x
  * @param y
  * @return
  */
 public double differencesBetweenNeighborhoodsVertical(int x, int y, int k) {
   double result = 0;
   result =
       Math.abs(
           this.averageOverNeighborhoods(x, y + (int) Math.pow(2, k - 1), k)
               - this.averageOverNeighborhoods(x, y - (int) Math.pow(2, k - 1), k));
   return result;
 }
예제 #10
0
 /**
  * Find the distance between two characters
  *
  * @param Targ Target character
  * @return distance
  */
 public double Dist(GameObject Targ) {
   // find x squared and y squared
   double dx =
       Math.pow(((X + W / 2 * GROWTHFACTOR) - (Targ.X + Targ.W / 2 * Targ.GROWTHFACTOR)), 2);
   double dy =
       Math.pow(((Y + H / 2 * GROWTHFACTOR) - (Targ.Y + Targ.H / 2 * Targ.GROWTHFACTOR)), 2);
   // find distance
   return (Math.sqrt(dx + dy));
 }
예제 #11
0
 /*
  * Given a number, round up to the nearest power of ten times 1, 2, or 5.
  *
  * Note: The argument must be strictly positive.
  */
 private static double roundUp(double val) {
   int exponent = (int) Math.floor(log10(val));
   val *= Math.pow(10, -exponent);
   if (val > 5.0) val = 10.0;
   else if (val > 2.0) val = 5.0;
   else if (val > 1.0) val = 2.0;
   val *= Math.pow(10, exponent);
   return val;
 }
 public YIntervalSeries getYIntervalSeries(String rowname, long factor) {
   YIntervalSeries mydataset = new YIntervalSeries(rowname);
   double sdcount = 0;
   double total = 0;
   Vector<Double> totalvalues = new Vector<Double>();
   double avgtotal = 0;
   double minus = 0;
   double plus = 0;
   double zero = 0;
   for (Integer key : ysum.keySet()) {
     Double value = ysum.get(key) / (double) count.get(key);
     Double point = (double) xsum.get(key) / (double) count.get(key);
     Vector<Double> listofvalues = values.get(key);
     double sumofdiff = 0.0;
     for (Double onevalue : listofvalues) {
       sumofdiff += Math.pow(onevalue - value, 2);
       sdcount++;
       total += Math.pow(onevalue, 2);
       avgtotal += onevalue;
       totalvalues.add(onevalue);
       if (onevalue == 1) {
         plus++;
       }
       ;
       if (onevalue == -1) {
         minus++;
       }
       ;
       if (onevalue == 0) {
         zero++;
       }
       ;
     }
     double sd = Math.sqrt(sumofdiff / count.get(key));
     // mydataset.add(point/factor, value,value+sd,value-sd);
     // mydataset.add(point/factor, value,value,value);
     mydataset.add(
         point / factor,
         value,
         value + 1.96 * (sd / Math.sqrt(count.get(key))),
         value - 1.96 * (sd / Math.sqrt(count.get(key))));
   }
   double sdtotal = 0;
   double avgsd = total / sdcount;
   double test = 0;
   for (Double onevalue : totalvalues) {
     sdtotal += Math.pow(Math.pow(onevalue, 2) - (total / sdcount), 2);
     test += onevalue;
   }
   // System.out.println(rowname+" mean square: "+avgsd+"
   // +/-95%:"+1.96*Math.sqrt(sdtotal/sdcount)/Math.sqrt(sdcount));
   // System.out.println("total -1:"+minus+" total +1:"+plus+" zero: "+zero
   // +" total:"+sdcount);
   return mydataset;
 }
 /**
  * Calculates a number of births on the basis of rates, using Poisson distributed num of events
  *
  * @param lambda rate
  * @return the number of births
  */
 int numberOfBirths(double lambda) {
   double L = 0.0;
   double U = gen.nextDouble();
   double factB = 1.0;
   for (int b = 0; b < 8; b++) {
     if (b > 0) factB = factB * b;
     L = L + Math.pow(lambda * tau, (double) b) * Math.pow(Math.E, -lambda * tau) / factB;
     if (L >= U) return b;
   }
   return 8; // size of Moore neighbourhood
 }
예제 #14
0
파일: MyLine.java 프로젝트: ErezSavir/openu
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof MyLine) {
     MyLine otherLine = (MyLine) obj;
     double length1 =
         Math.pow(this.getEndX() - this.getStartX(), 2)
             + Math.pow(this.getEndY() - this.getStartY(), 2);
     double length2 =
         Math.pow(otherLine.getEndX() - otherLine.getStartX(), 2)
             + Math.pow(otherLine.getEndY() - otherLine.getStartY(), 2);
     return length1 == length2;
   }
   return false;
 }
예제 #15
0
  // returns the endpoint which is closer to (x,y) than the other one
  public Client getPointNear(int x, int y) {
    if (start == null || end == null)
      throw new RuntimeException("ERROR: getPointNear() not allowed on open links");

    int distToStart = (int) Math.pow(start.getX() - x, 2) + (int) Math.pow(start.getY() - y, 2);

    int distToEnd = (int) Math.pow(end.getX() - x, 2) + (int) Math.pow(end.getY() - y, 2);

    if (distToStart < distToEnd) {
      return start;
    } else {
      return end;
    }
  }
예제 #16
0
  /**
   * Picture Quality.
   *
   * @return
   */
  public double contrast() {
    double result = 0, my, sigma, my4 = 0, alpha4 = 0;
    my = this.calculateMy();
    sigma = this.calculateSigma(my);

    for (int x = 0; x < this.imgWidth; x++) {
      for (int y = 0; y < this.imgHeight; y++) {
        my4 = my4 + Math.pow(this.grayScales[x][y] - my, 4);
      }
    }
    alpha4 = my4 / (Math.pow(sigma, 4));
    // fixed based on the patches of [email protected]
    result = sigma / (Math.pow(alpha4, 0.25));
    return result;
  }
예제 #17
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      Color color = c == null ? Color.GRAY : c.getBackground();
      // In a compound sort, make each succesive triangle 20%
      // smaller than the previous one.
      int dx = (int) (size / 2 * Math.pow(0.8, priority));
      int dy = descending ? dx : -dx;
      // Align icon (roughly) with font baseline.
      y = y + 5 * size / 6 + (descending ? -dy : 0);
      int shift = descending ? 1 : -1;
      g.translate(x, y);

      // Right diagonal.
      g.setColor(color.darker());
      g.drawLine(dx / 2, dy, 0, 0);
      g.drawLine(dx / 2, dy + shift, 0, shift);

      // Left diagonal.
      g.setColor(color.brighter());
      g.drawLine(dx / 2, dy, dx, 0);
      g.drawLine(dx / 2, dy + shift, dx, shift);

      // Horizontal line.
      if (descending) {
        g.setColor(color.darker().darker());
      } else {
        g.setColor(color.brighter().brighter());
      }
      g.drawLine(dx, 0, 0, 0);

      g.setColor(color);
      g.translate(-x, -y);
    }
예제 #18
0
 public double getDistance(double[] targetFeature, double[] queryFeature) {
   double result = 0;
   for (int i = 2; i < targetFeature.length; i++) {
     result += Math.pow(targetFeature[i] - queryFeature[i], 2);
   }
   return result;
 }
예제 #19
0
  private double computeZoomIncrementToMakeExactlyNIncrements() {
    double minZoomPercent = mImagePresentationModel.getMinZoom();
    double maxZoomPercent = mImagePresentationModel.getMaxZoom();
    double incrementsCount = mZoomSlider.getMaximum();

    return Math.pow(maxZoomPercent / minZoomPercent, 1.0 / (incrementsCount - 1));
  }
예제 #20
0
 static {
   int[] codes = new int[] {0, 128, 255};
   colors = new Color[(int) Math.pow(codes.length, 3) - 2];
   int index = 0;
   for (int r : codes) {
     for (int g : codes) {
       for (int b : codes) {
         if (r == 0 && g == 0 && b == 0) continue;
         if (r == 255 && g == 255 && b == 255) continue;
         colors[index] = new Color(r, g, b);
         index++;
       }
     }
   }
   Arrays.sort(
       colors,
       new Comparator<Color>() {
         public int compare(Color c1, Color c2) {
           int diff = c1.getRed() - c2.getRed();
           diff += c1.getGreen() - c2.getGreen();
           diff += c1.getBlue() - c2.getBlue();
           return diff;
         }
       });
   reverse(colors);
 }
예제 #21
0
 private long normalizeMax(long l) {
   int exp = (int) Math.log10((double) l);
   long multiple = (long) Math.pow(10.0, exp);
   int i = (int) (l / multiple);
   l = (i + 1) * multiple;
   return l;
 }
예제 #22
0
 public CompareSorts() {
   for (int i = 0; i < 5; i++) {
     double range = 10 * Math.pow(10, i);
     for (int j = 0; j < range; j++) {
       lists[i][j] = randgen.nextInt((int) range);
     }
   }
 }
예제 #23
0
  /*------------------------------------------------------------------*/
  double getInitialCausalCoefficientMirrorOnBounds(double[] c, double z, double tolerance) {
    double z1 = z, zn = Math.pow(z, c.length - 1);
    double sum = c[0] + zn * c[c.length - 1];
    int horizon = c.length;

    if (0.0 < tolerance) {
      horizon = 2 + (int) (Math.log(tolerance) / Math.log(Math.abs(z)));
      horizon = (horizon < c.length) ? (horizon) : (c.length);
    }
    zn = zn * zn;
    for (int n = 1; (n < (horizon - 1)); n++) {
      zn = zn / z;
      sum = sum + (z1 + zn) * c[n];
      z1 = z1 * z;
    }
    return (sum / (1.0 - Math.pow(z, 2 * c.length - 2)));
  } /* end getInitialCausalCoefficientMirrorOnBounds */
예제 #24
0
 private static int getScrollAmount(Component c, MouseWheelEvent me, JScrollBar scrollBar) {
   final int scrollBarWidth = scrollBar.getWidth();
   final int ratio =
       Registry.is("ide.smart.horizontal.scrolling") && scrollBarWidth > 0
           ? Math.max((int) Math.pow(c.getWidth() / scrollBarWidth, 2), 10)
           : 10; // do annoying scrolling faster if smart scrolling is on
   return me.getUnitsToScroll() * scrollBar.getUnitIncrement() * ratio;
 }
예제 #25
0
 public static String readableFileSize(long size) {
   if (size <= 0) return "0";
   final String[] units = new String[] {"B", "KB", "MB", "GB", "TB"};
   int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
   return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups))
       + " "
       + units[digitGroups];
 }
예제 #26
0
  private Picture initialImage() {
    pic2 = new Picture(500, 600);
    pic1 = new Picture(500, 600);

    for (int x = 0; x < pic2.width(); x++)
      for (int y = 0; y < pic2.height(); y++) {
        double dist = 1.0 - Math.sqrt((x - 300) * (x - 300) + (y - 200) * (y - 200)) / 500;
        int red =
            (int)
                (dist < 0.5
                    ? 0
                    : Math.min(Math.pow(dist, 0.4) + Math.pow(dist - 0.5, 0.1), 1.0) * 255);
        int green = (int) (dist * 255);
        int blue = 0;
        pic2.set(x, y, new Color(red, green, blue));
      }
    return pic2;
  }
예제 #27
0
  /**
   * 1. For every point(x, y) calculate the average over neighborhoods.
   *
   * @param x
   * @param y
   * @return
   */
  public double averageOverNeighborhoods(int x, int y, int k) {
    double result = 0, border;
    border = Math.pow(2, 2 * k);
    int x0 = 0, y0 = 0;

    for (int i = 0; i < border; i++) {
      for (int j = 0; j < border; j++) {
        x0 = x - (int) Math.pow(2, k - 1) + i;
        y0 = y - (int) Math.pow(2, k - 1) + j;
        if (x0 < 0) x0 = 0;
        if (y0 < 0) y0 = 0;
        if (x0 >= imgWidth) x0 = imgWidth - 1;
        if (y0 >= imgHeight) y0 = imgHeight - 1;
        result = result + grayScales[x0][y0];
      }
    }
    result = (1 / Math.pow(2, 2 * k)) * result;
    return result;
  }
예제 #28
0
  /**
   * Calculation of the separation length between tics. Some smart rounding algorithms are needed to
   * get the scaling properly in case of data going to 10.3 or so... Useful stuff stolen from the
   * Gnuplot sources, thank you guys!!
   */
  public static double calculateTicSep(double min, double max, int maxNumberOfTicks) {
    double xnorm, tic, posns;
    double lrange = log10(Math.abs(min - max));
    double fl = Math.floor(lrange);
    xnorm = Math.pow(10.0, lrange - fl);
    posns = maxNumberOfTicks / xnorm;

    if (posns > 40) tic = 0.05; // eg 0, .05, .10, ...
    else if (posns > 20) tic = 0.1; // eg 0, .1, .2, ...
    else if (posns > 10) tic = 0.2; // eg 0,0.2,0.4,...
    else if (posns > 4) tic = 0.5; // 0,0.5,1,
    else if (posns > 1) tic = 1; // 0,1,2,....
    else if (posns > 0.5) tic = 2; // 0, 2, 4, 6
    else if (posns > 0.2) tic = 10; // 0, 10, 100, 6
    else tic = Math.ceil(xnorm);

    tic *= Math.pow(10.0, fl);

    return tic;
  }
예제 #29
0
 public double coarseness(int n0, int n1) {
   double result = 0;
   for (int i = 1; i < n0 - 1; i++) {
     for (int j = 1; j < n1 - 1; j++) {
       result = result + Math.pow(2, this.sizeLeadDiffValue(i, j));
     }
   }
   // fixed based on the patch by [email protected]
   result = (1.0 / (n0 * n1)) * result;
   return result;
 }
예제 #30
0
  /** @return */
  public double calculateSigma(double mean) {
    double result = 0;

    for (int x = 0; x < this.imgWidth; x++) {
      for (int y = 0; y < this.imgHeight; y++) {
        result = result + Math.pow(this.grayScales[x][y] - mean, 2);
      }
    }
    result = result / (this.imgWidth * this.imgHeight);
    return Math.sqrt(result);
  }