long delay = PApplet.round((lastTime + avgTimePerFrame - now) / 1e6f); try { if (delay > 0) Thread.sleep(delay);
/** * Create a bitmap font on the fly from either a font name that's * installed on the system, or from a .ttf or .otf that's inside * the data folder of this sketch. * <p/> * Use 'null' for the charset if you want to dynamically create * character bitmaps only as they're needed. */ public PFont createFont(String name, float size, boolean smooth, char[] charset) { String lowerName = name.toLowerCase(); Typeface baseFont = null; if (lowerName.endsWith(".otf") || lowerName.endsWith(".ttf")) { AssetManager assets = activity.getAssets(); baseFont = Typeface.createFromAsset(assets, name); } else { baseFont = (Typeface) PFont.findNative(name); } return new PFont(baseFont, round(size), smooth, charset); }
public PVector worldToPixel(PVector pt, boolean undistort) { // Reprojection float invZ = 1.0f / pt.z; int px = PApplet.constrain(PApplet.round((pt.x * invZ * fx) + cx), 0, w - 1); int py = PApplet.constrain(PApplet.round((pt.y * invZ * fy) + cy), 0, h - 1); if (undistort && this.handleDistorsion) { double[] out = device.distort(px, py); return new PVector((float) out[0], (float) out[1]); } else { return new PVector(px, py); } }
/** * Handle distorsions * * @param pt * @return */ public PVector worldToPixelCoord(PVector pt, boolean undist) { // Reprojection float invZ = 1.0f / pt.z; int px = PApplet.constrain(PApplet.round((pt.x * invZ * fx) + cx), 0, w - 1); int py = PApplet.constrain(PApplet.round((pt.y * invZ * fy) + cy), 0, h - 1); if (this.handleDistorsion && undist) { double[] out = device.undistort(px, py); px = (int) (out[0]); py = (int) (out[1]); } return new PVector(px, py); }
public int getAlpha(int max) { if (parent != null && inner) { // Constraining by the opacity of the parent in case this is an "inner" // widget. max = PApplet.min(max, parent.getAlpha(255)); } return PApplet.round(opacity.get() * max); }
public float drag(float newp, float maxd) { float x1 = PApplet.constrain(newp, 0, maxd); int tot = colLabels.getTotItemsCount() - 1; int idx = PApplet.round(PApplet.map(x1, 0, maxd, 0, tot)); mira.browser.openColumn(idx); return x1; } public void stopDrag() {
public float press(float pos, float maxd) { float x1 = PApplet.constrain(pos, 0, maxd); int tot = rowBrowser.getChildrenCount() - 1; int idx = PApplet.round(PApplet.map(x1, 0, maxd, 0, tot)); goTo(idx); return x1; } public int pressSlider(float pos, float size) {
public float press(float pos, float maxd) { float x1 = PApplet.constrain(pos, 0, maxd); int tot = colLabels.getTotItemsCount() - 1; int idx = PApplet.round(PApplet.map(x1, 0, maxd, 0, tot)); mira.browser.openColumn(idx); return x1; } public int pressSlider(float pos, float size) {
public float drag(float newp, float maxd) { float x1 = PApplet.constrain(newp, 0, maxd); int tot = rowBrowser.getChildrenCount() - 1; int idx = PApplet.round(PApplet.map(x1, 0, maxd, 0, tot)); goTo(idx); return x1; } public void stopDrag() {
public float drag(float newp, float maxd) { float y1 = PApplet.constrain(newp, 0, maxd); int tot = rowBrowser.getTotItemsCount() - 1; int n = PApplet.round(PApplet.map(y1, 0, maxd, 0, tot)); RowScroller scroller = rowBrowser.getScroller(); scroller.jumpTo(n); return y1; } public void stopDrag() {
public float press(float pos, float maxd) { float y1 = PApplet.constrain(pos, 0, maxd); int tot = rowBrowser.getTotItemsCount() - 1; int n = PApplet.round(PApplet.map(y1, 0, maxd, 0, tot - 1)); RowScroller scroller = rowBrowser.getScroller(); scroller.jumpTo(n); return y1; } public int pressSlider(float pos, float size) {
public void snap() { if (getCount() == 0) return; float x0 = visX0.getTarget(); float x1 = visX1.getTarget(); int i0 = PApplet.constrain(PApplet.round(x0 / itemWidth), 0, getCount() - 1); int i1 = PApplet.constrain(PApplet.round(x1 / itemWidth), 0, getCount() - 1); if (PApplet.abs(i0 * itemWidth - x0) < SNAP_THRESHOLD) { visX0.setTarget(i0 * itemWidth); } else if (PApplet.abs(i1 * itemWidth - x1) < SNAP_THRESHOLD) { visX1.setTarget(i1 * itemWidth); } }
protected BoxplotSelection getPercentileSelection(float x0, float x1, float v0, float v1, float p, double valx, double valy, int counts, boolean shift) { float y0 = 1 - v1; float dy = v1 - v0; float y1 = y0 + dy; if (x0 <= valx && valx <= x1 && y0 <= valy && valy <= y1) { BoxplotSelection sel = new BoxplotSelection(x0, y0, x1 - x0, dy); sel.setColor(mixColors(WHITE, COLOR, 0.5f)); if (shift) { sel.setLabel(PApplet.round(p * counts) + "/" + counts); } else { sel.setLabel(PApplet.nfc(100 * p, 2) + "%"); } return sel; } return null; }
public Selection getSelection(double valx, double valy, boolean shift) { if (canDraw()) { float binw = 1.0f / binCount; for (int bx = 0; bx < binCount; bx++) { float p = density[bx]; float h = PApplet.map(p, 0, maxProb, 0, 0.5f); float x0 = binw * bx; float x1 = binw * bx + binw; if (x0 < valx && valx < x1) { Selection sel = new Selection(x0, (1 - h), binw, h); if (shift) { sel.setLabel(PApplet.round(sampleSize * p) + "/" + sampleSize); } else { sel.setLabel(PApplet.nfc(100 * p, 2) + "%"); } return sel; } } } else { return getUnavailableSelection(); } return null; }
public Selection getSelection(double valx, double valy, boolean shift) { if (canDraw()) { float binw = 1.0f / binCountX; float binh = 1.0f / binCountY; for (int bx = 0; bx < binCountX; bx++) { for (int by = 0; by < binCountY; by++) { float x0 = binw * bx; float y0 = 1 - binh * by - binh; float x1 = x0 + binw; float y1 = y0 + binh; if (x0 <= valx && valx <= x1 && y0 <= valy && valy <= y1) { Selection sel = new Selection(x0, y0, binw, binh); float p = density[bx][by]; float np = PApplet.map(p, 0, maxProb, 0, 1); sel.setColor(mixColors(WHITE, COLOR, np)); if (shift) { sel.setLabel(PApplet.round(sampleSize * p) + "/" + sampleSize); } else { sel.setLabel(PApplet.nfc(100 * p, 2) + "%"); } return sel; } } } } else { return getUnavailableSelection(); } return null; }
if (shift) { float count = (density[bx][by] / dx) * sampleCounts[bx]; sel.setLabel(PApplet.round(count) + "/" + sampleCounts[bx]); } else {