Esempio n. 1
0
  public void draw(PApplet canvas, float scale) {
    PVector orient = PVector.fromAngle(orientation);
    orient.mult(scale * getRadius());
    float x = (float) position.x * scale;
    float y = (float) position.y * scale;
    float diameter = getRadius() * 2 * scale;

    canvas.fill(teamColor);
    canvas.stroke(0);
    canvas.ellipse(x, y, diameter, diameter);
    canvas.line(x, y, x + (float) orient.x, y + (float) orient.y);

    // Delegate Decoration to Robot
    float heading = orient.heading();
    float drawScale = 100f / scale * getRadius();

    canvas.translate(x, y);
    canvas.rotate(heading);
    canvas.scale(drawScale);
    // TODO: How to resolve scale, so that teams don't have to mind it also...
    decorateRobot(canvas);
    canvas.scale(1f / drawScale);
    canvas.rotate(-heading);
    canvas.translate(-x, -y);
  }
  public void draw() {
    p.pushMatrix();
    p.pushStyle();
    p.fill(100, 100, 0);
    p.rect(0, 0, width, height);
    //  p.scale((float)ppHor, (float)ppVert);
    // p.translate(x, y);
    // p.sca
    // p.stroke(0);
    // p.strokeWeight(1.0f);
    p.noStroke();
    p.rectMode(PApplet.CORNER);

    // p.line(0, 0, 100, 100);

    // TODO: block on datset change here.
    if (d.getNumDatapoints() > minInd) {
      int which = 0;
      int i = minInd;
      for (; (i <= maxInd && i < d.getNumDatapoints()); i++) {
        Double v = d.getParam(i, myId);
        if (!v.isNaN()) {
          if (i >= minSelected && i <= maxSelected) {
            // p.stroke(0, 0, 256);
            p.noStroke();
            p.fill(hues[(int) d.getParam(i, myId)], 150, 256);
          } else {
            p.noStroke();
            p.fill(hues[(int) d.getParam(i, myId)], 256, 256);
          }
        } else {
          if (i >= minSelected && i <= maxSelected) {
            // p.stroke(0, 0, 256);
            p.noStroke();
            p.fill(200);
          } else {
            p.noStroke();
            p.fill(0);
          }
        }
        p.rect((ppHor * which++), 0, ppHor, height);
      }
    }

    p.popStyle();
    p.popMatrix();
  }
Esempio n. 3
0
  // Drawing the box
  void display() {
    // We look at each body and get its screen position
    Vec2 pos = box2d.getBodyPixelCoord(body);
    // Get its angle of rotation
    float a = body.getAngle();

    parent.rectMode(PConstants.CENTER);
    parent.pushMatrix();
    parent.translate(pos.x, pos.y);
    parent.rotate(-a);
    parent.fill(127);
    parent.stroke(0);
    parent.strokeWeight(2);
    parent.rect(0, 0, w, h);
    parent.popMatrix();
  }
Esempio n. 4
0
  public void drawGrid(int[][] f) {
    int piece;
    int numcols = f[0].length;
    int numrows = f.length;

    for (int i = 0; i < numcols; i++) {
      for (int j = 0; j < numrows; j++) {
        piece = f[i][j];
        if (piece == 1) {
          p.image(piece1, x + i * dx + 1, y + j * dy + 1, dx - 1, dy - 1);
        } else if (piece == 2) {
          p.image(piece2, x + i * dx + 1, y + j * dy + 1, dx - 1, dy - 1);
        } else {
          p.fill(EMPTY_COLOR);
          p.rect(x + i * dx, y + j * dy, dx, dy);
        }
      }
    }
  }
Esempio n. 5
0
  /**
   * Draws the vertices to the screen.
   *
   * @param inpAudioFrameIdx The audio frame to reference for height data.
   */
  public void drawSphere(int inpAudioFrameIdx) {
    _audioFrameDataVals = rtrvAudioFrameData(inpAudioFrameIdx);
    float prevAudioFrameLvlNbr, currAudioFrameLvlNbr;

    if (inpAudioFrameIdx > 0) {
      prevAudioFrameLvlNbr = rtrvAudioFrameData(inpAudioFrameIdx - 1)[0];
    } else {
      prevAudioFrameLvlNbr = 0;
    }

    currAudioFrameLvlNbr = rtrvAudioFrameData(inpAudioFrameIdx)[0];

    // _parApp.noStroke();
    _parApp.stroke(_fillClrNbr);
    _lerpClrAmt = _parApp.frameCount / (float) _musicData.length;
    _fillClrNbr = (int) PApplet.lerpColor(FROM_CLR_NBR, TO_CLR_NBR, _lerpClrAmt, PApplet.RGB);
    _parApp.fill(_fillClrNbr);

    float newVertexHghtNbr = 0,
        adjacentLatitudeLnLatitudeDegNbr = 0,
        adjacentLatitudeLnLongitudeDegNbr = 0,
        adjacentLatitudeLnRadiusLenNbr = 0,
        currLatitudeLnLatitudeDegNbr = 0,
        currLatitudeLnLongitudeDegNbr = 0;
    PVector adjacentVertex, currVertex;
    int adjacentLatitudeVertexIdx = 0, currLatitudeVertexIdx = 0;

    for (int latitudeDegNbr = -90; latitudeDegNbr <= 90; latitudeDegNbr += _resNbr) {

      if (PApplet.abs(latitudeDegNbr) == 90) {
        // Create Triangle Fans for each of the poles.
        _parApp.beginShape(PApplet.TRIANGLE_FAN);

        // Draw the pole vertex.
        currLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr, 0);
        newVertexHghtNbr =
            calcAndStoreNewVertexHghtNbr(
                currLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr);
        currVertex = Main.toCartesian(latitudeDegNbr, 0, newVertexHghtNbr);
        // _parApp.text("Lat: " + latitudeDegNbr, currVertex.x, currVertex.y, currVertex.z + 20);
        _parApp.vertex(currVertex.x, currVertex.y, currVertex.z);

        float adjacentLatitudeDegNbr;

        if (latitudeDegNbr == -90) {
          adjacentLatitudeDegNbr = latitudeDegNbr + _resNbr;
        } else {
          adjacentLatitudeDegNbr = latitudeDegNbr - _resNbr;
        }

        // In order to complete the sphere, you have to go completely around the circle (i.e.,
        // include both -180 and 180).
        for (int longitudeDegNbr = -180; longitudeDegNbr <= 180; longitudeDegNbr += _resNbr) {

          adjacentLatitudeVertexIdx = calcVertexIdx(adjacentLatitudeDegNbr, longitudeDegNbr);

          if (longitudeDegNbr == 180) {
            // When we complete the circle, use the heights that we used for longitude = -180 to
            // stitch the mesh together.
            newVertexHghtNbr = _radiusLenNbrs[calcVertexIdx(adjacentLatitudeDegNbr, -180)];
          } else {
            // If we're building the second pole, we need to stitch it to the previous ring.
            if (adjacentLatitudeDegNbr == latitudeDegNbr - _resNbr) {
              adjacentLatitudeVertexIdx = calcVertexIdx(adjacentLatitudeDegNbr, longitudeDegNbr);
              newVertexHghtNbr = _radiusLenNbrs[adjacentLatitudeVertexIdx];
            } else {
              newVertexHghtNbr =
                  calcAndStoreNewVertexHghtNbr(
                      adjacentLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr);
            }
          }

          adjacentVertex =
              Main.toCartesian(adjacentLatitudeDegNbr, longitudeDegNbr, newVertexHghtNbr);
          _parApp.vertex(adjacentVertex.x, adjacentVertex.y, adjacentVertex.z);
        }

        _parApp.endShape();
      } else if (latitudeDegNbr - _resNbr != -90) {
        // We already built a triangle fan for the first pole, so we do not want to build a triangle
        // strip over it.
        _parApp.beginShape(PConstants.TRIANGLE_STRIP);

        // In order to complete the sphere, you have to go completely around the circle (i.e.,
        // include both -180 and 180).
        for (int longitudeDegNbr = -180; longitudeDegNbr <= 180; longitudeDegNbr += _resNbr) {

          if (PApplet.abs(latitudeDegNbr) < 90) {
            adjacentLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr - _resNbr, longitudeDegNbr);
            adjacentLatitudeLnLatitudeDegNbr = _latitudeDegs[adjacentLatitudeVertexIdx];
            adjacentLatitudeLnLongitudeDegNbr = _longitudeDegs[adjacentLatitudeVertexIdx];
            adjacentLatitudeLnRadiusLenNbr = _radiusLenNbrs[adjacentLatitudeVertexIdx];

            adjacentVertex =
                Main.toCartesian(
                    adjacentLatitudeLnLatitudeDegNbr,
                    adjacentLatitudeLnLongitudeDegNbr,
                    adjacentLatitudeLnRadiusLenNbr);
            _parApp.vertex(adjacentVertex.x, adjacentVertex.y, adjacentVertex.z);
          }

          currLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr, longitudeDegNbr);
          currLatitudeLnLatitudeDegNbr = _latitudeDegs[currLatitudeVertexIdx];
          currLatitudeLnLongitudeDegNbr = _longitudeDegs[currLatitudeVertexIdx];

          if (longitudeDegNbr == 180) {
            // When we complete the circle, use the heights that we used for longitude = -180 to
            // stitch the mesh together.
            newVertexHghtNbr = _radiusLenNbrs[calcVertexIdx(latitudeDegNbr, -180)];
          } else {
            newVertexHghtNbr =
                calcAndStoreNewVertexHghtNbr(
                    currLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr);
          }

          currVertex =
              Main.toCartesian(
                  currLatitudeLnLatitudeDegNbr, currLatitudeLnLongitudeDegNbr, newVertexHghtNbr);
          _parApp.vertex(currVertex.x, currVertex.y, currVertex.z);
        }
        _parApp.endShape();
      }
    }
  }
Esempio n. 6
0
 // Draw a box at the location
 public void highlightLocation(Location l) {
   p.fill(p.color(50, 200, 50, 150));
   p.rect(xCoordOf(l), yCoordOf(l), dx, dy);
 }