void setWithType(int type, int sx, int sy, int c, float p) { switch (type) { case 0: setNorm(sx,sy,c,p); break; case 1: setAdd(sx,sy,c,p); break; case 2: setBruise(sx,sy,c,p); break; default: break; } } void setWithType(int type, float x, float y, int c, float p) { switch (type) { case 0: setNorm(x,y,c,p); break; case 1: setAdd(x,y,c,p); break; case 2: setBruise(x,y,c,p); break; default: break; } } void setNorm(int sx, int sy, int c, float p) { set(sx,sy,colorMixNorm(c,get(sx,sy),p)); } void setNorm(float x, float y, int c, float p) { int x0 = int(floor(x)), x1 = x0+1; int y0 = int(floor(y)), y1 = y0+1; float px1 = x-x0, px0 = 1.0-px1; float py1 = y-y0, py0 = 1.0-py1; float p00 = p*px0*py0; float p10 = p*px1*py0; float p01 = p*px0*py1; float p11 = p*px1*py1; set(x0,y0,colorMixNorm(c,get(x0,y0),p00)); set(x1,y0,colorMixNorm(c,get(x0,y0),p10)); set(x0,y1,colorMixNorm(c,get(x0,y0),p01)); set(x1,y1,colorMixNorm(c,get(x0,y0),p11)); } void setNorm(PImage img, int sx, int sy, int c, float p) { img.set(sx,sy,colorMixNorm(c,img.get(sx,sy),p)); } void setNorm(PImage img, float x, float y, int c, float p) { int x0 = int(floor(x)), x1 = x0+1; int y0 = int(floor(y)), y1 = y0+1; float px1 = x-x0, px0 = 1.0-px1; float py1 = y-y0, py0 = 1.0-py1; float p00 = p*px0*py0; float p10 = p*px1*py0; float p01 = p*px0*py1; float p11 = p*px1*py1; img.set(x0,y0,colorMixNorm(c,img.get(x0,y0),p00)); img.set(x1,y0,colorMixNorm(c,img.get(x0,y0),p10)); img.set(x0,y1,colorMixNorm(c,img.get(x0,y0),p01)); img.set(x1,y1,colorMixNorm(c,img.get(x0,y0),p11)); } void setAdd(int sx, int sy, int c, float p) { set(sx,sy,colorMixAdd(c,get(sx,sy),p)); } void setAdd(float x, float y, int c, float p) { int x0 = int(floor(x)), x1 = x0+1; int y0 = int(floor(y)), y1 = y0+1; float px1 = x-x0, px0 = 1.0-px1; float py1 = y-y0, py0 = 1.0-py1; float p00 = p*px0*py0; float p10 = p*px1*py0; float p01 = p*px0*py1; float p11 = p*px1*py1; set(x0,y0,colorMixAdd(c,get(x0,y0),p00)); set(x1,y0,colorMixAdd(c,get(x0,y0),p10)); set(x0,y1,colorMixAdd(c,get(x0,y0),p01)); set(x1,y1,colorMixAdd(c,get(x0,y0),p11)); } void setAdd(PImage img, int sx, int sy, int c, float p) { img.set(sx,sy,colorMixAdd(c,img.get(sx,sy),p)); } void setAdd(PImage img, float x, float y, int c, float p) { int x0 = int(floor(x)), x1 = x0+1; int y0 = int(floor(y)), y1 = y0+1; float px1 = x-x0, px0 = 1.0-px1; float py1 = y-y0, py0 = 1.0-py1; float p00 = p*px0*py0; float p10 = p*px1*py0; float p01 = p*px0*py1; float p11 = p*px1*py1; img.set(x0,y0,colorMixAdd(c,img.get(x0,y0),p00)); img.set(x1,y0,colorMixAdd(c,img.get(x0,y0),p10)); img.set(x0,y1,colorMixAdd(c,img.get(x0,y0),p01)); img.set(x1,y1,colorMixAdd(c,img.get(x0,y0),p11)); } void setBruise(int sx, int sy, int c, float p) { set(sx,sy,colorMixBruise(c,get(sx,sy),p)); } void setBruise(float x, float y, int c, float p) { int x0 = int(floor(x)), x1 = x0+1; int y0 = int(floor(y)), y1 = y0+1; float px1 = x-x0, px0 = 1.0-px1; float py1 = y-y0, py0 = 1.0-py1; float p00 = p*px0*py0; float p10 = p*px1*py0; float p01 = p*px0*py1; float p11 = p*px1*py1; set(x0,y0,colorMixBruise(c,get(x0,y0),p00)); set(x1,y0,colorMixBruise(c,get(x0,y0),p10)); set(x0,y1,colorMixBruise(c,get(x0,y0),p01)); set(x1,y1,colorMixBruise(c,get(x0,y0),p11)); } void setBruise(PImage img, int sx, int sy, int c, float p) { img.set(sx,sy,colorMixBruise(c,img.get(sx,sy),p)); } void setBruise(PImage img, float x, float y, int c, float p) { int x0 = int(floor(x)), x1 = x0+1; int y0 = int(floor(y)), y1 = y0+1; float px1 = x-x0, px0 = 1.0-px1; float py1 = y-y0, py0 = 1.0-py1; float p00 = p*px0*py0; float p10 = p*px1*py0; float p01 = p*px0*py1; float p11 = p*px1*py1; img.set(x0,y0,colorMixBruise(c,img.get(x0,y0),p00)); img.set(x1,y0,colorMixBruise(c,img.get(x0,y0),p10)); img.set(x0,y1,colorMixBruise(c,img.get(x0,y0),p01)); img.set(x1,y1,colorMixBruise(c,img.get(x0,y0),p11)); } int colorMixNorm(int c1, int c2, float p1) { int r1 = c1>>16&0xFF; int g1 = c1>>8&0xFF; int b1 = c1&0xFF; int r2 = c2>>16&0xFF; int g2 = c2>>8&0xFF; int b2 = c2&0xFF; float p2 = 1.0-p1; int rr = int(r1*p1+r2*p2); int gg = int(g1*p1+g2*p2); int bb = int(b1*p1+b2*p2); return (rr<<16|gg<<8|bb); } int colorMixAdd(int c1, int c2, float p1) { int r1 = c1>>16&0xFF; int g1 = c1>>8&0xFF; int b1 = c1&0xFF; int r2 = c2>>16&0xFF; int g2 = c2>>8&0xFF; int b2 = c2&0xFF; float p2 = 1.0-p1; int rr = r2 + int(r1*p1); int gg = g2 + int(g1*p1); int bb = b2 + int(b1*p1); return (rr<<16|gg<<8|bb); } int colorMixBruise(int c1, int c2, float p1) { int r1 = 255 - (c1>>16&0xFF); int g1 = 255 - (c1>>8&0xFF); int b1 = 255 - (c1&0xFF); int r2 = c2>>16&0xFF; int g2 = c2>>8&0xFF; int b2 = c2&0xFF; float p2 = 1.0-p1; int rr = int(r2-r1*p1); int gg = int(g2-g1*p1); int bb = int(b2-b1*p1); if (rr<0) rr=0; if (gg<0) gg=0; if (bb<0) bb=0; return (rr<<16|gg<<8|bb); }