Пример #1
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);
 }
Пример #2
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);
 }
Пример #3
0
 protected void drawLabel(PApplet theApplet) {
   theApplet.pushMatrix();
   theApplet.fill(isInside ? color.colorForeground : color.colorBackground);
   if (isActive) {
     theApplet.fill(color.colorActive);
   }
   theApplet.rect(_myOffsetX, _myOffsetY, _myWidth - 1 + _myRightBorder, _myHeight);
   _myLabel.draw(theApplet, _myOffsetX + 4, _myOffsetY + 5);
   theApplet.popMatrix();
 }
Пример #4
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();
    }
Пример #5
0
 public void display(PApplet theApplet, Toggle theController) {
   if (isActive) {
     theApplet.fill(isOn ? color.getActive() : color.getForeground());
   } else {
     theApplet.fill(isOn ? color.getActive() : color.getBackground());
   }
   theApplet.rect(0, 0, width, height);
   if (isLabelVisible) {
     _myCaptionLabel.draw(theApplet, 0, 0, theController);
   }
 }
Пример #6
0
 public void display(PApplet theApplet, Toggle theController) {
   theApplet.fill(color.getBackground());
   theApplet.rect(0, 0, width, height);
   theApplet.fill(color.getActive());
   if (isOn) {
     theApplet.rect(0, 0, width / 2, height);
   } else {
     theApplet.rect((width % 2 == 0 ? 0 : 1) + width / 2, 0, width / 2, height);
   }
   if (isLabelVisible) {
     _myCaptionLabel.draw(theApplet, 0, 0, theController);
   }
 }
Пример #7
0
  public void thinkAndMove(final PApplet p) {
    // initial frame use only
    if (x == -1) x = p.width / 2;
    if (y == -1) y = p.height / 3;

    target_x = ball.x;
    target_y = ball.y - DESIRED_DIST_BEHIND; // want to get behind the ball

    final float diff_x = target_x - x;
    final float diff_y = target_y - y;
    if (diff_x < MAX_VELOCITY_X) {
      x = target_x;
    } else {
      if (x < target_x) x += MAX_VELOCITY_X;
      else if (x > target_x) x -= MAX_VELOCITY_X;
    }
    if (diff_y < MAX_VELOCITY_Y) {
      y = target_y;
    } else {
      if (y > target_y) y -= MAX_VELOCITY_Y;
      else if (y < target_y) y += MAX_VELOCITY_Y;
    }

    p.colorMode(PConstants.RGB);
    p.fill(255, 0, 0);
    p.ellipse(x, y, 5, 5);

    if (y < p.height / 3) {
      fluid.addForce(p, (x - 5) / p.width, y / p.height, 0, MAX_FORCE / p.height);
      fluid.addForce(p, (x) / p.width, y / p.height, 0, MAX_FORCE / p.height);
      fluid.addForce(p, (x + 5) / p.width, y / p.height, 0, MAX_FORCE / p.height);
    }
  }
Пример #8
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);
   }
 }
Пример #9
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);
  }
Пример #10
0
  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();
  }
Пример #11
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();
 }
Пример #12
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()
Пример #14
0
  /** Draws the histogram labels */
  protected void drawHistLabels() {
    parent.pushStyle();
    parent.textMode(MODEL);
    parent.textFont(font);
    parent.textSize(fontSize);
    parent.fill(fontColor);
    parent.noStroke();

    if (type == GPlot.VERTICAL) {
      if (rotateLabels) {
        parent.textAlign(RIGHT, CENTER);

        for (int i = 0; i < plotPoints.getNPoints(); i++) {
          if (plotPoints.isValid(i) && plotPoints.getX(i) >= 0 && plotPoints.getX(i) <= dim[0]) {
            parent.pushMatrix();
            parent.translate(plotPoints.getX(i), labelsOffset);
            parent.rotate(-HALF_PI);
            parent.text(plotPoints.getLabel(i), 0, 0);
            parent.popMatrix();
          }
        }
      } else {
        parent.textAlign(CENTER, TOP);

        for (int i = 0; i < plotPoints.getNPoints(); i++) {
          if (plotPoints.isValid(i) && plotPoints.getX(i) >= 0 && plotPoints.getX(i) <= dim[0]) {
            parent.text(plotPoints.getLabel(i), plotPoints.getX(i), labelsOffset);
          }
        }
      }
    } else {
      if (rotateLabels) {
        parent.textAlign(CENTER, BOTTOM);

        for (int i = 0; i < plotPoints.getNPoints(); i++) {
          if (plotPoints.isValid(i) && -plotPoints.getY(i) >= 0 && -plotPoints.getY(i) <= dim[1]) {
            parent.pushMatrix();
            parent.translate(-labelsOffset, plotPoints.getY(i));
            parent.rotate(-HALF_PI);
            parent.text(plotPoints.getLabel(i), 0, 0);
            parent.popMatrix();
          }
        }
      } else {
        parent.textAlign(RIGHT, CENTER);

        for (int i = 0; i < plotPoints.getNPoints(); i++) {
          if (plotPoints.isValid(i) && -plotPoints.getY(i) >= 0 && -plotPoints.getY(i) <= dim[1]) {
            parent.text(plotPoints.getLabel(i), -labelsOffset, plotPoints.getY(i));
          }
        }
      }
    }

    parent.popStyle();
  }
Пример #15
0
  @Override
  public void display() {
    if (isDisplay) {
      context.fill(0, 80);
      // rect(xpos, ypos, width, width);
      context.fill(196, 196, 196, 80);
      context.ellipse(xpos + width / 2, ypos + width / 2, width, width);

      context.fill(255);
      context.ellipse(xpos + width / 2, ypos + width / 2, width / 2, width / 2);
      if (isSelected) {
        context.fill(255, 196, 13);
        context.ellipse(xpos + width / 2, ypos + width / 2, width / 2, width / 2);
      }
      context.fill(255);
      context.textSize(10);
      context.text("Bus Number", xpos - width, ypos + 3 * height / 2);
    }
  }
  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();
  }
Пример #17
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();
  }
  public void draw(int x, int y, int width, int height) {
    parent.fill(120);

    parent.textSize(20);
    parent.text(titulo, startAtX, startAtY - 22);
    parent.textSize(10);
    parent.text(eixoX + " x " + eixoY, startAtX, startAtY - 10);

    parent.textSize(squareSpace / 2);

    drawYAxis();
    drawXAxis();
    drawSquares();
  }
  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);
      }
    }
  }
Пример #20
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();
  }
  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);
      }
    }
  }
Пример #22
0
  /**
   * Draws the control where if should be drawn
   *
   * @param p
   */
  public void draw() {
    p.pushMatrix();
    p.pushStyle();

    p.translate(x, y);
    p.fill(textColor);

    // AlignUtils.positionText(p, width, height, xAlign, yAlign);
    p.textAlign(PApplet.LEFT, PApplet.CENTER);

    p.text(name, 0, height / 2);
    // p.text(name, 0, 0);

    p.popStyle();
    p.popMatrix();
  }
Пример #23
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();
  }
Пример #24
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);
 }
Пример #25
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);
        }
      }
    }
  }
Пример #26
0
 public void draw(PApplet p) {
   p.fill(_color);
   p.ellipse(BomberMan.TILE_SIZE / 2, BomberMan.TILE_SIZE / 2, DIAMETER, DIAMETER);
 }
Пример #27
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();
  }
Пример #28
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();
      }
    }
  }
Пример #29
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);
 }
Пример #30
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();
      }
    }
  }