public static boolean isRed(PGraphics g, int incomingPix, int baseline, float threshold) { int r1 = incomingPix >> 16 & 255; int r2 = baseline >> 16 & 255; return abs(r1 - r2) < threshold; }
public static boolean isGreen(PGraphics g, int incomingPix, int baseline, int threshold) { int r1 = incomingPix >> 8 & 255; int r2 = baseline >> 8 & 255; return abs(r1 - r2) < threshold; }
public static boolean isBlue(PGraphics g, int incomingPix, int baseline, float threshold) { int r1 = incomingPix >> 0 & 255; int r2 = baseline >> 0 & 255; return abs(r1 - r2) < threshold; }
/** * RGB distance of two colors. Return true if all channels differences are * below the difference threshold. * * @param c1 * @param c2 * @param threshold * @return */ public static boolean colorDistRGB(int c1, int c2, int threshold) { int r1 = c1 >> 16 & 255; int g1 = c1 >> 8 & 255; int b1 = c1 >> 0 & 255; int r2 = c2 >> 16 & 255; int g2 = c2 >> 8 & 255; int b2 = c2 >> 0 & 255; int dr = PApplet.abs(r1 - r2); int dg = PApplet.abs(g1 - g2); int db = PApplet.abs(b1 - b2); return dr < threshold && dg < threshold && db < threshold; }
/** * RGB distance of two colors. Return true if all channels differences are * below the difference threshold. * * @param c1 * @param c2 * @param threshold * @return */ public static boolean colorDistRGBAverage(int c1, int c2, int threshold) { int r1 = c1 >> 16 & 255; int g1 = c1 >> 8 & 255; int b1 = c1 >> 0 & 255; int r2 = c2 >> 16 & 255; int g2 = c2 >> 8 & 255; int b2 = c2 >> 0 & 255; int dr = PApplet.abs(r1 - r2); int dg = PApplet.abs(g1 - g2); int db = PApplet.abs(b1 - b2); return dr + dg + db < threshold; }
/** * RGB distance of two colors. Return true if all channels differences are * below the difference threshold. * * @param c1 * @param c2 * @param tr * @param tg * @param tb * @return */ public static boolean colorDistRGB(int c1, int c2, int tr, int tg, int tb) { int r1 = c1 >> 16 & 255; int g1 = c1 >> 8 & 255; int b1 = c1 >> 0 & 255; int r2 = c2 >> 16 & 255; int g2 = c2 >> 8 & 255; int b2 = c2 >> 0 & 255; int dr = PApplet.abs(r1 - r2); int dg = PApplet.abs(g1 - g2); int db = PApplet.abs(b1 - b2); return dr < tr && dg < tg && db < tb; }
boolean subPixelStroke(float weight) { float sw = transformScale() * weight; return PApplet.abs(sw - (int)sw) > 0; }
boolean subPixelStroke(float weight) { float sw = transformScale() * weight; return PApplet.abs(sw - (int)sw) > 0; }
private void goTo(int idx) { int dif = idx - rowBrowser.current; for (int i = 0; i < PApplet.abs(dif); i++) { if (dif < 0) rowBrowser.prev(false); else rowBrowser.next(false); } } };
public static boolean colorFinderHSBRedish(PGraphics g, int baseline, int incomingPix, float hueTresh, float saturationTresh, float brightnessTresh) { float h1 = g.hue(baseline); float h2 = g.hue(incomingPix); // If the hue is low but still red, shit it. if (h2 < 30) { h2 = h2 + 255f; } return abs(h1 - h2) < hueTresh && // Avoid desaturated pixels abs(g.saturation(incomingPix) - g.saturation(baseline)) < saturationTresh && // avoid pixels not bright enough abs(g.brightness(incomingPix) - g.brightness(baseline)) < brightnessTresh; }
/** * Color distance on the HSB scale. The incomingPix is compared with the * baseline. The method returns true if each channel validates the condition * for the given threshold. * * @param g * @return */ public boolean colorFinderHSB(PGraphics g, int incomingPix) { float h1 = g.hue(referenceColor); float h2 = g.hue(incomingPix); return abs(h1 - h2) < hue && // Avoid desaturated pixels abs(g.saturation(incomingPix) - g.saturation(referenceColor)) < saturation && // avoid pixels not bright enough abs(g.brightness(incomingPix) - g.brightness(referenceColor)) < brightness; }
/** * Warning here, the threshold is the same for each channel. Often the range * depends on the declaration. To change the intensity of each, try to call * HSB(100, 100, 100) for even thresholding or HSB(100, 200, 50) to be less * picky on the brigthness and more picky on the saturation. * * @param g * @param baseline * @param incomingPix * @param threshold * @return */ public static boolean colorDistHSBAutoThresh(PGraphics g, int baseline, int incomingPix, float threshold) { float h1 = g.hue(baseline); float h2 = g.hue(incomingPix); float d1 = abs(h1 - h2); float d2 = abs(g.saturation(baseline) - g.saturation(incomingPix)); float d3 = abs(g.brightness(baseline) - g.brightness(incomingPix)); return (d1 + d2 + d3) < (threshold * 3); }
/** * Color distance on the HSB scale. The incomingPix is compared with the * baseline. The method returns true if each channel validates the condition * for the given threshold. * * @param g * @param baseline * @param incomingPix * @param hueTresh * @param saturationTresh * @param brightnessTresh * @return */ public static boolean colorDistHSB(PGraphics g, int baseline, int incomingPix, float hueTresh, float saturationTresh, float brightnessTresh) { float h1 = g.hue(baseline); float h2 = g.hue(incomingPix); return abs(h1 - h2) < hueTresh && // Avoid desaturated pixels abs(g.saturation(incomingPix) - g.saturation(baseline)) > saturationTresh && // avoid pixels not bright enough abs(g.brightness(incomingPix) - g.brightness(baseline)) > brightnessTresh; }
public void snap() { if (0 < children.size()) { float offset = 0; MiraWidget first = (MiraWidget)children.get(0); MiraWidget last = (MiraWidget)children.get(children.size() - 1); float h = PApplet.min(height, getTotalHeight()); if (PApplet.abs(first.targetY()) < 30) { offset = -first.targetY(); } else if (PApplet.abs(first.targetY() + first.targetHeight()) < snapThreshold) { offset = -(first.targetY() + first.targetHeight()); } else if (PApplet.abs(last.targetY() - h) < 30) { offset = h - last.targetY(); } else if (PApplet.abs(last.targetY() + last.targetHeight() - h) < snapThreshold) { offset = h - (last.targetY() + last.targetHeight()); } if (0 != offset) { for (Widget child: children) { float y = child.targetY(); y += offset; child.targetY(y); } } } }
public void snap() { if (getItemCount() == 0) return; float vis0 = visPos0.getTarget(); float vis1 = visPos1.getTarget(); int i0 = getCloserIndex(vis0); int i1 = getCloserIndex(vis1); float pos0 = getItemPos(i0); float pos1 = getItemPos(i1); if (PApplet.abs(pos0 - vis0) < SNAP_THRESHOLD) { visPos0.setTarget(pos0); } else if (PApplet.abs(pos1 - vis1) < SNAP_THRESHOLD) { visPos1.setTarget(pos1); } }
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); } }
public boolean visible() { if (isTransparent() || bounds.zero()) { return false; } else { float[] ipx = intersect(left(), right(), intf.left(), intf.right()); float[] ipy = intersect(top(), bottom(), intf.top(), intf.bottom()); return ipx != null && PApplet.abs(ipx[1] - ipx[0]) > 0 && ipy != null && PApplet.abs(ipy[1] - ipy[0]) > 0; } }