public int colorFor(Word word) { host.pushStyle(); host.colorMode(PConstants.HSB, range); int color = getColorFor(word); host.popStyle(); return color; }
/** 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(); }
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(); }
/** * 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(); }
/** * 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(); }
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(); }
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(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(); }
/** * 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(); } } }