Ejemplo n.º 1
0
 /**
  * Construct an FloatList from an iterable pile of objects. For instance, a float array, an array
  * of strings, who knows). Un-parseable or null values will be set to NaN.
  *
  * @nowebref
  */
 public FloatList(Iterable<Object> iter) {
   this(10);
   for (Object o : iter) {
     if (o == null) {
       append(Float.NaN);
     } else if (o instanceof Number) {
       append(((Number) o).floatValue());
     } else {
       append(PApplet.parseFloat(o.toString().trim()));
     }
   }
   crop();
 }
Ejemplo n.º 2
0
    // --------------------------------------------------------
    private void calculPositionAndAngle() {

      PVector prev = new PVector(0, 0);
      PVector next;

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

        next = new PVector();

        // Position
        if (i == 0) {
          next = new PVector(0, 0);
        } else {
          next.x = prev.x + cos(random(angleMini - HALF_PI, angleMax - HALF_PI)) * distance;
          next.y = prev.y + sin(random(angleMini - HALF_PI, angleMax - HALF_PI)) * distance;

          // Angle
          float a = atan2(prev.y - next.y, prev.x - next.x) - HALF_PI;
          angle.append(a);
          if (i == n - 1) lastAngle = a;
        }

        // Add position
        position.add(next);

        distance *= 1.01f;
        prev.set(next);
      }
    }
Ejemplo n.º 3
0
 /** Add this value, but only if it's not already in the list. */
 public void appendUnique(float value) {
   if (!hasValue(value)) {
     append(value);
   }
 }
Ejemplo n.º 4
0
 public void append(FloatList list) {
   for (float v : list.values()) { // will concat the list...
     append(v);
   }
 }
Ejemplo n.º 5
0
 public void append(float[] values) {
   for (float v : values) {
     append(v);
   }
 }
Ejemplo n.º 6
0
 /** Just an alias for append(), but matches pop() */
 public void push(float value) {
   append(value);
 }
Ejemplo n.º 7
0
    // --------------------------------------------------------
    private void calculPositionAndAngle() {

      PVector prev = new PVector(0, 0);
      PVector next = new PVector(0, 0);
      float lastAngle = 0, randomAngle, tempAmplitude;

      // Position
      for (int i = 0; i < n; i++) {

        if (i == 0) {

          position.add(next);

        } else {

          tempAmplitude = amplitude;
          next = new PVector(0, 0);

          do {

            randomAngle = random(-tempAmplitude, tempAmplitude) + lastAngle;
            next.x = prev.x + cos(randomAngle + beginAngle) * distance;
            next.y = prev.y + sin(randomAngle + beginAngle) * distance;
            tempAmplitude += radians(1);
          } while (outside(next, border));

          // Angle
          float a = atan2(prev.y - next.y, prev.x - next.x);
          lastAngle = randomAngle;

          // Add position
          position.add(next);

          // Set prev to next
          prev.set(next);
        }
      }

      // Angle
      for (int i = 0; i < n; i++) {

        float a;

        if (i == 0) {

          // a = atan2(position.get(0).y-position.get(1).y,position.get(0).x-position.get(1).x);
          angle.append(beginAngle - PI);

        } else if (i == n - 1) {

          a =
              atan2(
                  position.get(n - 2).y - position.get(n - 1).y,
                  position.get(n - 2).x - position.get(n - 1).x);
          angle.append(a);

        } else {

          a =
              atan2(
                  position.get(i - 1).y - position.get(i + 1).y,
                  position.get(i - 1).x - position.get(i + 1).x);
          angle.append(a);
        }
      }
    }