123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- /*
-
- ASDFPIXELSORT
-
- */
-
- class ASDFPIXELSORT extends Shader {
- ASDFPIXELSORT() {
- name = "fxASDFPixelSort";
- params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- params.add(new Param("target", INTVAL, 0, 2, new int[]{RANDOM}));
- }
- int previousMode;
-
- void apply() {
- if (previousMode != int(params.get(1).value)) {
- if (params.get(1).value == 0) changeParam(0, new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- if (params.get(1).value == 1) changeParam(0, new Param("brightness", INTVAL, 0, 200, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- if (params.get(1).value == 2) changeParam(0, new Param("white", INTVAL, -15000000, -700000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- }
- previousMode = int(params.get(1).value);
- row = 0;
- column = 0;
- renderer.beginDraw();
- renderer.colorMode(RGB);
- colorMode(RGB);
- while (column < renderer.width-1) {
- renderer.loadPixels();
- sortColumn();
- column++;
- renderer.updatePixels();
- }
-
- while (row < renderer.height-1) {
- renderer.loadPixels();
- sortRow();
- row++;
- renderer.updatePixels();
- }
-
- renderer.endDraw();
- }
-
- int row = 0;
- int column = 0;
- void sortRow() {
- int x = 0;
- int y = row;
- int xend = 0;
- while (xend < renderer.width-1) {
- switch((int)params.get(1).value) {
- case 0:
- x = getFirstNotBlackX(x, y);
- xend = getNextBlackX(x, y);
- break;
- case 1:
- x = getFirstBrightX(x, y);
- xend = getNextDarkX(x, y);
- break;
- case 2:
- x = getFirstNotWhiteX(x, y);
- xend = getNextWhiteX(x, y);
- break;
- default:
- break;
- }
-
- if (x < 0) break;
-
- int sortLength = xend-x;
-
- color[] unsorted = new color[sortLength];
- color[] sorted = new color[sortLength];
-
- for (int i=0; i<sortLength; i++) {
- unsorted[i] = renderer.pixels[x + i + y * renderer.width];
- }
-
- sorted = sort(unsorted);
-
- for (int i=0; i<sortLength; i++) {
- renderer.pixels[x + i + y * renderer.width] = sorted[i];
- }
-
- x = xend+1;
- }
- }
-
-
- void sortColumn() {
- int x = column;
- int y = 0;
- int yend = 0;
-
- while (yend < renderer.height-1) {
- switch((int)params.get(1).value) {
- case 0:
- y = getFirstNotBlackY(x, y);
- yend = getNextBlackY(x, y);
- break;
- case 1:
- y = getFirstBrightY(x, y);
- yend = getNextDarkY(x, y);
- break;
- case 2:
- y = getFirstNotWhiteY(x, y);
- yend = getNextWhiteY(x, y);
- break;
- default:
- break;
- }
-
- if (y < 0) break;
-
- int sortLength = yend-y;
- color[] unsorted = new color[sortLength];
- color[] sorted = new color[sortLength];
- for (int i=0; i<sortLength; i++) {
- unsorted[i] = renderer.pixels[x + (y+i) * renderer.width];
- }
-
- sorted = sort(unsorted);
-
-
- for (int i=0; i<sortLength; i++) {
- renderer.pixels[x + (y+i) * renderer.width] = sorted[i];
- }
-
- y = yend+1;
- }
- }
-
-
- //BLACK
- int getFirstNotBlackX(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
- x++;
- if (x >= renderer.width) return -1;
- }
- return x;
- }
-
- int getNextBlackX(int _x, int _y) {
- int x = _x+1;
- int y = _y;
- color c;
- while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
- x++;
- if (x >= renderer.width) return renderer.width-1;
- }
- return x-1;
- }
-
- //BRIGHTNESS
- int getFirstBrightX(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- while (brightness (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
- x++;
- if (x >= renderer.width) return -1;
- }
- return x;
- }
-
- int getNextDarkX(int _x, int _y) {
- int x = _x+1;
- int y = _y;
- color c;
- while (brightness (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
- x++;
- if (x >= renderer.width) return renderer.width-1;
- }
- return x-1;
- }
-
- //WHITE
- int getFirstNotWhiteX(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
- x++;
- if (x >= renderer.width) return -1;
- }
- return x;
- }
-
- int getNextWhiteX(int _x, int _y) {
- int x = _x+1;
- int y = _y;
- color c;
- while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
- x++;
- if (x >= renderer.width) return renderer.width-1;
- }
- return x-1;
- }
-
-
- //BLACK
- int getFirstNotBlackY(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- if (y < renderer.height) {
- while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
- y++;
- if (y >= renderer.height) return -1;
- }
- }
- return y;
- }
-
- int getNextBlackY(int _x, int _y) {
- int x = _x;
- int y = _y+1;
- color c;
- if (y < renderer.height) {
- while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
- y++;
- if (y >= renderer.height) return renderer.height-1;
- }
- }
- return y-1;
- }
-
- //BRIGHTNESS
- int getFirstBrightY(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- if (y < renderer.height) {
- while (brightness (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
- y++;
- if (y >= renderer.height) return -1;
- }
- }
- return y;
- }
-
- int getNextDarkY(int _x, int _y) {
- int x = _x;
- int y = _y+1;
- color c;
- if (y < renderer.height) {
- while (brightness (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
- y++;
- if (y >= renderer.height) return renderer.height-1;
- }
- }
- return y-1;
- }
-
- //WHITE
- int getFirstNotWhiteY(int _x, int _y) {
- int x = _x;
- int y = _y;
- color c;
- if (y < renderer.height) {
- while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
- y++;
- if (y >= renderer.height) return -1;
- }
- }
- return y;
- }
-
- int getNextWhiteY(int _x, int _y) {
- int x = _x;
- int y = _y+1;
- color c;
- if (y < renderer.height) {
- while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
- y++;
- if (y >= renderer.height) return renderer.height-1;
- }
- }
- return y-1;
- }
- }
-
-
- /*
-
- DISTORTER
-
- */
-
- class DISTORTER extends Shader{
- boolean do_blend = false; // blend image after process
- int blend_mode = OVERLAY; // blend type
- int channel = BRIGHTNESS; // channel used in processing (R,G,B) or (H,S,B)
- float scalex = 0.05; // from 0.01 to 1
- float scaley = 0.1; // from 0.01 to 1
- boolean shift_hue = true;
- float shift_amt = 0.1; // from 0 to 1
-
- PImage buffer;
-
-
- int[][] distort = new int[2][512];
- final static float tick = 1.0/512.0;
-
- int mode = 0;
-
- DISTORTER() {
-
- buffer = createImage(renderer.width, renderer.height, ARGB);
- name = "fxDIstorter";
- params.add(new Param("width", FLOATVAL, 1, buffer.width/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- params.add(new Param("height", FLOATVAL, 1, buffer.height/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM,SQUAR}));
- params.add(new Param("shift hue amount", FLOATVAL, 0, 1, new int[]{SAWTOOTH, SAWTOOTHINVERSE, TAN, TANINVERSE, RAMP, RAMPINVERSE}));
- params.add(new Param("scale x", FLOATVAL, 0.01, 1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- params.add(new Param("scale y", FLOATVAL, 0.01, 1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- params.add(new Param("blend mode", INTVAL, 0, 11, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
- params.add(new Param("channel", INTVAL, 0, 12, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
-
- // channel, blend_mode
-
- //params.add(new Param("height", FLOATVAL, 1, buffer.height/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
-
-
- // prepare distortion pattern
- for (int i=0; i<512; i++) {
- distort[0][i] = (int)random(-128, 128);
- distort[1][i] = (int)random(-128, 128);
- }
- }
-
-
- final int[] blends = {
- ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN
- };
-
- // ALL Channels, Nxxx stand for negative (255-value)
- // channels to work with
- final static int RED = 0;
- final static int GREEN = 1;
- final static int BLUE = 2;
- final static int HUE = 3;
- final static int SATURATION = 4;
- final static int BRIGHTNESS = 5;
- final static int NRED = 6;
- final static int NGREEN = 7;
- final static int NBLUE = 8;
- final static int NHUE = 9;
- final static int NSATURATION = 10;
- final static int NBRIGHTNESS = 11;
-
- void apply() {
-
- buffer = renderer.get();
- buffer.resize(renderer.width, renderer.height);
-
- float neww = params.get(0).value;
- float newh = params.get(1).value;
- do_blend = boolean(int(params.get(2).value));
- shift_amt = params.get(3).value;
- scalex = params.get(4).value;
- scaley = params.get(5).value;
- blend_mode = blends[(int)params.get(6).value];
- channel = (int)params.get(7).value;
-
-
- float totalnum = neww+newh;
- float times = (totalnum/floor(totalnum/neww));
- float offx = (totalnum%neww)/times;
- float ratiox = neww/buffer.width;
-
- renderer.beginDraw();
- renderer.colorMode(RGB);
- colorMode(RGB);
- renderer.noStroke();
-
- for (int y=0; y<buffer.height; y++) {
- float yy = y/(float)buffer.height;
- for (int x=0; x<buffer.width; x++) {
- float xx = x/(float)buffer.width;
-
- float offy = floor(newh*yy);
- float fx = xx*ratiox+offx*offy;
-
- float shift = fx%1.0;
- float st = shift/tick;
- int no1 = floor(st)%512;
- int no2 = ceil(st)%512;
- float l = st-(float)no1;
-
- float cx = lerp(distort[0][no1], distort[0][no2], l);
- float cy = lerp(distort[1][no1], distort[1][no2], l);
-
- float rx =getChannel(buffer.get(x, y), channel);
- int sx = (int)((buffer.width+x+cx*rx*scalex*0.1)%buffer.width);
- int sy = (int)((buffer.height+y+cy*scaley)%buffer.height);
-
- color c=buffer.get(sx, sy);
-
- if (shift_hue) {
- colorMode(HSB, 255);
- c = color((hue(c)+shift_amt*255*noise(newh+y))%255.0, constrain(saturation(c)*1.2, 0, 255), constrain(brightness(c), 0, 255));
- colorMode(RGB, 255);
- }
- // buffer.fill(lerpColor(c,img.get(x,y),0.2));
- renderer.fill(c);
- renderer.rect(x, y, 1, 1);
- }
- }
-
- if (do_blend)
- renderer.blend(buffer, 0, 0, buffer.width, buffer.height, 0, 0, renderer.width, renderer.height, blend_mode);
-
- renderer.endDraw();
- }
-
-
-
- float getChannel(color c, int channel) {
- int ch = channel>5?channel-6:channel;
- float cc;
-
- switch(ch) {
- case RED:
- cc = red(c);
- break;
- case GREEN:
- cc = green(c);
- break;
- case BLUE:
- cc = blue(c);
- break;
- case HUE:
- cc = hue(c);
- break;
- case SATURATION:
- cc = saturation(c);
- break;
- default:
- cc= brightness(c);
- break;
- }
-
- return channel>5?255-cc:cc;
- }
-
-
- }
|