public final float red(int what) { return g.red(what); }
/** * ( begin auto-generated from red.xml ) * * Extracts the red value from a color, scaled to match current * <b>colorMode()</b>. This value is always returned as a float so be * careful not to assign it to an int value.<br /><br />The red() function * is easy to use and undestand, but is slower than another technique. To * achieve the same results when working in <b>colorMode(RGB, 255)</b>, but * with greater speed, use the >> (right shift) operator with a bit * mask. For example, the following two lines of code are equivalent:<br * /><pre>float r1 = red(myColor);<br />float r2 = myColor >> 16 * & 0xFF;</pre> * * ( end auto-generated ) * * @webref color:creating_reading * @usage web_application * @param rgb any value of the color datatype * @see PGraphics#green(int) * @see PGraphics#blue(int) * @see PGraphics#alpha(int) * @see PGraphics#hue(int) * @see PGraphics#saturation(int) * @see PGraphics#brightness(int) * @see_external rightshift */ public final float red(int rgb) { return g.red(rgb); }
/** * Color distance on the LAB 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 ref * @return */ public static boolean colorFinderLAB(PGraphics g, int incomingPix, ColorReferenceThresholds ref) { double[] lab = converter.RGBtoLAB((int) g.red(incomingPix), (int) g.green(incomingPix), (int) g.blue(incomingPix)); double l = constrain(lab[0], 0, 100); double A = constrain(lab[1], -128, 128); double B = constrain(lab[2], -128, 128); double d = Math.sqrt(Math.pow(l - ref.averageL, 2) + Math.pow(A - ref.averageA, 2) + Math.pow(B - ref.averageB, 2)); // System.out.println("d: " + d); return d < (ref.AThreshold + ref.BThreshold + ref.LThreshold) * 2f; }
/** * Color distance on the LAB 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 LTresh * @param ATresh * @param BTresh * @return */ public static boolean colorFinderLAB(PGraphics g, int baseline, int incomingPix, float LTresh, float ATresh, float BTresh) { double[] labBase = converter.RGBtoLAB((int) g.red(baseline), (int) g.green(baseline), (int) g.blue(baseline)); double[] labIncoming = converter.RGBtoLAB((int) g.red(incomingPix), (int) g.green(incomingPix), (int) g.blue(incomingPix)); return labIncoming[0] > 50.0 // Very large light base // absd(labBase[0] - labIncoming[0]) < LTresh * 20 // Very large light base && absd(labBase[1] - labIncoming[1]) < ATresh && absd(labBase[2] - labIncoming[2]) < BTresh; }
public void draw(PGraphics pg, boolean pdf) { pg.beginDraw(); pg.background(WHITE); if (canDraw()) { pg.noStroke(); float rad = 0; int a; int count = PApplet.min(500, points.size()); rad = PApplet.map(count, 0, 500, 0.05f, 0.01f); a = (int) PApplet.map(count, 0, 500, 70, 10); pg.fill(pg.red(COLOR), pg.green(COLOR), pg.blue(COLOR), a); for (Value2D pt : points) { float px = pg.width * (float) pt.x; float py = pg.height * (float) (1 - pt.y); float pw = pg.width * rad; float ph = pg.height * rad; if (50000 < points.size()) pg.rect(px - pw / 2, py - ph / 2, pw, ph); else pg.ellipse(px, py, pw, ph); } } else { drawCross(pg); } if (pdf) pg.dispose(); pg.endDraw(); }