Пример #1
0
  void drawLinksTo(TwitterFilteringComponent t) {
    parent.noStroke();
    parent.fill(170, 170, 255, 130);
    int targetY;

    targetY = (t.y < lineY ? (t.y + t.height) : t.y);

    // println(t.y + " and " + targetY);
    // draw links from timeline to this component
    parent.beginShape(PConstants.POLYGON);
    parent.vertex(
        PApplet.map(
            getHourOfYear(t.dateSelection.getStart()),
            getHourOfYear(timelineStartDate),
            getHourOfYear(timelineEndDate),
            lineStart,
            lineStop),
        lineY);
    parent.vertex(t.x, targetY);
    parent.vertex(t.x + t.width, targetY);
    parent.vertex(
        PApplet.map(
            getHourOfYear(t.dateSelection.getEnd()),
            getHourOfYear(timelineStartDate),
            getHourOfYear(timelineEndDate),
            lineStart,
            lineStop),
        lineY);
    parent.endShape();
  }
Пример #2
0
  @Override
  public float applyFunction(float x, boolean clamp) {
    float fa = PApplet.map(a, 0.0f, 1.0f, -1.0f, 1.0f);
    float fc = PApplet.map(c, 0.0f, 1.0f, -1.0f, 1.0f);

    float hC = (fc - fa) * 0.5f;
    float hV = (b - d);
    float hW = hC + hV;
    float hA = hW + hV + (fc - b) * 0.5f;
    float hB = hW + hA;

    float y = ((((hA * x) - hB) * x + hC) * x + b);

    return clamp(y, clamp);
  }
 private void drawPoints() {
   if (data == null) return;
   pushStyle();
   fill(pointColor, 150f);
   noStroke();
   for (PVector point : data.getPoints()) {
     float x =
         PApplet.map(
             point.x, data.getXMin(), data.getXMax(), 0 + pointRadius, getWidth() - pointRadius);
     float y =
         PApplet.map(
             point.y, data.getYMin(), data.getYMax(), getHeight() - pointRadius, 0 + pointRadius);
     ellipse(x, y, pointRadius * 2, pointRadius * 2);
   }
   popStyle();
 }
Пример #4
0
  protected void setInternalValue(float theValue) {
    // TODO simplify below code.
    // TODO rename modifiedValue and currentValue to make it more obvious to
    // what these variables refer to
    modifiedValue =
        (isSnapToTickMarks)
            ? PApplet.round((theValue * _myTickMarksNum)) / ((float) _myTickMarksNum)
            : theValue;
    currentValue = theValue;
    myAngle =
        PApplet.map(
            isSnapToTickMarks == true ? modifiedValue : currentValue,
            0,
            1,
            startAngle,
            startAngle + range);

    if (isSnapToTickMarks) {
      if (previousValue != modifiedValue && isSnapToTickMarks) {
        broadcast(FLOAT);
        previousValue = modifiedValue;
        return;
      }
    }
    if (previousValue != currentValue) {
      broadcast(FLOAT);
      previousValue = modifiedValue;
    }
  }
Пример #5
0
  private PVector calculateTextureVertex(int x, int y) {

    float u =
        iu
            * PApplet.map(
                y, (longDetail * leftCrop), longDetail - (longDetail * rightCrop), 0, longDetail);
    float v =
        iv
            * PApplet.map(
                x, (latDetail * bottomCrop), latDetail - (latDetail * topCrop), 0, latDetail);

    if (u > 0.96) u = 0.95f;

    PVector texture = new PVector(u, v);

    return texture;
  }
Пример #6
0
 void moveToPosition(TwitterFilteringComponent t) {
   // moves component to a position above the middle of its range
   float maxX =
       PApplet.map(
           getHourOfYear(t.dateSelection.getEnd()),
           getHourOfYear(timelineStartDate),
           getHourOfYear(timelineEndDate),
           lineStart,
           lineStop);
   float minX =
       PApplet.map(
           getHourOfYear(t.dateSelection.getStart()),
           getHourOfYear(timelineStartDate),
           getHourOfYear(timelineEndDate),
           lineStart,
           lineStop);
   // if (t.x != int((maxX+minX)/2)-t.width/2) {
   t.moveTo((int) ((maxX + minX) / 2 - smallVizSize.x / 2), (int) (previousPos.y));
   // }
 }
  public void drawLegend(PApplet pg, int posX, int posY, int length, int mouseX, int mouseY) {
    this.posX = posX;
    this.posY = posY;
    this.length = length;
    this.pg = pg;

    // Save previous drawing style
    pg.pushStyle();

    // color filling
    for (int i = posX; i <= posX + length; i++) {
      float inter = pg.map(i, posX, posX + length, 0, 1);
      int c = pg.lerpColor(fromColor, toColor, inter);
      pg.stroke(c);
      pg.line(i, posY, i, posY + 25);
    }

    // border
    pg.stroke(0);
    pg.rect(posX, posY, length, 25, 0);

    // title
    pg.fill(0);
    pg.textAlign(pg.CENTER);
    pg.text(title, posX + length / 2, posY - 10);

    // min and max values
    pg.text(minValue, posX, posY - 10);
    pg.text(maxValue, posX + length, posY - 10);

    // corresponding value shown below the color box
    if (isInLegend(mouseX, mouseY)) {

      float inter = pg.map((float) mouseX, (float) posX, (float) posX + length, minValue, maxValue);
      pg.fill(0);
      pg.text(inter, mouseX, posY + 40);
    }

    // Restore previous drawing style
    pg.popStyle();
  }
Пример #8
0
 void randomWalk(Mimo m) {
   Simulation1.app.noiseSeed(Simulation1.app.millis());
   float speed = Simulation1.app.noise(Simulation1.app.frameCount * 0.1f) * maxSpeed;
   if (Simulation1.app.random(1) < 0.99) {
     return;
   }
   float a =
       PApplet.map(
           Simulation1.app.random(1), 0, 1, directionChangeRange.x, directionChangeRange.y);
   m.vel = new PVector(PApplet.cos(a), PApplet.sin(a));
   m.vel.mult(speed);
 }
Пример #9
0
 /**
  * setStereosep(int) takes a percentage for desired MOD stereo spread. 100 gives full Amiga
  * hard-panning while 0 centres all channels. This only works on 4 or 8 channel files that are
  * verified as being MODs. Panning arrangement is 1:L 2:R 3:R 4:L(5:L 6:R 7:R 8:L). Just to be
  * clear, this has no effect on XM or S3M files!
  */
 public void setStereosep(int percentage) {
   int spread = (int) PApplet.map(percentage, 0, 100, 0, 128);
   if (modtype == "MOD") {
     player.ibxm.channels[0].set_panning(128 - spread);
     player.ibxm.channels[1].set_panning(128 + spread);
     player.ibxm.channels[2].set_panning(128 + spread);
     player.ibxm.channels[3].set_panning(128 - spread);
     if (player.get_num_channels() > 4) {
       player.ibxm.channels[4].set_panning(128 - spread);
       player.ibxm.channels[5].set_panning(128 + spread);
       player.ibxm.channels[6].set_panning(128 + spread);
       player.ibxm.channels[7].set_panning(128 - spread);
     }
   }
 }
Пример #10
0
  @Override
  public float applyFunction(float x, boolean clamp) {
    // http://en.wikipedia.org/wiki/Gompertz_curve
    float min_param_a = 0.0f + PConstants.EPSILON;
    a = PApplet.max(a, min_param_a);

    float b = -8.0f;
    float c = 0 - a * 16.0f;
    float y = PApplet.exp(b * PApplet.exp(c * x));

    float maxVal = PApplet.exp((b * PApplet.exp(c)));
    float minVal = PApplet.exp(b);
    y = PApplet.map(y, minVal, maxVal, 0, 1);

    return clamp(y, clamp);
  }
 public void drawXAxis() {
   pushStyle();
   textAlign(PApplet.CENTER, PApplet.TOP);
   textSize(8);
   fill(MyColorEnum.WHITE);
   float max = data.getXMax();
   float min = data.getXMin();
   int numberOfTicks = 10;
   float tickValue = (max - min) / numberOfTicks;
   for (int i = 0; i < numberOfTicks; i++) {
     float x = pointRadius + PApplet.map(i, 0, numberOfTicks - 1, 0, getWidth() - 2 * pointRadius);
     String numberLabel = (int) (tickValue * i) + "";
     text(numberLabel, x, getHeight() + 5);
   }
   popStyle();
 }
Пример #12
0
 public void display(PGraphics graphics, Controller<?> theController) {
   height = label.getHeight();
   graphics.fill(backgroundColor, currentAlpha);
   graphics.rect(0, 0, getWidth() + borderSize * 2, height + borderSize * 2);
   graphics.pushMatrix();
   if (alignH == Skatolo.RIGHT) {
     graphics.translate(6, 0);
   } else {
     graphics.translate(getWidth() - 6, 0);
   }
   graphics.triangle(0, 0, 4, -4, 8, 0);
   graphics.popMatrix();
   int a = (int) (PApplet.map(currentAlpha, 0, maxAlpha, 0, 255));
   label.setColor(a << 24 | (color >> 16) << 16 | (color >> 8) << 8 | (color >> 0) << 0);
   label.draw(graphics, 0, 0, theController);
 }
Пример #13
0
 public void display(PApplet theApplet, Controller<?> theController) {
   _myHeight = _myLabel.getHeight();
   theApplet.fill(_myBackgroundColor, _myAlpha);
   theApplet.rect(0, 0, getWidth() + _myBorder * 2, _myHeight + _myBorder * 2);
   theApplet.pushMatrix();
   if (_myAlignH == ControlP5.RIGHT) {
     theApplet.translate(6, 0);
   } else {
     theApplet.translate(getWidth() - 6, 0);
   }
   theApplet.triangle(0, 0, 4, -4, 8, 0);
   theApplet.popMatrix();
   int a = (int) (PApplet.map(_myAlpha, 0, _myMaxAlpha, 0, 255));
   _myLabel.setColor(
       a << 24 | (_myColor >> 16) << 16 | (_myColor >> 8) << 8 | (_myColor >> 0) << 0);
   _myLabel.draw(theApplet, 0, 0, theController);
 }
Пример #14
0
  /**
   * Draws the connections. The opacity of the line which represents the connection is determined by
   * the distance between the two end points of the connection.
   */
  public void draw() {

    // calculate the theoretical max distance between the two end points of the connection.
    float max =
        (float)
            Math.sqrt(gui.displayWidth * gui.displayWidth + gui.displayHeight * gui.displayHeight);
    max *= 0.75;
    // Map the distance between the two end nodes to a range of 0..100 to have a value for the
    // opacity
    float alpha = PApplet.map(getDistance(), 0, max, 100, 0);

    // set the stroke to the color of this connection. Adjust the opacity for distance.
    gui.stroke(color, 15 + alpha * 0.5f);

    // Get the positions of the two endpoints of the connection
    PVector pos1 = node1.getTransformedPosition();
    PVector pos2 = node2.getTransformedPosition();
    float corner = getAngle(node1, node2);
    float x1 = (float) (pos1.x + node1.getDiameter() / 2 * Math.cos(corner));
    float y1 = (float) (pos1.y + node1.getDiameter() / 2 * Math.sin(corner));
    float x2 = (float) (pos2.x + node2.getDiameter() / 2 * -Math.cos(corner));
    float y2 = (float) (pos2.y + node2.getDiameter() / 2 * -Math.sin(corner));
    // draw the connection
    // gui.line(pos1.x, pos1.y, pos2.x, pos2.y);

    gui.noStroke();
    gui.fill(color, 15 + alpha * 0.5f);
    if (!firstIsOriginal) {
      float x3 = (float) (x2 + 3 * Math.cos(corner + Math.PI / 2));
      float y3 = (float) (y2 + 3 * Math.sin(corner + Math.PI / 2));
      x2 = (float) (x2 + 3 * Math.cos(corner - Math.PI / 2));
      y2 = (float) (y2 + 3 * Math.sin(corner - Math.PI / 2));

      gui.triangle(x1, y1, x2, y2, x3, y3);
    } else {
      float x3 = (float) (x1 + 3 * Math.cos(corner + Math.PI / 2));
      float y3 = (float) (y1 + 3 * Math.sin(corner + Math.PI / 2));
      x1 = (float) (x1 + 3 * Math.cos(corner - Math.PI / 2));
      y1 = (float) (y1 + 3 * Math.sin(corner - Math.PI / 2));

      gui.triangle(x1, y1, x2, y2, x3, y3);
    }
  }
Пример #15
0
 /*
  * (non-Javadoc)
  *
  * @see controlP5.Controller#mousePressed()
  */
 public void mousePressed() {
   float x = _myParent.absolutePosition().x() + position().x() + _myRadius;
   float y = _myParent.absolutePosition().y() + position().y() + _myRadius;
   if (PApplet.dist(x, y, _myControlWindow.mouseX, _myControlWindow.mouseY) < _myRadius) {
     isActive = true;
     if (PApplet.dist(x, y, _myControlWindow.mouseX, _myControlWindow.mouseY) > _myRadius / 2) {
       myAngle =
           (PApplet.atan2(_myControlWindow.mouseY - y, _myControlWindow.mouseX - x) - startAngle);
       if (myAngle < 0) {
         myAngle = TWO_PI + myAngle;
       }
       if (isLimited) {
         myAngle %= TWO_PI;
       }
       currentValue = PApplet.map(myAngle, 0, range, 0, 1);
       setInternalValue(currentValue);
     }
   }
 }
Пример #16
0
  public void setY(float setY) {
    y = PApplet.constrain(setY - h / 2, minY, maxY);

    // mapping eventuell noch logarithmisch? - mŸsste stimmen

    // calc cameraTarget
    p5.cam_eyetargetpos.z =
        PApplet.map(
            y + h,
            p5.timeChooser.y + p5.timeChooser.h,
            p5.timeChooser.y,
            (p5.height / 2.0f) / PApplet.tan(PConstants.PI * 30.0f / 180.0f),
            -p5.timeline.timelineLength
                + (p5.height / 2.0f) / PApplet.tan(PConstants.PI * 30.0f / 180.0f));

    // System.out.println("set Y: " + p5.cam_eyetargetpos.z + " " + (p5.timeChooser.y +
    // p5.timeChooser.h) + " " + (p5.timeChooser.y) + " " + ((p5.height / 2.0f) /
    // p5.tan(PConstants.PI * 30.0f / 180.0f)) + " " + (p5.timeline.timelineLength + (p5.height /
    // 2.0f) / p5.tan(PConstants.PI * 30.0f / 180.0f)));
  }
Пример #17
0
 /**
  * Should provide the geographic coordinates corresponding to the given screen coordinates.
  *
  * @param screenX Screen x coordinate.
  * @param screenY Screen y coordinate.
  * @return Geographic coordinate representation of the given screen location.
  */
 public PVector screenToGeo(float screenX, float screenY) {
   return new PVector(
       PApplet.map(screenX, xOrigin, xOrigin + mapWidth, minGeoX, maxGeoX),
       PApplet.map(screenY, yOrigin + mapHeight, yOrigin, minGeoY, maxGeoY));
 }
Пример #18
0
  /** @param theWindow */
  void draw(ControlWindow theWindow) {
    if (enabled) {

      if (_myMode >= ControlP5.WAIT) {

        previousPosition.set(currentPosition);
        currentPosition.set(theWindow.mouseX, theWindow.mouseY, 0);

        if (_myController != null) {
          if (_myController.getControlWindow().equals(theWindow)) {
            switch (_myMode) {
              case (ControlP5.WAIT):
                if (moved()) {
                  startTime = System.nanoTime();
                }

                if (System.nanoTime() > startTime + (_myDelayInMillis * 1000000)) {

                  position.set(currentPosition);
                  _myAlignH = ControlP5.RIGHT;
                  if (position.x
                      > (_myController.getControlWindow().papplet().width - (getWidth() + 20))) {
                    position.sub(new PVector(getWidth(), 0, 0));
                    _myAlignH = ControlP5.LEFT;
                  }
                  _myMode = ControlP5.FADEIN;
                  startTime = System.nanoTime();
                  _myAlpha = 0;
                }
                break;
              case (ControlP5.FADEIN):
                float t1 = System.nanoTime() - startTime;
                _myAlpha = (int) PApplet.map(t1, 0, 200 * 1000000, 0, _myMaxAlpha);
                if (_myAlpha >= 250) {
                  _myMode = ControlP5.IDLE;
                  _myAlpha = 255;
                }
                break;
              case (ControlP5.IDLE):
                break;
              case (ControlP5.FADEOUT):
                float t2 = System.nanoTime() - startTime;
                _myAlpha = (int) PApplet.map(t2, 0, 200 * 1000000, _myMaxAlpha, 0);
                if (_myAlpha <= 0) {
                  _myMode = ControlP5.DONE;
                }
                break;
              case (ControlP5.DONE):
                _myController = null;
                _myMode = ControlP5.INACTIVE;
                position.set(-1000, -1000, 0);
            }

            _myAlpha = PApplet.max(0, PApplet.min(_myAlpha, _myMaxAlpha));

            if (_myMode >= ControlP5.WAIT) {
              _myAlpha = (_myMode == ControlP5.WAIT) ? 0 : _myAlpha;
              theWindow.papplet().pushMatrix();
              theWindow.papplet().translate(position.x, position.y);
              theWindow.papplet().translate(offset.x, offset.y);
              _myView.display(theWindow.papplet(), null);
              theWindow.papplet().popMatrix();
            }
            if (_myMode < ControlP5.FADEOUT) {
              if (moved()) {
                deactivate(0);
              }
            }
          }
        }
      }
    }
  }
Пример #19
0
 public float getFloatValue() {
   return PApplet.map(angle, -PApplet.PI, PApplet.PI, vMin, vMax);
 }
Пример #20
0
 /*
  * (non-Javadoc)
  *
  * @see controlP5.Controller#value()
  */
 public float value() {
   _myValue =
       PApplet.map(_myTickMarksNum > 0 ? modifiedValue : currentValue, 0, 1, _myMin, _myMax);
   return _myValue;
 }
Пример #21
0
 /*
  * (non-Javadoc)
  *
  * @see controlP5.Controller#setValue(float)
  */
 public void setValue(float theValue) {
   setInternalValue(PApplet.map(theValue, _myMin, _myMax, 0, 1));
 }
Пример #22
0
 /**
  * getChanvol(int) takes a channel as its argument and returns that channel's current volume as an
  * int between 0 and 64. This is the final volume given to the mixer engine after volume
  * command/tremolo/envelope/global levels have been calculated.
  *
  * @param chan
  * @return int
  */
 public int getChanvol(int chan) {
   int chanvol = player.ibxm.channels[chan].chanvolfinal;
   // return (int)p.map(chanvol, 0, 8064, 0, 64);
   return (int) p.map(chanvol, 0, 12288, 0, 64);
 }
 private int hashY(float y) {
   float f = PApplet.map(y, fluidMinY, fluidMaxY, 0, hashHeight - .001f);
   return (int) f;
 }
 private int hashX(float x) {
   float f = PApplet.map(x, fluidMinX, fluidMaxX, 0, hashWidth - .001f);
   return (int) f;
 }
Пример #25
0
  void drawTimeLine() {

    // draw the base timeline

    int minorTickHeight = (int) (20 * scaleFactorY);
    int majorTickHeight = (int) (40 * scaleFactorY);
    parent.strokeWeight(10);
    parent.stroke(0);
    parent.line(lineStart, lineY, lineStop, lineY);
    // draw days
    // int maxDays = Days.daysBetween(timelineStartDate,
    // timelineEndDate).getDays();
    int maxHours = Hours.hoursBetween(timelineStartDate, timelineEndDate).getHours();
    // println("Interval  is " + fullTimeInterval);
    // println("Period is " + Days.daysBetween(minDate, maxDate).getDays());
    // println("Max days is " + maxDays);

    DateTime tempdt = new DateTime(timelineStartDate);
    String previousMonth = timelineStartDate.monthOfYear().getAsText();
    int previousDay = -1; // =tempdt.dayOfYear().get();
    int monthStart = lineStart;
    parent.textAlign(PConstants.CENTER, PConstants.TOP);

    for (int a = 0; a < maxHours; a++) {
      // println(a);
      parent.textAlign(PConstants.CENTER, PConstants.TOP);
      // draw label
      parent.textFont(parent.font);
      parent.textSize(10 * fontScale);

      if (tempdt.dayOfYear().get() != previousDay) {
        int tx = (int) (PApplet.map(a, 0, maxHours, lineStart, lineStop));
        // draw tick
        parent.strokeWeight(1);
        parent.line(tx, lineY, tx, lineY + minorTickHeight);
        previousDay = tempdt.dayOfYear().get();
        parent.fill(0);
        if (tempdt.dayOfMonth().get() == 1) {
          // special case!
          parent.textSize(14 * fontScale);
          parent.text(
              tempdt.dayOfMonth().getAsString(),
              tx,
              lineY + majorTickHeight + parent.textDescent());
        } else {
          parent.text(
              tempdt.dayOfMonth().getAsString(),
              tx,
              lineY + minorTickHeight + parent.textDescent());
        }

        // check if need to draw monthName
        if (!previousMonth.equals(tempdt.monthOfYear().getAsText())) {
          // draw some visual markers!
          // line(monthStart, lineY, monthStart,
          // lineY+majorTickHeight);
          parent.line(tx, lineY, tx, lineY + majorTickHeight);
          // position halfway between monthStart and tx, draw
          // monthname
          parent.textSize(18 * fontScale);
          // check! do we overlap the next month? if so, change
          // alignment
          if (parent.textWidth(previousMonth) / 2 + monthStart > tx) {
            parent.textAlign(PConstants.RIGHT, PConstants.TOP);
          }
          parent.text(
              previousMonth,
              (tx + monthStart) / 2,
              lineY + minorTickHeight + 2 * (parent.textAscent() + parent.textDescent()));
          previousMonth = tempdt.monthOfYear().getAsText();
          monthStart = tx;
        }
      }
      tempdt = tempdt.plus(Period.hours(1));
    }
    // draw final day
    parent.line(lineStop, lineY, lineStop, lineY + minorTickHeight);
    if (tempdt.dayOfMonth().get() == 1) {
      // special case!
      parent.text(
          tempdt.dayOfMonth().getAsString(),
          lineStop,
          lineY + majorTickHeight + parent.textDescent());
    } else {
      parent.text(
          tempdt.dayOfMonth().getAsString(),
          lineStop,
          lineY + minorTickHeight + parent.textDescent());
    }
    // draw final month!
    parent.textSize(18 * fontScale);
    parent.text(
        tempdt.monthOfYear().getAsText(),
        (lineStop + monthStart) / 2,
        lineY + minorTickHeight + 2 * (parent.textAscent() + parent.textDescent()));
  }
Пример #26
0
  @Override
  public void create() {

    if (firstTime) {
      setCamera(0.0f, 10.0f, 20.0f);
      firstTime = false;
      // this.settings.drawJoints = false;
    }

    Body ground = null;
    {
      PolygonDef sd = new PolygonDef();
      sd.setAsBox(50.0f, 0.4f);

      BodyDef bd = new BodyDef();
      bd.position.set(0.0f, 0.0f);
      ground = m_world.createBody(bd);
      ground.createShape(sd);

      sd.setAsBox(0.4f, 50.0f, new Vec2(-10.0f, 0.0f), 0.0f);
      ground.createShape(sd);
      sd.setAsBox(0.4f, 50.0f, new Vec2(10.0f, 0.0f), 0.0f);
      ground.createShape(sd);
    }

    ConstantVolumeJointDef cvjd = new ConstantVolumeJointDef();

    float cx = 0.0f;
    float cy = 10.0f;
    float rx = 4.0f;
    float ry = 4.0f;
    int nBodies = 100;
    float bodyRadius = 0.4f;
    ArrayList<Body> bodies = new ArrayList<Body>();
    for (int i = 0; i < nBodies; ++i) {
      float angle = PApplet.map(i, 0, nBodies, 0, 2 * 3.1415f);
      BodyDef bd = new BodyDef();
      // bd.isBullet = true;
      bd.fixedRotation = true;

      float x =
          cx
              + (1.0f + .5f * (float) Math.cos(4 * (angle + .25f * 3.1415f)))
                  * rx
                  * (float) Math.sin(angle);
      float y =
          cy
              + (1.0f + .5f * (float) Math.cos(4 * (angle + .25f * 3.1415f)))
                  * ry
                  * (float) Math.cos(angle);
      bd.position.set(new Vec2(x, y));
      Body body = m_world.createBody(bd);
      CircleDef cd = new CircleDef();
      cd.radius = bodyRadius;
      cd.density = 1.0f;
      // cd.filter.groupIndex = -2;
      body.createShape(cd);
      cvjd.addBody(body);
      body.setMassFromShapes();
      bodies.add(body);
    }

    cvjd.frequencyHz = 10.0f;
    cvjd.dampingRatio = 10.0f;
    ((ConstantVolumeJoint) m_world.createJoint(cvjd)).inflate(1.5f);

    cvjd = new ConstantVolumeJointDef();
    for (int i = 0; i < nBodies / 4; ++i) {
      cvjd.addBody(bodies.get(i));
    }
    cvjd.frequencyHz = 10.0f;
    cvjd.dampingRatio = 10.0f;
    ((ConstantVolumeJoint) m_world.createJoint(cvjd)).inflate(1.5f);

    cvjd = new ConstantVolumeJointDef();
    for (int i = nBodies / 4; i < nBodies / 2; ++i) {
      cvjd.addBody(bodies.get(i));
    }
    cvjd.frequencyHz = 10.0f;
    cvjd.dampingRatio = 10.0f;
    ((ConstantVolumeJoint) m_world.createJoint(cvjd)).inflate(1.5f);

    cvjd = new ConstantVolumeJointDef();
    for (int i = nBodies / 2; i < 3 * nBodies / 4; ++i) {
      cvjd.addBody(bodies.get(i));
    }

    cvjd.frequencyHz = 10.0f;
    cvjd.dampingRatio = 10.0f;
    ((ConstantVolumeJoint) m_world.createJoint(cvjd)).inflate(1.5f);

    cvjd = new ConstantVolumeJointDef();
    for (int i = 3 * nBodies / 4; i < nBodies; ++i) {
      cvjd.addBody(bodies.get(i));
    }

    cvjd.frequencyHz = 10.0f;
    cvjd.dampingRatio = 10.0f;
    ((ConstantVolumeJoint) m_world.createJoint(cvjd)).inflate(1.5f);

    //		cvjd = new ConstantVolumeJointDef();
    //		for (int i=0+nBodies/8; i<nBodies/4+nBodies/8; ++i) {
    //			cvjd.addBody(bodies.get(i));
    //		}
    //		cvjd.frequencyHz = 10.0f;
    //		cvjd.dampingRatio = 10.0f;
    //		m_world.createJoint(cvjd);
    //
    //		cvjd = new ConstantVolumeJointDef();
    //		for (int i=nBodies/4+nBodies/8; i<nBodies/2+nBodies/8; ++i) {
    //			cvjd.addBody(bodies.get(i));
    //		}
    //		cvjd.frequencyHz = 10.0f;
    //		cvjd.dampingRatio = 10.0f;
    //		m_world.createJoint(cvjd);
    //
    //		cvjd = new ConstantVolumeJointDef();
    //		for (int i=nBodies/2+nBodies/8; i<3*nBodies/4+nBodies/8; ++i) {
    //			cvjd.addBody(bodies.get(i));
    //		}
    //		cvjd.frequencyHz = 10.0f;
    //		cvjd.dampingRatio = 10.0f;
    //		m_world.createJoint(cvjd);
    //		cvjd = new ConstantVolumeJointDef();
    //		for (int i=3*nBodies/4+nBodies/8; i<nBodies+nBodies/8; ++i) {
    //			int index = i;
    //			if (index >= bodies.size()) index -= bodies.size();
    //			cvjd.addBody(bodies.get(index));
    //		}
    //
    //		cvjd.frequencyHz = 10.0f;
    //		cvjd.dampingRatio = 10.0f;
    //		m_world.createJoint(cvjd);

    //		cvjd = new ConstantVolumeJointDef();
    //		cvjd.addBody(bodies.get(0));
    //		cvjd.addBody(bodies.get(nBodies/4));
    //		cvjd.addBody(bodies.get(nBodies/2));
    //		cvjd.addBody(bodies.get(3*nBodies/4));
    //		cvjd.frequencyHz = 10.0f;
    //		m_world.createJoint(cvjd);
    //
    //		cvjd = new ConstantVolumeJointDef();
    //		cvjd.addBody(bodies.get(0 + nBodies/8));
    //		cvjd.addBody(bodies.get(nBodies/4 + nBodies/8));
    //		cvjd.addBody(bodies.get(nBodies/2 + nBodies/8));
    //		cvjd.addBody(bodies.get(3*nBodies/4 + nBodies/8));
    //		cvjd.frequencyHz = 1.0f;
    //		m_world.createJoint(cvjd);

    BodyDef bd2 = new BodyDef();
    PolygonDef psd = new PolygonDef();
    psd.setAsBox(3.0f, 1.5f, new Vec2(cx, cy + 15.0f), 0.0f);
    psd.density = 1.0f;
    bd2.position = new Vec2(cx, cy + 15.0f);
    Body fallingBox = m_world.createBody(bd2);
    fallingBox.createShape(psd);
    fallingBox.setMassFromShapes();
  }
Пример #27
0
 /**
  * Should provide the screen coordinates corresponding to the given geographic coordinates.
  *
  * @param geoX Geographic x coordinate.
  * @param geoY Geographic y coordinate.
  * @return Screen coordinate representation of the given geographic location.
  */
 public PVector geoToScreen(float geoX, float geoY) {
   return new PVector(
       PApplet.map(geoX, minGeoX, maxGeoX, xOrigin, xOrigin + mapWidth),
       PApplet.map(geoY, minGeoY, maxGeoY, yOrigin + mapHeight, yOrigin));
 }
Пример #28
0
  /** @param theWindow */
  void draw(ControlWindow theWindow) {
    // System.out.println(previousPosition+"\t"+currentPosition+"\t"+position);
    if (enabled) {

      if (mode >= Skatolo.WAIT) {

        previousPosition.set(currentPosition);
        currentPosition.set(theWindow.getPointerX(), theWindow.getPointerY(), 0);

        if (controller != null) {
          if (controller.getControlWindow().equals(theWindow)) {
            switch (mode) {
              case (Skatolo.WAIT):
                if (moved()) {
                  startTime = System.nanoTime();
                }

                if (System.nanoTime() > startTime + (delayInMillis * 1000000)) {

                  position.set(currentPosition);
                  alignH = Skatolo.RIGHT;
                  if (position.x
                      > (controller.getControlWindow().papplet().width - (getWidth() + 20))) {
                    position.sub(new PVector(getWidth(), 0, 0));
                    alignH = Skatolo.LEFT;
                  }
                  mode = Skatolo.FADEIN;
                  startTime = System.nanoTime();
                  currentAlpha = 0;
                }
                break;
              case (Skatolo.FADEIN):
                float t1 = System.nanoTime() - startTime;
                currentAlpha = (int) PApplet.map(t1, 0, 200 * 1000000, 0, maxAlpha);
                if (currentAlpha >= 250) {
                  mode = Skatolo.IDLE;
                  currentAlpha = 255;
                }
                break;
              case (Skatolo.IDLE):
                break;
              case (Skatolo.FADEOUT):
                float t2 = System.nanoTime() - startTime;
                currentAlpha = (int) PApplet.map(t2, 0, 200 * 1000000, maxAlpha, 0);
                if (currentAlpha <= 0) {
                  mode = Skatolo.DONE;
                }
                break;
              case (Skatolo.DONE):
                controller = null;
                mode = Skatolo.INACTIVE;
                position.set(-1000, -1000, 0);
            }

            currentAlpha = PApplet.max(0, PApplet.min(currentAlpha, maxAlpha));

            if (mode >= Skatolo.WAIT) {
              currentAlpha = (mode == Skatolo.WAIT) ? 0 : currentAlpha;
              theWindow.graphics().pushMatrix();
              theWindow.graphics().translate(position.x, position.y);
              theWindow.graphics().translate(offset.x, offset.y);
              controllerView.display(theWindow.graphics(), null); // TODO: Warning HERE !
              theWindow.graphics().popMatrix();
            }
            if (mode < Skatolo.FADEOUT) {
              if (moved()) {
                deactivate(0);
              }
            }
          }
        }
      }
    }
  }
 @Override
 public void harmTarget(Harmable target, float distance) {
   target.harm(this.damage * PApplet.map(distance, 0, this.range, -1f, -0.5f) * (-1f));
 }