Пример #1
0
    public void display(PApplet theApplet, Controller theController) {
      theApplet.translate(_myRadius, _myRadius);

      theApplet.pushMatrix();
      theApplet.pushStyle();
      theApplet.ellipseMode(PApplet.CENTER);
      theApplet.noStroke();
      theApplet.fill(color().colorBackground);
      theApplet.ellipse(0, 0, _myRadius * 2, _myRadius * 2);
      theApplet.popMatrix();

      theApplet.pushMatrix();
      if (displayStyle == LINE) {
        theApplet.rotate(myAngle);
        theApplet.stroke(color().colorForeground);
        theApplet.line(0, 0, _myRadius, 0);
      } else if (displayStyle == ELLIPSE) {
        theApplet.rotate(myAngle);
        theApplet.noStroke();
        theApplet.fill(color().colorForeground);
        theApplet.ellipse(_myRadius * 0.75f, 0, _myRadius * 0.2f, _myRadius * 0.2f);
      } else if (displayStyle == ARC) {
        theApplet.noStroke();
        theApplet.fill(color().colorForeground);
        theApplet.arc(0, 0, _myRadius * 1.8f, _myRadius * 1.8f, startAngle, myAngle);
        theApplet.fill(color().colorBackground);
        theApplet.ellipse(0, 0, _myRadius * 1.2f, _myRadius * 1.2f);
      }
      theApplet.popMatrix();

      theApplet.pushMatrix();
      theApplet.rotate(startAngle);

      if (isShowTickMarks) {
        float step = range / _myTickMarksNum;
        theApplet.stroke(color().colorForeground);
        theApplet.strokeWeight(myTickMarkWeight);
        for (int i = 0; i <= _myTickMarksNum; i++) {
          theApplet.line(_myRadius + 2, 0, _myRadius + myTickMarkLength + 2, 0);
          theApplet.rotate(step);
        }
      } else {
        if (isShowRange) {
          theApplet.stroke(color().colorForeground);
          theApplet.strokeWeight(myTickMarkWeight);
          theApplet.line(_myRadius + 2, 0, _myRadius + myTickMarkLength + 2, 0);
          theApplet.rotate(range);
          theApplet.line(_myRadius + 2, 0, _myRadius + myTickMarkLength + 2, 0);
        }
      }
      theApplet.noStroke();
      theApplet.popStyle();
      theApplet.popMatrix();
    }
Пример #2
0
 public void displayByArea(DisplayArea area) {
   changeMode();
   position.add(direction);
   if (position.z > 300 || position.z < -300) { // ograniczenie poruszania się obszaru wyświetlania
     direction.mult(-1);
   }
   area.moveCenterTo(position);
   pApplet.stroke(255, 0, 0);
   pApplet.pushMatrix();
   for (int j = 0; j < model.getSegmentCount(); j++) {
     Segment segment = model.getSegment(j);
     Face[] faces = segment.getFaces();
     pApplet.beginShape(PConstants.QUADS);
     for (Face face : faces) {
       if (area.isColliding(face.getCenter())) {
         PVector[] v = face.getVertices();
         PVector[] n = face.getNormals();
         for (int k = 0; k < v.length; k++) {
           pApplet.normal(n[k].x, n[k].y, n[k].z);
           pApplet.vertex(v[k].x, v[k].y, v[k].z);
         }
       }
     }
     pApplet.endShape();
   }
   pApplet.popMatrix();
 }
Пример #3
0
 public void drawCollisionShapes() {
   p.fill(255, 0, 0, 50);
   for (CollisionCircle circle : collisionShapes.values()) {
     p.stroke(0, 2);
     p.ellipse(circle.center.x, circle.center.y, circle.radius, circle.radius);
   }
 }
Пример #4
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);
  }
Пример #5
0
 /** Display the Repeller */
 public void display() {
   p.stroke(color1);
   if (dragging) p.fill(Style.textColorBlk);
   else if (rollover) p.fill(color2);
   else p.noFill();
   p.ellipse(getLoc().x, getLoc().y, radius * 2, radius * 2);
 }
Пример #6
0
 public void drawJunction() {
   parent.pushMatrix();
   parent.translate(x, y, z);
   parent.stroke(255, 255, 255);
   parent.fill(255); // 0, 0, 0, 0);
   parent.box(x_dim, y_dim, z_dim);
   parent.popMatrix();
 }
Пример #7
0
 void drawConsole() {
   // Draw console
   parent.stroke(255);
   parent.fill(0);
   parent.rect(parent.width - 410, 10, 400, 30);
   parent.fill(255);
   parent.text(textBuffer, parent.width - 400, 30);
 }
Пример #8
0
  @Override
  public void preRender(PApplet p) {
    super.preRender(p);

    p.rectMode(PApplet.CENTER);
    p.fill(getFillColor().getRGB());
    p.stroke(getStrokeColor().getRGB());
    p.strokeWeight(getStrokeWeight());
  }
 public static void staticDisplay(PApplet main, char player, int width, int height) {
   String name = "Knight";
   if (player == Chess.WHITE) {
     main.stroke(255);
     main.fill(255);
     main.ellipse(width, height, 40, 40);
     main.stroke(0);
     main.fill(0);
     main.text(name, width - 15, height + 5);
   } else {
     main.stroke(0);
     main.fill(0);
     main.ellipse(width, height, 40, 40);
     main.stroke(255);
     main.fill(255);
     main.text(name, width - 15, height + 5);
   } // end if-else
 } // end staticDisplay()
Пример #10
0
  public void draw() {
    PVector v = getBezierPoint3D();

    p.stroke(color, 50);
    p.pushMatrix();
    p.translate(v.x, v.y, v.z);
    p.sphere(2);
    p.popMatrix();
  }
  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();
  }
  public void draw() {
    // Iterate over all elements
    for (int i = 1; i < elementNum; i++) {
      // Set color
      p.stroke(elementColors[i]);

      if (i == 1) {

      } else {
        p.stroke(elementColors[i]);
        p.line(
            elements[i].x,
            elements[i].y,
            elements[i].z,
            elements[i - 1].x,
            elements[i - 1].y,
            elements[i - 1].z);
        p.noStroke();
      }
    }
  }
Пример #13
0
  public void draw() {
    if (!logic) {
      myParent.stroke(line_color);
    }

    for (int x = 1; x < dim[0]; x++) {
      if (logic) {
        if (values[x] > (resolution / 2)) {
          myParent.stroke(logic_colors[1]);
        } else {
          myParent.stroke(logic_colors[0]);
        }
        myParent.line(pos[0] + dim[0] - x - 2, pos[1], pos[0] + dim[0] - x - 2, pos[1] + dim[1]);
      } else {
        myParent.line(
            pos[0] + dim[0] - x,
            pos[1] + dim[1] - getY(values[x - 1]) - 1,
            pos[0] + dim[0] - x,
            pos[1] + dim[1] - getY(values[x]) - 1);
      }
    }
  }
Пример #14
0
  /**
   * Updates the particle view. This should be called on each draw cycle in order to update the
   * positions of all nodes and edges in the viewer. If you need to update the positions of
   * particles without drawing it (e.g. to speed up movement, call updateParticles() instead.
   */
  public void draw() {
    parent.pushStyle();
    parent.pushMatrix();
    zoomer.transform();
    updateCentroid();
    centroid.tick();

    parent.translate(width / 2, height / 2);
    parent.scale(centroid.getZ());
    parent.translate(-centroid.getX(), -centroid.getY());

    if (!isPaused) {
      updateParticles();
    }

    // Ensure that any selected element is positioned at the mouse location.
    if (selectedNode != null) {
      Particle p = nodes.get(selectedNode);
      p.makeFixed();
      float mX = (zoomer.getMouseCoord().x - (width / 2)) / centroid.getZ() + centroid.getX();
      float mY = (zoomer.getMouseCoord().y - (height / 2)) / centroid.getZ() + centroid.getY();
      p.position().set(mX, mY, 0);
    }

    // Draw edges if we have positive stroke weight.
    if (parent.g.strokeWeight > 0) {
      parent.stroke(0, 180);
      parent.noFill();

      for (Map.Entry<E, Spring> row : edges.entrySet()) {
        E edge = row.getKey();
        Spring spring = row.getValue();
        Vector3D p1 = spring.getOneEnd().position();
        Vector3D p2 = spring.getTheOtherEnd().position();
        edge.draw(parent, p1.x(), p1.y(), p2.x(), p2.y());
      }
    }

    // Draw nodes.
    parent.noStroke();
    parent.fill(120, 50, 50, 180);

    for (Map.Entry<N, Particle> row : nodes.entrySet()) {
      N node = row.getKey();
      Vector3D p = row.getValue().position();
      node.draw(parent, p.x(), p.y());
    }

    parent.popMatrix();
    parent.popStyle();
  }
Пример #15
0
  public void drawJunction() {
    parent.pushMatrix();
    if (stroke_color[0] != -1) {
      int[] rgb = RecursiveTower.hsvToRgb(stroke_color[0], stroke_color[1], stroke_color[2]);
      parent.stroke(rgb[0], rgb[1], rgb[2]);
    } else {
      parent.noStroke();
    }
    if (fill_color[0] != -1) {
      int[] rgb = RecursiveTower.hsvToRgb(fill_color[0], fill_color[1], fill_color[2]);
      parent.fill(rgb[0], rgb[1], rgb[2]);
    } else {
      parent.noFill();
    }
    switch (tower_orientation) {
      case 0:
        // moving in +x direction
        // +x becomes +y, +y becomes +z, +z becomes +x
        parent.translate(z, x, y);
        parent.box(z_dim, x_dim, y_dim);
        break;
      case 1:
        // moving in -x direction
        // +x becomes +y, +y becomes +z, +z becomes -x
        parent.translate(-z, x, y);
        parent.box(z_dim, x_dim, y_dim);
        break;
      case 2:
        // moving in +y direction
        // x stays the same, +y becomes +z, +z becomes +y
        parent.translate(x, z, y);
        parent.box(x_dim, z_dim, y_dim);
        break;
      case 3:
        // moving in -y direction
        // x stays the same, +y becomes +z, +z becomes -y
        parent.translate(x, -z, y);
        parent.box(x_dim, z_dim, y_dim);
        break;
      case 4:
        // moving in +z direction
        // xyz coordinates stay the same
        parent.translate(x, y, z);
        parent.box(x_dim, y_dim, z_dim);
        break;
    }

    parent.popMatrix();
  }
Пример #16
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();
  }
  public void drawSquares() {
    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < data[i].length; j++) {
        float cor = 255 - ((float) data[3 - i][j][QTD] / 100) * 255;
        parent.fill(cor);
        parent.stroke(cor);
        parent.rect(
            startAtX + squareSpace + j * squareSpace,
            startAtY + (i + 1) * squareSpace,
            squareSpace,
            squareSpace);

        if (cor > 127) cor = 0;
        else cor = 255;

        parent.fill(cor);
        parent.text(
            "" + data[3 - i][j][QTD],
            startAtX + squareSpace + j * squareSpace,
            startAtY + (i + 1) * squareSpace + squareSpace);
      }
    }
  }
  public void drawSquaresAt(int comeco, int qtd, int x, int y, int squareX, int squareY) {
    for (int i = 0; i < data.length; i++) {
      for (int j = comeco; j < comeco + qtd; j++) {

        int quantidade = data[3 - i][j][QTD];
        float cor = 255 - ((float) quantidade / 100) * 255;

        parent.fill(cor);
        parent.stroke(cor);
        int atX = x + (j - comeco) * squareX;
        int atY = y + i * squareY;
        parent.rect(atX, atY, atX + squareX, atY + squareY);

        if (cor > 127) cor = 0;
        else cor = 255;

        parent.fill(cor);
        if (probabilidades) parent.text("" + quantidade + "%", atX + 30, atY + 30);
        else parent.text("" + quantidade, atX + 30, atY + 30);
        //				parent.text("" + data[3 - i][j][QTD], startAtX + squareSpace + j * squareSpace,
        // startAtY + (i + 1) * squareSpace + squareSpace);
      }
    }
  }
Пример #19
0
 // draw center line
 public void drawBounds() {
   myParent.stroke(bounds_color);
   myParent.line(pos[0], pos[1] + (dim[1] / 2), dim[0], pos[1] + (dim[1] / 2));
 }
Пример #20
0
  // draw method for all of the parts of the lamp
  public void draw(float zoom, float color, boolean shadeDraw, boolean partsDraw) {
    myParent.background(100, 100, 100);

    if (shadeDraw) {
      myParent.pushMatrix();
      myParent.translate(0, 0, zoom);
      for (int j = 0; j < shade.edges.size(); j++) {
        DCHalfEdge edge = shade.edges.get(j);
        float edgeStartX = (float) (edge.start.getX());
        float edgeStartY = (float) (edge.start.getY());

        float edgeEndX = (float) (edge.end.getX());
        float edgeEndY = (float) (edge.end.getY());
        myParent.stroke(color);
        myParent.strokeWeight(3);

        myParent.line(edgeStartX, edgeStartY, edgeEndX, edgeEndY);
      }
      myParent.popMatrix();
    }
    if (partsDraw) {
      myParent.pushMatrix();
      myParent.translate(myParent.width / 2 - 350, myParent.height / 2, zoom);
      for (int j = 0; j < rib.edges.size(); j++) {
        DCHalfEdge edge = rib.edges.get(j);
        float edgeStartX = (float) (edge.start.getX());
        float edgeStartY = (float) (edge.start.getY());

        float edgeEndX = (float) (edge.end.getX());
        float edgeEndY = (float) (edge.end.getY());

        myParent.stroke(color);
        myParent.strokeWeight(3);
        if (edge.inner) {
          myParent.stroke(255, 0, 0);
        }
        myParent.line(edgeStartX, edgeStartY, edgeEndX, edgeEndY);
      }
      myParent.popMatrix();

      myParent.pushMatrix();
      myParent.translate(100, 40, zoom);
      for (int j = 0; j < bottomBase.edges.size(); j++) {
        DCHalfEdge edge = bottomBase.edges.get(j);
        float edgeStartX = (float) (edge.start.getX());
        float edgeStartY = (float) (edge.start.getY());

        float edgeEndX = (float) (edge.end.getX());
        float edgeEndY = (float) (edge.end.getY());
        myParent.stroke(color);
        myParent.strokeWeight(3);
        if (edge.inner) {
          myParent.stroke(255, 0, 0);
        }
        myParent.line(edgeStartX, edgeStartY, edgeEndX, edgeEndY);
        myParent.stroke(255, 0, 0);
      }
      myParent.popMatrix();

      myParent.pushMatrix();
      myParent.translate(100, myParent.height - 150, zoom);
      for (int j = 0; j < topBase.edges.size(); j++) {

        DCHalfEdge edge = topBase.edges.get(j);
        float edgeStartX = (float) (edge.start.getX());
        float edgeStartY = (float) (edge.start.getY());

        float edgeEndX = (float) (edge.end.getX());
        float edgeEndY = (float) (edge.end.getY());
        myParent.stroke(color);
        myParent.strokeWeight(3);
        if (edge.inner) {
          myParent.stroke(255, 0, 0);
        }
        myParent.line(edgeStartX, edgeStartY, edgeEndX, edgeEndY);
        myParent.stroke(255, 0, 0);
      }
      myParent.popMatrix();
    }
  }
Пример #21
0
  public void draw(final PApplet p, final Game g, final PlasmaFluid fluid) {
    p.pushStyle();

    p.stroke(255);
    p.strokeWeight(3);
    p.fill(150, 150);
    p.ellipseMode(PApplet.CENTER);

    p.rectMode(PApplet.CORNER);
    if (g.mode == Game.PREGAME_WAIT
        || g.mode == Game.JUST_SCORED
        || g.mode == Game.JUST_SCORED_WAIT) {

      int numcircles = 0;

      final int count = g.modeFrameCountdown;
      if (count > (Const.PREGAME_WAIT_COUNT * 2 / 3)) {
        numcircles = 3;
      } else if (count > (Const.PREGAME_WAIT_COUNT / 3)) {
        numcircles = 2;
      } else {
        numcircles = 1;
      }

      final float stepsize = width / 8;
      final float size = width / 9f;
      if (numcircles > 2) {
        p.ellipse(stepsize * 2, height / 2, size * 0.75f, size * 0.75f);
        p.ellipse(stepsize * 6, height / 2, size * 0.75f, size * 0.75f);
      }
      if (numcircles > 1) {
        p.ellipse(stepsize * 5, height / 2, size * 0.9f, size * 0.9f);
        p.ellipse(stepsize * 3, height / 2, size * 0.9f, size * 0.9f);
      }
      p.ellipse(stepsize * 4, height / 2, size, size);

      if (numcircles == 2 && numcircles != lastnum) {
        fluid.addForce(
            p,
            (stepsize * 2) / width,
            0.5f,
            -forceval * (1 + r.nextFloat()),
            0,
            Const.OTHER_OFFSET,
            colorval);
        fluid.addForce(
            p,
            (stepsize * 6) / width,
            0.5f,
            forceval * (1 + r.nextFloat()),
            0,
            Const.OTHER_OFFSET,
            colorval);
      }
      if (numcircles == 1 && numcircles != lastnum) {
        fluid.addForce(
            p,
            (stepsize * 5) / width,
            0.5f,
            0,
            forceval * (1 + r.nextFloat()),
            Const.OTHER_OFFSET,
            colorval);
        fluid.addForce(
            p,
            (stepsize * 3) / width,
            0.5f,
            0,
            -forceval * (1 + r.nextFloat()),
            Const.OTHER_OFFSET,
            colorval);
      }
      //			if (numcircles == 1 && count == 0) {
      //				fluid.addForce(p, (stepsize*4.2f)/width, 0.5f, 0, forceval*(1+r.nextFloat()),
      // Const.OTHER_OFFSET, colorval);
      //				fluid.addForce(p, (stepsize*3.8f)/width, 0.5f, 0, -forceval*(1+r.nextFloat()),
      // Const.OTHER_OFFSET, colorval);
      //			}

      lastnum = numcircles;
    } else if (g.mode == Game.GAME_OVER) {
      p.stroke(255);
      p.fill(255);
      p.rect(width / 2, height / 2, g.modeFrameCountdown * 3, 30);
    }

    p.popStyle();
  }
Пример #22
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();
      }
    }
  }
Пример #23
0
  /**
   * Draws the histogram
   *
   * @param plotBasePoint the histogram base point in the plot reference system
   */
  public void draw(GPoint plotBasePoint) {
    if (visible) {
      // Calculate the baseline for the histogram
      float baseline = 0;

      if (plotBasePoint.isValid()) {
        baseline = (type == GPlot.VERTICAL) ? plotBasePoint.getY() : plotBasePoint.getX();
      }

      // Draw the rectangles
      parent.pushStyle();
      parent.rectMode(CORNERS);
      parent.strokeCap(SQUARE);

      for (int i = 0; i < plotPoints.getNPoints(); i++) {
        if (plotPoints.isValid(i)) {
          // Obtain the corners
          float x1, x2, y1, y2;

          if (type == GPlot.VERTICAL) {
            x1 = plotPoints.getX(i) - leftSides.get(i);
            x2 = plotPoints.getX(i) + rightSides.get(i);
            y1 = plotPoints.getY(i);
            y2 = baseline;
          } else {
            x1 = baseline;
            x2 = plotPoints.getX(i);
            y1 = plotPoints.getY(i) - leftSides.get(i);
            y2 = plotPoints.getY(i) + rightSides.get(i);
          }

          if (x1 < 0) {
            x1 = 0;
          } else if (x1 > dim[0]) {
            x1 = dim[0];
          }

          if (-y1 < 0) {
            y1 = 0;
          } else if (-y1 > dim[1]) {
            y1 = -dim[1];
          }

          if (x2 < 0) {
            x2 = 0;
          } else if (x2 > dim[0]) {
            x2 = dim[0];
          }

          if (-y2 < 0) {
            y2 = 0;
          } else if (-y2 > dim[1]) {
            y2 = -dim[1];
          }

          // Draw the rectangle
          float lw = lineWidths[i % lineWidths.length];
          parent.fill(bgColors[i % bgColors.length]);
          parent.stroke(lineColors[i % lineColors.length]);
          parent.strokeWeight(lw);

          if (Math.abs(x2 - x1) > 2 * lw && Math.abs(y2 - y1) > 2 * lw) {
            parent.rect(x1, y1, x2, y2);
          } else if ((type == GPlot.VERTICAL
                  && x2 != x1
                  && !(y1 == y2 && (y1 == 0 || y1 == -dim[1])))
              || (type == GPlot.HORIZONTAL
                  && y2 != y1
                  && !(x1 == x2 && (x1 == 0 || x1 == dim[0])))) {
            parent.rect(x1, y1, x2, y2);
            parent.line(x1, y1, x1, y2);
            parent.line(x2, y1, x2, y2);
            parent.line(x1, y1, x2, y1);
            parent.line(x1, y2, x2, y2);
          }
        }
      }

      parent.popStyle();

      // Draw the labels
      if (drawLabels) {
        drawHistLabels();
      }
    }
  }
Пример #24
0
 public void draw() {
   parent.stroke(255);
   parent.fill(0x024C68);
   parent.rect(position.x, position.y, width, height);
 }