/* Webcam */ boolean webcamRunning; void startWebcam() { String[] cameras = Capture.list(); println("Hi"); println(cameras); cam.start(); webcamRunning = true; } void stopWebcam() { cam.stop(); webcamRunning = false; } class WEBCAM extends Shader { PImage img; int rw, rh, x, y, w, h, croptop, cropbottom, cropleft, cropright, contrast, brightness, hue, saturation; final int[] blends = {BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN}; WEBCAM() { rw = canvas.width; rh = canvas.height; name = "Webcam"; img = createImage(rw, rh, ARGB); if (!webcamRunning) startWebcam(); //params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("x", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN, })); params.add(new Param("y", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("w", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("h", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("croptop", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("cropbottom", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("cropleft", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("cropright", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("contrast", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("brightness", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("hue", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("saturation", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param("blend mode", INTVAL, 0, this.blends.length-1, new int[]{RANDOM })); } void apply() { rw = canvas.width; rh = canvas.height; x = int(params.get(0).value*rw); y = int(params.get(1).value*rh); w = int(params.get(2).value*(rw*2)); h = int(params.get(3).value*(rh*2)); if(cam.available()) img = cam.get(); img = webcamImg.get(); canvas.beginDraw(); canvas.image(img, x, y, w, h); //for ( int i = 0, l = canvas.pixels.length; i= canvas.width) return -1; } return x; } int getNextBlackX(int _x, int _y) { int x = _x+1; int y = _y; color c; while ( (c = canvas.pixels[x + y * canvas.width]) > params.get(0).value) { x++; if (x >= canvas.width) return canvas.width-1; } return x-1; } //BRIGHTNESS int getFirstBrightX(int _x, int _y) { int x = _x; int y = _y; color c; while (brightness (c = canvas.pixels[x + y * canvas.width]) < params.get(0).value) { x++; if (x >= canvas.width) return -1; } return x; } int getNextDarkX(int _x, int _y) { int x = _x+1; int y = _y; color c; while (brightness (c = canvas.pixels[x + y * canvas.width]) > params.get(0).value) { x++; if (x >= canvas.width) return canvas.width-1; } return x-1; } //WHITE int getFirstNotWhiteX(int _x, int _y) { int x = _x; int y = _y; color c; while ( (c = canvas.pixels[x + y * canvas.width]) > params.get(0).value) { x++; if (x >= canvas.width) return -1; } return x; } int getNextWhiteX(int _x, int _y) { int x = _x+1; int y = _y; color c; while ( (c = canvas.pixels[x + y * canvas.width]) < params.get(0).value) { x++; if (x >= canvas.width) return canvas.width-1; } return x-1; } //BLACK int getFirstNotBlackY(int _x, int _y) { int x = _x; int y = _y; color c; if (y < canvas.height) { while ( (c = canvas.pixels[x + y * canvas.width]) < params.get(0).value) { y++; if (y >= canvas.height) return -1; } } return y; } int getNextBlackY(int _x, int _y) { int x = _x; int y = _y+1; color c; if (y < canvas.height) { while ( (c = canvas.pixels[x + y * canvas.width]) > params.get(0).value) { y++; if (y >= canvas.height) return canvas.height-1; } } return y-1; } //BRIGHTNESS int getFirstBrightY(int _x, int _y) { int x = _x; int y = _y; color c; if (y < canvas.height) { while (brightness (c = canvas.pixels[x + y * canvas.width]) < params.get(0).value) { y++; if (y >= canvas.height) return -1; } } return y; } int getNextDarkY(int _x, int _y) { int x = _x; int y = _y+1; color c; if (y < canvas.height) { while (brightness (c = canvas.pixels[x + y * canvas.width]) > params.get(0).value) { y++; if (y >= canvas.height) return canvas.height-1; } } return y-1; } //WHITE int getFirstNotWhiteY(int _x, int _y) { int x = _x; int y = _y; color c; if (y < canvas.height) { while ( (c = canvas.pixels[x + y * canvas.width]) > params.get(0).value) { y++; if (y >= canvas.height) return -1; } } return y; } int getNextWhiteY(int _x, int _y) { int x = _x; int y = _y+1; color c; if (y < canvas.height) { while ( (c = canvas.pixels[x + y * canvas.width]) < params.get(0).value) { y++; if (y >= canvas.height) return canvas.height-1; } } return y-1; } } /* DISTORTER by Tomasz Sulej */ 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; final static int distortionMatrixSize = 512; //doesnt really make a difference, it's more or less "noise variety".. only kinda different if real low, like 2 or so int[][] distort = new int[2][distortionMatrixSize]; final static float tick = 1.0/distortionMatrixSize; int mode = 0; int initBufferW, initBufferH; DISTORTER() { buffer = createImage(canvas.width, canvas.height, ARGB); initBufferW = buffer.width; initBufferH = buffer.height; name = "fxDistorter"; params.add(new Param("width", FLOATVAL, 2, buffer.width/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG})); params.add(new Param("height", FLOATVAL, 2, 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, blends.length-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG})); params.add(new Param("channel", INTVAL, 0, 12, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 8; //params.add(new Param(DIRECTION)); // 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; i5?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; } } /* FM */ class FM extends Shader { // configuration int colorspace = RGB; int quantval = 30; // 0 - off, less - more glitch, more - more precision boolean do_blend = true; // blend image after process int blend_mode = OVERLAY; // blend type //unused parameters (giers): final static boolean first_channel_only = false; // for L.. or Y.. colorspaces set true to modulate only luma; final static boolean lowpass1_on = true; // on/off of first low pass filter final static boolean lowpass2_on = true; // on/off of second low pass filter final static boolean lowpass3_on = true; // on/off of third low pass filter // better don't touch it, lowpass filters are run in cascade float lowpass1_cutoff = 0.25; // percentage of rate float lowpass2_cutoff = 0.1; float lowpass3_cutoff = 0.05; // working buffer PGraphics buffer; // local variables float min_omega, max_omega; float min_phase_mult=0.05; float max_phase_mult=50.0; LowpassFilter lpf1, lpf2, lpf3; int[][] pxls; boolean negate = false; FM() { name = "fxFM"; params.add(new Param ("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param ("blend_mode", INTVAL, 0, blends.length-1, new int[]{RANDOM})); params.add(new Param ("omega", FLOATVAL, 0, 1, new int[]{SINE, SAWTOOTH, TRIANG})); params.add(new Param ("phase", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("colorspace", INTVAL, 0, 16, new int[]{RANDOM})); params.add(new Param ("quant", INTVAL, 0, 40, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 6; buffer = createGraphics(canvas.width, canvas.height); buffer.beginDraw(); buffer.noStroke(); //buffer.smooth(8); //buffer.background(0); // buffer.image(canvas, 0, 0); buffer.endDraw(); float rate = 100000.0; lpf1 = new LowpassFilter(rate, lowpass1_cutoff*rate); lpf2 = new LowpassFilter(rate, lowpass2_cutoff*rate); lpf3 = new LowpassFilter(rate, lowpass3_cutoff*rate); //img.loadPixels(); } void prepareData() { pxls = new int[3][canvas.pixels.length]; for (int i=0; i> 16) & 0xff; pxls[1][i] = (cl >> 8) & 0xff; pxls[2][i] = (cl) & 0xff; } } float omega, min_phase, max_phase; int rw, rh; void apply() { buffer.setSize(canvas.width, canvas.height); min_omega = TWO_PI/(0.05*canvas.width); max_omega = TWO_PI/(300.0*canvas.width); rw = canvas.width; do_blend = boolean(int(params.get(0).value)); blend_mode = blends[(int)params.get(1).value]; omega = map(sqrt(params.get(2).value), 0, 1, min_omega, max_omega); float phase = map(sq(params.get(3).value), 0, 1, min_phase_mult, max_phase_mult); colorspace = (int)params.get(4).value; quantval = (int) params.get(5).value; if (rw != canvas.width || rh != canvas.height) { rw = canvas.width; rh = canvas.height; min_omega = TWO_PI/(0.05*canvas.width); max_omega = TWO_PI/(300.0*canvas.width); } prepareData(); //buffer = canvas.get(0, 0, canvas.width, canvas.height); max_phase = phase * omega; min_phase = -max_phase; processImage(); } void processImage() { buffer.beginDraw(); buffer.loadPixels(); int [][] dest_pxls = new int[3][canvas.pixels.length]; if (first_channel_only) { arrayCopy(pxls[1], dest_pxls[1]); arrayCopy(pxls[2], dest_pxls[2]); } for (int i=0; i< (first_channel_only?1:3); i++) { for (int y=0; y 0) { m = map((int)map(m, -1, 1, 0, quantval), 0, quantval, -1, 1); // quantize } float dem = abs(m-pre_m); // demodulate signal, derivative pre_m = m; // remember current value // lowpass filter chain if (lowpass1_on) dem = lpf1.lowpass(dem); if (lowpass2_on) dem = lpf2.lowpass(dem); if (lowpass3_on) dem = lpf3.lowpass(dem); // remap signal back to channel value int v = constrain( (int)map(2*(dem-omega), min_phase, max_phase, 0, 255), 0, 255); ////////////////////// // FM part ends here ////////////////////// dest_pxls[i][x+off] = negate?255-v:v; } } } for (int i=0; i127?hue(c)-256:hue(c); g = saturation(c)>127?saturation(c)-256:saturation(c); b = brightness(c)>127?brightness(c)-256:brightness(c); } else { r = red(c)>127?red(c)-256:red(c); g = green(c)>127?green(c)-256:green(c); b = blue(c)>127?blue(c)-256:blue(c); } raw[iter++] = r; raw[iter++] = g; raw[iter++] = b; raw1[iter2] = r; raw2[iter2] = g; raw3[iter2] = b; iter2++; } } n = (int)pow(2, ceil(log(s*3)/log(2))); n2 = (int)pow(2, ceil(log(s)/log(2))); in = new float[n]; w = new float[n]; out = new float[n]; out1 = new float[n2]; out2 = new float[n2]; out3 = new float[n2]; in1 = new float[n2]; in2 = new float[n2]; in3 = new float[n2]; arrayCopy(raw, 0, in, 0, raw.length); for (int i=raw.length; i0) { for (int i=0; i0) w[n-1] = (int)(w[n-1]/scalingfactorin+0.5); else w[n-1] = (int)(w[n-1]/scalingfactorin-0.5); } } /* AUECHO */ class AUECHO extends Shader { final int[] blends = {BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN}; AUECHO() { name = "fxAUecho"; params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param ("echo", FLOATVAL, 0.001, 1, new int[]{TRIANG, SINE, RAMPUPDOWN, })); params.add(new Param ("decay", FLOATVAL, 0.001, 1, new int[]{TRIANG, SINE, RAMPUPDOWN })); params.add(new Param ("blend mode", INTVAL, 0, this.blends.length-1, new int[]{RANDOM })); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 4; } void apply() { canvas.beginDraw(); if (boolean((int)params.get(0).value)) { canvas.colorMode(HSB); colorMode(HSB); } else { canvas.colorMode(RGB); colorMode(RGB); } canvas.loadPixels(); float _delay = params.get(1).value; float decay = params.get(2).value; int delay = (int)(canvas.pixels.length * _delay); color[] history = new color[canvas.pixels.length]; int blendMode =this.blends[(int)params.get(3).value]; for ( int i = 0, l = canvas.pixels.length; i 255 ? r + red(origColor) - 255 : r + red(origColor), // simulate overflow ;) g = g + green(origColor) > 255 ? g + green(origColor) - 255 : g + green(origColor), b = b + blue(origColor) > 255 ? b + blue(origColor) - 255 : b + blue(origColor) ); //canvas.pixels[i] = history[i] = toColor; canvas.pixels[i] = history[i] = blendColor(origColor, toColor, blendMode); } canvas.updatePixels(); if (boolean((int)params.get(0).value)) { canvas.colorMode(RGB); colorMode(RGB); } canvas.endDraw(); } } /* SLITSCAN */ class SLITSCAN extends Shader { int[] fx; int[] fy; float[] phx; float[] phy; int[] sx, sy; boolean[] skipfx; boolean[] skipfy; boolean dox, doy; PImage buffer; float[][] ft = new float[2][32]; //int depth; // number of octaves int fxnum; int fynum; SLITSCAN() { name = "fxSlitSscan"; buffer = createImage(canvas.width, canvas.height, ARGB); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 0; int s = (int)(log(min(buffer.width, buffer.height))/log(2)); olds = s; params.add(new Param("x num", INTVAL, 1, s, new int[]{RANDOM})); params.add(new Param("y num", INTVAL, 1, s, new int[]{RANDOM})); for (int i=0; i<32; i++) { ft[0][i] = pow(2.0, i); ft[1][i] = 0.5*1.0/ft[0][i]; } } int olds, oldfxnum, oldfynum; void apply() { canvas.beginDraw(); canvas.colorMode(RGB); canvas.noStroke(); colorMode(RGB); canvas.fill(255); buffer.resize(canvas.width, canvas.height); buffer = canvas.get(0, 0, canvas.width, canvas.height); //int s = buffer.width>buffer.height?buffer.height:buffer.width; //int s = min(buffer.width, buffer.height); //depth = (int)(log(s)/log(2)); int s = (int)(log(min(buffer.width, buffer.height))/log(2)); if (olds != s) { olds = s; changeParam(1, new Param("x num", INTVAL, 1, s, new int[]{RANDOM})); changeParam(2, new Param("y num", INTVAL, 1, s, new int[]{RANDOM})); } //depth = (int)params.get(1).value; //println(depth); fxnum = (int)random(params.get(1).value); fynum = (int)random(params.get(2).value); fx = new int[fxnum+1]; fy = new int[fynum+1]; sx = new int[fxnum+1]; sy = new int[fynum+1]; phx = new float[fxnum+1]; phy = new float[fynum+1]; skipfx = new boolean[fxnum+1]; skipfy = new boolean[fynum+1]; for (int i=0; i thresh/h) { bright -= darken/h; constrain(bright, 0, 255); } color c = color(hue, sat, bright); canvas.pixels[i] = c; } } } else if (mode == 1) { for (int h = 1; h < count+1; h++) { for (int i = 0; i < canvas.width*canvas.height; i++) { float hue = hue(canvas.pixels[i]); float sat = saturation(canvas.pixels[i]); float bright = brightness(canvas.pixels[i]); if (bright < thresh/h) { bright -= darken/h; constrain(bright, 0, 255); } color c = color(hue, sat, bright); canvas.pixels[i] = c; } } } canvas.updatePixels(); canvas.endDraw(); colorMode(RGB); } } /* BRIGHTER */ class BRIGHTER extends Shader { float thresh = 120; float thresh2 = 150; float brighten = 180; float speed; BRIGHTER() { name = "fxBrighter"; params.add(new Param("threshold", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("threshold 2", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("brighten", INTVAL, 0, 255, new int[]{TRIANG, SINE, RAMPUPDOWN })); } void apply() { brighten = int(params.get(2).value); thresh2 = int(params.get(1).value); thresh = int(params.get(0).value); canvas.beginDraw(); canvas.colorMode(HSB); colorMode(HSB); canvas.loadPixels(); for (int i = 0; i < canvas.width*canvas.height; i++) { float hue = hue(canvas.pixels[i]); float sat = saturation(canvas.pixels[i]); float bright = brightness(canvas.pixels[i]); if (bright < thresh && bright > thresh2) { bright += brighten; constrain(bright, 0, 255); } color c = color(hue, sat, bright); canvas.pixels[i] = c; } canvas.colorMode(RGB); canvas.updatePixels(); canvas.endDraw(); colorMode(RGB); } } /* AMPLIFY */ //13 class AMPLIFY extends Shader { int spawnT; float h, s, b; AMPLIFY() { name = "fxAmplify"; params.add(new Param("hue / red", FLOATVAL, -255, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("saturation / green", FLOATVAL, -255, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("brightness / blue", FLOATVAL, -255, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("RGB / HSB", INTVAL, 0, 1, new int[]{SQUAR, RANDOM})); } void apply() { canvas.beginDraw(); if (params.get(3).value > 0) colorMode(HSB); else { colorMode(RGB); } canvas.loadPixels(); for (int i = 0; i < canvas.width*canvas.height; i++) { float h = hue(canvas.pixels[i]); float s = saturation(canvas.pixels[i]); float b = brightness(canvas.pixels[i]); canvas.pixels[i] = color(h+params.get(0).value, s+params.get(1).value, b+params.get(2).value); } canvas.updatePixels(); canvas.endDraw(); colorMode(RGB); } } /* BROKENCOLORROT */ class BROKENCOLORROT extends Shader { int spawnT; float h, s, b; BROKENCOLORROT() { name = "fxBrokenColorRot"; params.add(new Param("hue", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("saturation", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("brightness", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("mode", INTVAL, 0, 1, new int[]{SQUAR, RANDOM})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 4; } void apply() { canvas.beginDraw(); if (params.get(3).value > 0) colorMode(HSB); else { colorMode(RGB); } canvas.loadPixels(); float h = params.get(0).value; float s = params.get(1).value; float b = params.get(2).value; for (int i = 0; i < canvas.width*canvas.height; i++) { h = hue(canvas.pixels[i])+h; if (h > 255) h -= 255; s = saturation(canvas.pixels[i])+s; if (s > 255) s -= 255; b = brightness(canvas.pixels[i])+b; if (b > 255) b -= 255; canvas.pixels[i] = color(h, s, b); } canvas.updatePixels(); canvas.endDraw(); colorMode(RGB); } } /* POSTERIZE */ class POSTER extends Shader { int levels = 2; POSTER() { name = "fxPosterize"; params.add(new Param("levels", INTVAL, 2, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); } void apply() { levels = (int)params.get(0).value; canvas.beginDraw(); canvas.filter(POSTERIZE, levels); canvas.endDraw(); } } /* DUAL */ class DUAL extends Shader { PImage buffer; int dualColor; int dirx = 1; int diry = 1; DUAL() { name = "fxDual"; params.add(new Param("dual color", INTVAL, 2000000, 15000000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("flip direction", INTVAL, 0, 3, new int[]{RANDOM})); params.add(new Param("mode", INTVAL, 0, 1, new int[]{SQUAR, RANDOM})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 3; buffer = createImage(canvas.width, canvas.height, ARGB); } void apply() { switch((int)params.get(1).value) { case(0): dirx = 1; diry = 1; break; case(1): dirx = -1; diry = 1; break; case(2): dirx = 1; diry = -1; break; case(3): dirx = -1; diry = -1; break; } dualColor = (int)params.get(0).value; buffer.resize(canvas.width, canvas.height); canvas.beginDraw(); canvas.imageMode(CORNER); canvas.loadPixels(); buffer.loadPixels(); if ((int)params.get(2).value > 0) { for (int i = 0; i < canvas.width*canvas.height; i++) { buffer.pixels[i] = canvas.pixels[i]+dualColor; } } else { for (int i = 0; i < canvas.width*canvas.height; i++) { buffer.pixels[i] = canvas.pixels[i]+dualColor; buffer.pixels[i] = buffer.pixels[i]+i/10; } } buffer.updatePixels(); canvas.updatePixels(); canvas.pushMatrix(); canvas.scale(dirx, diry); canvas.image(buffer, 0, 0, dirx * canvas.width, diry * canvas.height); canvas.popMatrix(); canvas.endDraw(); } } /* GRAUZONE */ class GRAUZONE extends Shader { int nFrames = 20; int iWrite = 0, iRead = 1; PImage[] buffer; PGraphics grauz; GRAUZONE() { name = "fxGrauzone"; params.add(new Param("delay (in frames)", INTVAL, 3, 100, new int[]{RANDOM})); nFrames = (int)params.get(0).value; buffer = new PImage[nFrames]; } int nFramesPrev; void apply() { nFramesPrev = nFrames; if (nFramesPrev != (int)params.get(0).value) { iWrite = 0; iRead = 1; int nFramesOld = nFrames; nFrames = (int)params.get(0).value; if (nFrames > nFramesOld) { buffer = new PImage[nFrames]; } } buffer[iWrite] = canvas.get(); grauz = createGraphics(canvas.width, canvas.height); grauz.beginDraw(); // grauz.resize(canvas.width, canvas.height); buffer[iWrite] = canvas.get(); if (buffer[iRead] != null) { grauz.tint(255, 127); buffer[iRead].filter(INVERT); grauz.image(buffer[iRead], 0, 0, canvas.width, canvas.height); grauz.tint(255, 255); } grauz.endDraw(); canvas.beginDraw(); canvas.imageMode(CORNER); canvas.image(grauz, 0, 0, canvas.width, canvas.height); canvas.endDraw(); iWrite++; iRead++; if (iRead >= nFrames-1) { iRead = 0; } if (iWrite >= nFrames-1) { iWrite = 0; } } } /* COPYZOOM */ class COPYZOOM extends Shader { int coprx, copry, coprw, coprh; PImage buffer; COPYZOOM() { name = "fxCopyZoom"; params.add(new Param("w", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("h", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("x", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("y", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); buffer = createImage(canvas.width, canvas.height, ARGB); } void apply() { canvas.imageMode(CORNER); if (buffer.width != canvas.width || buffer.height != canvas.height) buffer.resize(canvas.width, canvas.height); buffer = canvas.get(); coprw = int(map(params.get(0).value, 0, 1, 1, canvas.width)); coprh = int(map(params.get(1).value, 0, 1, 1, canvas.height)); coprx = int(map(params.get(2).value, 0, 1, 0, canvas.width-coprw)); copry = int(map(params.get(3).value, 0, 1, 0, canvas.height-coprh)); canvas.beginDraw(); buffer.copy(coprx, copry, coprw, coprh, 0, 0, canvas.width, canvas.height); canvas.image(buffer, 0, 0, canvas.width, canvas.height); canvas.endDraw(); } } /* SUBTLESORT */ class SUBTLESORT extends Shader { int direction = 0; int mode = 0; int c; //int count = int(random(777)); color col; 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; // channels for depth: RED, GREEN, BLUE, HUE, SATURATION, BRIGHTNESS, NRED, NGREEN, NBLUE, NHUE, NSATURATION, NBRIGHTNESS. int channel = BRIGHTNESS; // channel weight. float channel_weight = .2; // SUBTLESORT() { name ="fxSubtleSort"; params.add(new Param ("channel weight", FLOATVAL, 0.001, 20, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("channel", INTVAL, 0, 6, new int[]{RANDOM})); //params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); params.add(new Param("mode", INTVAL, 0, 1, new int[]{SQUARE, RANDOM})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 3; } void apply() { channel_weight = map(renderSize, 4, 15000, 0, 1.5)*params.get(0).value; channel = (int)params.get(1).value; direction = (int)params.get(2).value; mode = (int)params.get(3).value; canvas.beginDraw(); canvas.noStroke(); //if (direction == 0) { for (int i = 0; i < canvas.width; i++) { for (int j = 0; j < canvas.height; j++) { c = i+(j*canvas.width); col = canvas.pixels[c]; canvas.fill(col); canvas.rect(i, j+(getChannel(col)), 1, getChannel(col)); } } //} /*else if (direction == 1) { for (int i = 0; i < canvas.width; i++) { for (int j = 0; j < canvas.height; j++) { c = i+(j*canvas.width); col = canvas.pixels[c]; canvas.fill(col); canvas.rect(i, j-(getChannel(col)*mode), 1, -getChannel(col)); } } } else if (direction == 2) { for (int i = 0; i < canvas.width; i++) { for (int j = 0; j < canvas.height; j++) { c = i+(j*canvas.width); col = canvas.pixels[c]; canvas.fill(col); canvas.rect(i-(getChannel(col)*mode), j, -getChannel(col), 1); } } } else if (direction == 3) { for (int i = 0; i < canvas.width; i++) { for (int j = 0; j < canvas.height; j++) { c = i+(j*canvas.width); col = canvas.pixels[c]; canvas.fill(col); canvas.rect(i+(getChannel(col)), j, getChannel(col), 1); } } }*/ canvas.endDraw(); } float getChannel(color c) { int ch = 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_weight * (channel>5?255-cc:cc); } } /* SCANKER */ class SCANKER extends Shader { int mode; SCANKER() { name = "fxScanker"; params.add(new Param ("detail level 1", FLOATVAL, 0.001, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("detail level 2", FLOATVAL, -50, 50, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("detail level 3", FLOATVAL, -5, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 4; } void apply() { mode = (int)params.get(3).value; canvas.beginDraw(); canvas.loadPixels(); float factor = params.get(0).value + params.get(1).value + params.get(2).value; if (mode == 0) { for (int i = 0; i < canvas.width*canvas.height; i++) { // canvas.pixels[i] = canvas.pixels[i]+((i/1000)*scankMulti); canvas.pixels[i] = canvas.pixels[i]-int(map(i, 0, canvas.width*canvas.height, 0, source.width*source.height)/10*factor); } } else if (mode == 1) { for (int i = 0; i < canvas.width*canvas.height; i++) { // canvas.pixels[i] = canvas.pixels[i]+((i/1000)*scankMulti); canvas.pixels[i] = canvas.pixels[i]+int(map(i, 0, canvas.width*canvas.height, 0, source.width*source.height)/10*factor); } } canvas.updatePixels(); canvas.endDraw(); } } /* MASK */ class MASK extends Shader { int backgroundLayer, maskLayer, bandwidth, val, chan, shaderListLength, invert, blend_mode; boolean do_blend; PImage mask; PImage background; PImage foreground; MASK() { name = "mask"; shaderListLength = gui.shaderList.size(); params.add(new Param("target layer", INTVAL, 0, shaderListLength-2, new int[]{RANDOM})); params.add(new Param("mask layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM})); params.add(new Param("invert", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("bandwidth", INTVAL, 0, 255, new int[]{TRIANG, SINE})); params.add(new Param("value", INTVAL, 1, 255, new int[]{TRIANG, SINE})); params.add(new Param("channel (R/G/B/H/S/V", INTVAL, 0, 5, new int[]{RANDOM})); params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM})); params.add(new Param("blend mode", INTVAL, 0, blends.length-1, new int[]{RANDOM})); background = createImage(canvas.width, canvas.height, ARGB); mask = createImage(canvas.width, canvas.height, ARGB); foreground = createImage(canvas.width, canvas.height, ARGB); } void apply() { if (shaderListLength != gui.shaderList.size()) { shaderListLength = gui.shaderList.size(); changeParam(0, new Param("target layer", INTVAL, 0, shaderListLength-2, new int[]{RANDOM})); changeParam(1, new Param("mask layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM})); } if (mask.width != canvas.width || mask.height != canvas.height) mask.resize(canvas.width, canvas.height); if (background.width != canvas.width || background.height != canvas.height) background.resize(canvas.width, canvas.height); if (foreground.width != canvas.width || foreground.height != canvas.height) foreground.resize(canvas.width, canvas.height); backgroundLayer = (int)params.get(0).value; maskLayer = (int)params.get(1).value; invert = (int)params.get(2).value; bandwidth = (int)params.get(3).value; val = (int)params.get(4).value; chan = (int)params.get(5).value; do_blend = boolean((int)params.get(6).value); blend_mode = blends[(int)params.get(7).value]; if (backgroundLayer <= 0) { background.resize(source.width, source.height); background = source.get(); background.resize(canvas.width, canvas.height); } else background = gui.shaderList.get(backgroundLayer-1).result.get(); if (maskLayer <= 0) { mask.resize(source.width, source.height); mask = source.get(); mask.resize(canvas.width, canvas.height); } else mask = gui.shaderList.get(maskLayer-1).result.get(); canvas.beginDraw(); canvas.imageMode(CORNER); mask.loadPixels(); foreground.loadPixels(); canvas.loadPixels(); if (boolean(invert)) { for (int i = 0; i < canvas.width * canvas.height; i++) { if (!thresh(color(mask.pixels[i]))) foreground.pixels[i] = canvas.pixels[i]; else foreground.pixels[i] = background.pixels[i]; } } else { for (int i = 0; i < canvas.width * canvas.height; i++) { if (thresh(color(mask.pixels[i]))) foreground.pixels[i] = canvas.pixels[i]; else foreground.pixels[i] = background.pixels[i]; } } canvas.updatePixels(); foreground.updatePixels(); mask.updatePixels(); if (do_blend) canvas.blend(foreground, 0, 0, foreground.width, foreground.height, 0, 0, canvas.width, canvas.height, blend_mode); else canvas.image(foreground, 0, 0, canvas.width, canvas.height); canvas.endDraw(); } boolean thresh(color c) { switch(chan) { case(0): if (red(c) > val - bandwidth && red(c) < val + bandwidth) return(true); else return(false); case(1): if (green(c) > val - bandwidth && green(c) < val + bandwidth) return(true); else return(false); case(2): if (blue(c) > val - bandwidth && blue(c) < val + bandwidth) return(true); else return(false); case(3): if (hue(c) > val - bandwidth && hue(c) < val + bandwidth) return(true); else return(false); case(4): if (saturation(c) > val - bandwidth && saturation(c) < val + bandwidth) return(true); else return(false); case(5): if (brightness(c) > val - bandwidth && brightness(c) < val + bandwidth) return(true); else return(false); } return(false); } } class DRAWSTROKES extends Shader { int stat_type = ABSDIST2; // type of diff calculation: fast: ABSDIST, DIST, slow: HUE, SATURATION, BRIGHTNESS int stroke_len = 3; // length of the stroke, values: 1 and above int angles_no = 30; // number of directions stroke can be drew, 2 and above int segments = 500; // number of segments of single thread float stroke_width = 1; // width of the stroke, 0.5 - 3 int stroke_alpha = 100; // alpha channel of the stroke: 30 - 200 color background_color = color(255, 255, 255); // RGB boolean interactive = false; int max_display_size = 800; // viewing window size (regardless image size) int len; // working buffer PGraphics buffer; int currx, curry; int[] sintab, costab; int sqwidth; int iterations; int calcDiff(PImage img1, PImage img2) { int err = 0; for (int i=0; i 0) { // take end points int nx = currx + costab[i]; int ny = curry + sintab[i]; // if not out of the screen if (nx>=0 && nx=0 && nylen) { frameCount=0; //println("iteration: " + tick++); for (int i=0; i5?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; } } /* PIXELDRIFTER */ class PIXELDRIFTER extends Shader { int channel = HUE; // channel data used for shift float channel_off = 60; // channel value offset int iteration_no = 50; // number of iterations 1-100 int max_iter = iteration_no; int direction = UP; // UP, DOWN, LEFT, RIGHT boolean automate_channel_offset = false; // if true, change channel_offset every iteration float scale = 0.03; // 0.01 - 0.1, step size (0.01: 2px, 0.1:25px) float feedback = 0.9; // 0.9 - 0.999 ; blend ratio with original image boolean do_blend = false; // blend image after process int blend_mode = OVERLAY; // blend type // working buffer PGraphics buffer; // image PImage imgb; PImage img; String sessionid; float acho_step; int rw, rh; PIXELDRIFTER() { name = "fxPixelDrifter"; params.add(new Param ("channel offset", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("iterations", INTVAL, 1, 100, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("step size", FLOATVAL, 0.01, 0.1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("feedback", FLOATVAL, 0.1, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("direction", INTVAL, 37, 40, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param ("blend mode", INTVAL, 0, blends.length-1, new int[]{RANDOM})); params.add(new Param ("channel", INTVAL, 0, 1, new int[]{SQUAR, RANDOM})); params.add(new Param ("automate channel offset", INTVAL, 0, 1, new int[]{SQUAR, RANDOM})); rw = canvas.width; rh = canvas.height; img = createImage(rw, rh, ARGB); buffer = createGraphics(rw, rh); buffer.beginDraw(); buffer.noStroke(); buffer.smooth(8); buffer.background(0); buffer.image(img, 0, 0); buffer.endDraw(); scale = abs(scale); } void apply() { if (rw != canvas.width || rh != canvas.height) { rw = canvas.width; rh = canvas.height; img.resize(rw, rh); buffer = createGraphics(rw, rh); } channel_off = map(params.get(0).value, 0, 1, 10, max(rw, rh)); iteration_no = (int)params.get(1).value; scale = params.get(2).value; feedback = params.get(3).value; direction = (int)params.get(4).value; do_blend = boolean((int)params.get(5).value); blend_mode = blends[(int)params.get(6).value]; channel = (int)params.get(7).value == 1 ? HUE : RGB; automate_channel_offset = boolean((int)params.get(8).value); acho_step = 256.0 / iteration_no; img = canvas.get(); // if (iteration_no>0) { for (int i = 0; i < iteration_no; i++) { processImage(); } //iteration_no--; //iteration_no=(iteration_no==0)?max_iter:iteration_no; // if (iteration_no == 0) // iteration_no = 50; // } // } else { canvas.beginDraw(); if (do_blend) { canvas.blend(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height, blend_mode); } else { canvas.image(buffer, canvas.width/2, canvas.height/2, canvas.width, canvas.height); } canvas.endDraw(); // canvas.image(img, 0, 0, renderer.width, renderer.height); // noLoop(); // } } void processImage() { buffer.beginDraw(); for (int x=0; x5?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; } } /* DRIPDRIP */ class DRIPDRIP extends Shader { int maxsteps = 50; //maximum fade length in px int minsteps = 2; //minimum fade length in px Boolean brightmode = false; //if enabled will fade light over dark Boolean autotoggle = true; //switch brightmode at pivot point float autoPivot = 0.58; //where on the y axis (0-1) to switch int steps[]; int rw, rh; DRIPDRIP() { name = "fxDripDrip"; params.add(new Param ("max steps", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("min steps", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("bright breakpoint", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); //params.add(new Param ("auto toggle", INTVAL, 0, 1, new int[]{SQUAR, RANDOM})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 3; rw = canvas.width; rh = canvas.height; steps = new int[canvas.width*canvas.height]; for (int i = 0; i < canvas.width*canvas.height; i++) { steps[i] = (int)map(random(1), 0, 1, minsteps, maxsteps); } } void apply() { minsteps = (int)map(params.get(1).value, 0, 1, 1, max(canvas.width, canvas.height)/10); maxsteps = (int)map(params.get(0).value, 0, 1, minsteps, max(canvas.width, canvas.height)/10); autoPivot = params.get(2).value; //brightmode = boolean((int)params.get(3).value); //autotoggle = boolean((int)params.get(4).value); if (rw != canvas.width || rh != canvas.height) { rw = canvas.width; rh = canvas.height; steps = new int[canvas.width*canvas.height]; } for (int i = 0; i < steps.length; i++) { steps[i] = (int)map(random(1), 0, 1, minsteps, maxsteps); } canvas.beginDraw(); canvas.loadPixels(); for ( int x = 0, w = canvas.width; x-1; y--) { /* if ( alternatetoggle ) { brightmode = !brightmode; } else { if ( autotoggle ) { brightmode = y > (h*autoPivot); } } */ //if (autotoggle) { brightmode = y > (h*autoPivot); //} float rat = 1.0; int pos = x + y * w; color c = canvas.pixels[pos]; int ty = y; while ( rat > 1.0/steps[x*y]*2 ) { ty++; if ( ty >= h ) break; int tpos = x + ty * w; color tc = canvas.pixels[tpos]; if ( ( !brightmode && brightness(tc) < brightness(c) ) || ( brightmode && brightness(tc) > brightness(c) ) ) break; canvas.pixels[tpos] = blendC(tc, c, rat); rat-= rat/steps[x*y]; } } } canvas.updatePixels(); canvas.endDraw(); } color blendC(color tc, color sc, float rat) { return color( (red(tc)*(1.0-rat))+(red(sc)*rat), (green(tc)*(1.0-rat))+(green(sc)*rat), (blue(tc)*(1.0-rat))+(blue(sc)*rat) ); } } /* WRONGQSORT */ class WRONGQSORT extends Shader { boolean mode = L; // L or R, which sort part is broken boolean do_blend = false; // blend image after process int blend_mode = OVERLAY; // blend type static final boolean L = true; static final boolean R = false; // working buffer PGraphics buffer; // image PImage img; float random_point = 0.5; int len; int rw, rh; WRONGQSORT() { name = "fxWrongQSort"; params.add(new Param ("v", FLOATVAL, 0.1, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("randomize", FLOATVAL, 0.1, 0.9, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param ("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param ("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param ("blend mode", INTVAL, 0, blends.length-1, new int[]{RANDOM})); params.add(new Param ("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 5; img = createImage(canvas.width, canvas.height, ARGB); img = canvas.get(); buffer = createGraphics(canvas.width, canvas.height); buffer.beginDraw(); buffer.noStroke(); buffer.smooth(8); buffer.background(0); buffer.image(img, 0, 0); buffer.endDraw(); } void apply() { random_point = params.get(1).value; mode = boolean((int)params.get(2).value); do_blend = boolean((int)params.get(3).value); blend_mode = blends[(int)params.get(4).value]; if (rw != canvas.width || rh != canvas.height) { rw = canvas.width; rh = canvas.height; img.resize(rw, rh); buffer = createGraphics(rw, rh); } img = canvas.get(); len = rw * rh; int v = (int)map(params.get(0).value, 0, 1, 1, len-1); buffer.beginDraw(); buffer.image(img, 0, 0); buffer.endDraw(); buffer.loadPixels(); int x = 0; while (x pivot) { j--; } if (i <= j) { temp = x[i]; x[i] = x [j]; x[j] = temp; i++; j--; } } return i; } void quicksort(int x[], int left, int right) { if (left index-1) quicksort(x, left, index-1); if (right > index) quicksort(x, index, right); } } } } /* VHS */ class VHS extends Shader { PImage timg; int bass, treble, sxl, syl; VHS () { name = "fxVHS"; params.add(new Param ("sine x length", INTVAL, 1, 100, new int[]{TRIANG, SINE})); params.add(new Param ("sine y length", INTVAL, 1, 100, new int[]{TRIANG, SINE})); params.add(new Param ("bass", INTVAL, -15, 15, new int[]{TRIANG, SINE})); params.add(new Param ("treble", INTVAL, -15, 15, new int[]{TRIANG, SINE})); params.add(new Param ("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 4; } void apply() { sxl = (int)params.get(0).value; syl = (int)params.get(1).value; bass = (int)params.get(2).value; treble = (int)params.get(3).value; int virtw = canvas.width; int virth = canvas.height; PImage timg = createImage(canvas.width, canvas.height, RGB); timg = canvas.get(); PImage hay = sinwav(timg, sxl, syl); PImage result = createImage(timg.width, timg.height, RGB); result.copy(hay, 0, 0, virtw, virth, 0, 0, result.width, result.height); canvas.beginDraw(); canvas.image(basstreble(result, bass, treble), canvas.width/2, canvas.height/2, canvas.width, canvas.height); //0 to 100 canvas.endDraw(); } PImage sinwav(PImage img, int xp, int yp) { int ctr = 0; img.loadPixels(); float ylength = xp; float xlength = yp; // was map (yp, 0,100, 1, 100); PImage result = createImage(img.width, img.height, RGB); for ( int y =0, h = img.height; y=0?r:r+256; float g = cg[iter]; g = g>=0?g:g+256; float b = cb[iter]; b = b>=0?b:b+256; buffer.pixels[i] = color(r, g, b); iter++; } buffer.updatePixels(); if (do_blend) buffer.blend(img, 0, 0, img.width, img.height, 0, 0, buffer.width, buffer.height, blend_mode); buffer.endDraw(); canvas.beginDraw(); canvas.image(buffer, canvas.width/2, canvas.height/2); canvas.endDraw(); } } class Tuple { public int offset, len; byte chr; public Tuple(int o, int l, byte c) { offset = o; len = l; chr = c; } } class LZ77 { int windowWidth; int lookAheadWidht; public LZ77(int ww, int law) { windowWidth = ww; lookAheadWidht = law; } ArrayList clist = new ArrayList(); public void glitch(int no, float fac) { for (int i=0; i=bend; i--) { if (buff[currByte] == buff[i]) { int tboff = abs(i-currByte); int tblen = 1; int laEnd = constrain(currByte+lookAheadWidht, 0, buff.length-1); int mi = currByte+1; while (miblen) { blen = tblen; boff = tboff; } } } currByte +=blen+1; // println("currchar = " + (currByte-1)+",blen = " + blen); clist.add( new Tuple(boff, blen, buff[currByte-1]) ); // println(boff + ", " + blen + ", " + buff[currByte-1]); } //println("clist " + clist.size()*2); } void doDecompress(byte[] buff) { int i = 0; for (Tuple t : clist) { if (i>=buff.length) break; if (t.offset == 0) { buff[i++] = t.chr; } else { int start = i-t.offset; int end = start + t.len; for (int c = start; c=buff.length) break; } if (i>=buff.length) break; buff[i++] = t.chr; } } } } /* LENS */ class LENS extends Shader { // parameters float bendx = 0.1; // from 0 to 1 float bendy = 0.1; // from 0 to 1 float[] power_vals = { 2, 0.5 }; // two values of power from 0.1 to 10, one for x and second for y int[] types = { LINEAR, POWER }; // always to types one for x second for y int[] channels = { BRIGHTNESS, SATURATION }; // as above float[] facts = new float[2]; ////////////// PImage img; PImage limg; int shaderListLength; // working buffer PGraphics buffer; LENS() { name = "fxLens"; shaderListLength = gui.shaderList.size(); params.add(new Param("lens image layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM})); params.add(new Param("power x", FLOATVAL, 0.1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("power y", FLOATVAL, 0.1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("lens type x", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("lens type y", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("channel x", INTVAL, 0, 11, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("channel y", INTVAL, 0, 11, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("curvature factor x", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("curvature factor y", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 9; rw = canvas.width; rh = canvas.height; img = createImage(rw, rh, ARGB); limg = createImage(rw, rh, ARGB); buffer = createGraphics(rw, rh); buffer.beginDraw(); buffer.noStroke(); buffer.endDraw(); } int rw, rh; void apply() { if (rw != canvas.width || rh != canvas.height) { rw = canvas.width; rh = canvas.height; buffer = createGraphics(rw, rh); buffer.beginDraw(); buffer.noStroke(); buffer.endDraw(); img.resize(rw, rh); limg.resize(rw, rh); } if (shaderListLength != gui.shaderList.size()) { shaderListLength = gui.shaderList.size(); changeParam(0, new Param("lens image layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM})); } img = canvas.get(); if ((int)params.get(0).value == pos) { limg = canvas.get(); } else { limg = gui.shaderList.get((int)params.get(0).value).result.get(); } power_vals[0] = params.get(1).value; power_vals[1] = params.get(2).value; types[0] = (int)params.get(3).value; types[1] = (int)params.get(4).value; channels[0] = (int)params.get(5).value; channels[1] = (int)params.get(6).value; bendx = params.get(7).value; bendy = params.get(8).value; facts[0] = bendx * img.width; facts[1] = bendy * img.height; img.loadPixels(); limg.loadPixels(); buffer.beginDraw(); buffer.background(0); for (int x=0; x5?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; } int getShift(color c, int idx) { float cc = getChannel(c, channels[idx]); switch(types[idx]) { case LINEAR: return (int)(facts[idx] * cc/255.0); case POWER: return (int)(facts[idx]*map(pow(cc/255.0, power_vals[idx]), 0, 1, -1, 1)); case SINUSOIDAL: return (int)(facts[idx]*sin(map(cc, 0, 255, -PI, PI))); default: { // POLAR float c1 = idx==0?cc:getChannel(c, channels[1]); float c2 = idx==1?cc:getChannel(c, channels[0]); float ang = map(c1, 0, 255, 0, TWO_PI); float r = map(c2, 0, 255, 0, facts[0]); return (int)(idx==0?r*cos(ang):r*sin(ang)); } } } } /* SLICER */ class SLICER extends Shader { ArrayList edges = new ArrayList(); SegmentNode[] elements; Map m = new HashMap(); int max_patterns = 20; // CAN I KILL THIS? float max_rotation = TWO_PI; // random or fixed rotation up to specified angle, 0 - TWO_PI, 0 - no rotation boolean fixed_rotation = true; // fixed or random rotation int thr_min = -1; // you can change color of segment for specified brightness threshold int thr_max = -1; // set to -1 if you don't want to use it, values from 0 to 255 color[] palette = { #000000, #E7CBB3, #CEC6AF, #A0C3BC, #7C7F84, #ffffff }; // choose colors for palette you want to use with threshold, colors will be choosen randomly // SEPARATE config float max_shift = 2; // max expected shift, using gaussian random, so bigger number, more distortion int type = ROTATE; // choose type of distortion: PATTERNS, SEPARATE, ROTATE, SHIFTCOPY, SORT boolean do_blend = false; // blend result with original? int blend_type = SUBTRACT; // list here: https://processing.org/reference/blend_.html // segmentation config START float threshold = 500.0; // higher number - bigger segments int min_comp_size = 200; // minimal segment size (in pixels), minimum 10 int blur = 0; // sometimes it's good to blur image to have less sharp segment edges, 0 = off, blur > 0 - blur kernel size int stat_type = DIST; // edge calculation method final static int DIST = 0; final static int HUE = 1; final static int BRIGHTNESS = 2; final static int SATURATION = 3; final static int ABSDIST = 4; // do not touch it PImage img, mimg; // load image to this variable int num; // segmentation config END // do not touch, list of types final static int PATTERNS = 0; // fill segments with patterns final static int SEPARATE = 1; // separate segments (black background visible) final static int ROTATE = 2; // rotate content of the segments final static int SHIFTCOPY = 3; // copy content from shifted image final static int SORT = 4; // sort segments by color value // working buffer PGraphics buffer; SLICER() { name = "fxSlicer"; params.add(new Param("mask layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM})); params.add(new Param("max rotation", FLOATVAL, 0, TWO_PI, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("min threshold", INTVAL, -1, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("max threshold", INTVAL, -1, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("max shift", FLOATVAL, 0, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("type", INTVAL, 0, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("blend type", INTVAL, 0, blends.length-1, new int[]{RANDOM})); params.add(new Param("threshold", FLOATVAL, 100, 2000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("min comp size", INTVAL, 10, 500, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("blur", INTVAL, 0, 6, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("stat type", INTVAL, 0, 6, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("fixed rotation", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 13; shaderListLength = gui.shaderList.size(); img = createImage(canvas.width, canvas.height, ARGB); mimg = createImage(canvas.width, canvas.height, ARGB); buffer = createGraphics(img.width, img.height); buffer.beginDraw(); buffer.noStroke(); buffer.smooth(8); buffer.background(0); buffer.endDraw(); } int rw, rh, shaderListLength; void apply() { if (canvas.width != rw || canvas.height != rh) { rw = canvas.width; rh = canvas.height; buffer = createGraphics(rw, rh); buffer.beginDraw(); buffer.noStroke(); buffer.endDraw(); img.resize(rw, rh); mimg.resize(rw, rh); } if (shaderListLength != gui.shaderList.size()) { shaderListLength = gui.shaderList.size(); changeParam(0, new Param("mask layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM})); } img = canvas.get(); if ((int)params.get(0).value == pos) { mimg = canvas.get(); } else { mimg = gui.shaderList.get((int)params.get(0).value).result.get(); } max_rotation = params.get(1).value; thr_min = (int)params.get(2).value; thr_max = (int)params.get(3).value; max_shift = params.get(4).value; type = (int)params.get(5).value; do_blend = boolean((int)params.get(6).value); blend_type = blends[(int)params.get(7).value]; threshold = params.get(8).value; min_comp_size = (int)params.get(9).value; blur = (int)params.get(10).value; stat_type = (int)params.get(11).value; fixed_rotation = boolean((int)params.get(12).value); //println(""); //println("Processing..."); edges.clear(); makeEdges(); calculateSegmentation(); buffer.beginDraw(); m.clear(); if (type == PATTERNS) preparePatterns(); for (int x=0; x=thr_min && brightness(segm.c)<=thr_max) segm.c = palette[(int)random(palette.length)]; if (type == PATTERNS) { segm.pat = patterns[(int)random(max_patterns)]; segm.pats = random(0.5, 10); } if (type == SORT) { segm.xy = random(1)<0.5; int size = elements[segment].size; segm.clrs = new color[size]; segm.positions = new int[size]; segm.iters = 0; sortHelper(segm, x, y); } m.put(segment, segm); } if (type == PATTERNS) { int vx = segm.x-x; int vy = segm.y-y; float sinr = segm.rots; float cosr = segm.rotc; int imgx = int(segm.pat.width+x+(cosr*vx-sinr*vy))%segm.pat.width; int imgy = int(segm.pat.height+x+(sinr*vx+cosr*vy))%segm.pat.height; buffer.fill(segm.pat.get(imgx, imgy)); buffer.rect(x, y, 1, 1); } else if (type == SEPARATE) { buffer.fill(segm.c); buffer.rect(x+segm.dx, y+segm.dy, 1, 1); } else if (type == SHIFTCOPY) { int imgx = (2*x-segm.x)%img.width; int imgy = (2*y-segm.y)%img.height; buffer.fill(img.get(imgx, imgy)); buffer.rect(x, y, 1, 1); } else if (type == ROTATE) { int vx = segm.x-x; int vy = segm.y-y; float sinr = segm.rots; float cosr = segm.rotc; int imgx = int(img.width+x+(cosr*vx-sinr*vy))%img.width; int imgy = int(img.height+y+(sinr*vx+cosr*vy))%img.height; buffer.fill(img.get(imgx, imgy)); buffer.rect(x, y, 1, 1); } } if (type == SORT) { for (Integer key : m.keySet()) { S segm = m.get(key); segm.clrs = sort(segm.clrs); segm.positions = sort(segm.positions); } for (Integer key : m.keySet()) { S segm = m.get(key); for (int i=0; i> 16) & 0xffff; y = segm.positions[i] & 0xffff; } else { y = (segm.positions[i] >> 16) & 0xffff; x = segm.positions[i] & 0xffff; } buffer.fill(segm.clrs[i]); buffer.rect(x, y, 1, 1); } } } if (do_blend) buffer.blend(img, 0, 0, img.width, img.height, 0, 0, buffer.width, buffer.height, blend_type); buffer.endDraw(); canvas.beginDraw(); canvas.image(buffer, canvas.width/2, canvas.height/2); canvas.endDraw(); } void sortHelper(S segm, int x, int y) { int xyval; if (segm.xy) xyval = (x << 16) | y; else xyval = (y << 16) | x; segm.clrs[segm.iters] = img.get(x, y); segm.positions[segm.iters++] = xyval; } final float getStat(color c1, color c2) { switch(stat_type) { case HUE: abs(hue(c1)-hue(c2)); case BRIGHTNESS: abs(brightness(c1)-brightness(c2)); case SATURATION: abs(saturation(c1)-saturation(c2)); case ABSDIST: return abs(red(c1)-red(c2)) + abs(green(c1)-green(c2)) + abs(blue(c1)-blue(c2)); default: return sq(red(c1)-red(c2)) + sq(green(c1)-green(c2)) + sq(blue(c1)-blue(c2)); } } void makeEdges() { PImage img2 = mimg.get(0, 0, img.width, img.height); if (blur > 0) img2.filter(BLUR, blur); // make grid each point connected to neighbours for (int x=0; x0)) { Edge e = new Edge(); e.a = y*img2.width+x; e.b = (y-1)*img2.width+x+1; e.weight = getStat(c, img2.get(x+1, y-1)); edges.add(e); } } // sort edges Collections.sort(edges); } int findEnd(int x) { int y = x; while (y != elements[y].parent) y = elements[y].parent; elements[x].parent = y; return y; } void joinSegments(int x, int y) { if (elements[x].rank > elements[y].rank) { elements[y].parent = x; elements[x].size += elements[y].size; } else { elements[x].parent = y; elements[y].size += elements[x].size; if (elements[x].rank == elements[y].rank) elements[y].rank++; } num--; } void calculateSegmentation() { int no_vertices = img.width*img.height; num = no_vertices; elements = new SegmentNode[no_vertices]; // init nodes for (int i=0; ie.weight?1:0; } } class SegmentNode { int rank, parent, size; } /* STREAKER */ class STREAKER extends Shader { final int EXCLUSIVE = 0; final int LESSER = 1; final int GREATER = 2; final int CLASSIC = 0; final int RGBSUM = 1; final int BRIGHT = 2; PImage img; float tol = 100.0; // tolerance int mode = LESSER; // EXCLUSIVE, LESSER, GREATER int sum = BRIGHT; // CLASSIC, RGBSUM, BRIGHT int lim = 1; // move divisor int iterations = 1; float rand = 5; boolean h = false; boolean v = true; boolean Hrev = false; boolean Vrev = false; int W, H; STREAKER() { name = "fxStreaker"; img = createImage(canvas.width, canvas.height, ARGB); params.add(new Param("vertical/horizontal/both", INTVAL, 0, 2, new int[]{RANDOM})); params.add(new Param("verticals up / down", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("horicontals up / down", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("tolerance", FLOATVAL, 0, 100, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("tolerance randomness", FLOATVAL, 0, 50, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("detection mode (EXCLUSIVE, LESSER, GREATER)", INTVAL, 0, 2, new int[]{RANDOM})); params.add(new Param("sum (RBG sum, brightness, R>G>B)", INTVAL, 0, 2, new int[]{RANDOM})); params.add(new Param("move divisor", INTVAL, 1, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("iterations", INTVAL, 1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 9; W = canvas.width; H = canvas.height; } void apply() { if (W != canvas.width || H != canvas.height) { W = canvas.width; H = canvas.height; img.resize(W, H); } img = canvas.get(); int p0 = (int)params.get(0).value; v = (p0 == 0 || p0 == 2) ? true : false; h = (p0 == 1 || p0 == 2) ? true : false; Vrev = boolean((int)params.get(1).value); Hrev = boolean((int)params.get(2).value); tol = params.get(3).value; rand = params.get(4).value; mode = (int)params.get(5).value; sum = (int)params.get(6).value; lim = (int)params.get(7).value; iterations = (int)params.get(8).value; PGraphics temp = createGraphics(img.width, img.height); int off = 0; color c; boolean a = false; for (int i = 0; i < iterations; i++) { img.loadPixels(); temp.beginDraw(); temp.image(img, 0, 0); if (h) { if (!Hrev) { for (int y = 0; y < img.height-1; y++) { for (int x = 0; x < img.width-1; x++) { c = img.pixels[x+(y*img.width)]; while (check (x, y, x+off+1, y) == true && x+off+1 < img.width) { off++; a = true; } if (a) { temp.stroke(c); temp.line(x, y, x+(off/lim), y); x = x+(off/lim); a = false; off = 0; } } } } else { // hrev for (int y = 0; y < img.height-1; y++) { for (int x = img.width-1; x > 1; x--) { c = img.pixels[x+(y*img.width)]; while (check (x, y, x-off-1, y) == true && x-off-1 > 0) { off++; a = true; } if (a) { temp.stroke(c); temp.line(x, y, x-(off/lim), y); x = x-(off/lim); a = false; off = 0; } } } } } if (v) { if (!Vrev) { for (int x = 0; x < img.width-1; x++) { for (int y = 0; y < img.height-1; y++) { c = img.pixels[x+(y*img.width)]; while (check (x, y, x, y+off+1) == true && y+off+1 < img.height-1 ) { off++; a = true; } if (a) { temp.stroke(c); temp.line(x, y, x, y+(off/lim)); y = y+(off/lim); a = false; off = 0; } } } } else { //Vrev for (int x = 0; x < img.width-1; x++) { for (int y = img.height-1; y > 1; y--) { c = img.pixels[x+(y*img.width)]; while (check (x, y, x, y-off-1) == true && y-off-1 > 0) { off++; a = true; } if (a) { temp.stroke(c); temp.line(x, y, x, y-(off/lim)); y = y-(off/lim); a = false; off = 0; } } } } } temp.endDraw(); img = temp.get(); img.updatePixels(); } canvas.beginDraw(); canvas.image(img, canvas.width/2, canvas.height/2); canvas.endDraw(); } boolean check(int x, int y, int xc, int yc) { float src, dst, r; r = (rand != 0) ? random(0, rand) : 0; switch(sum) { case 1: //rgbsum src = rgbsum(x, y); dst = rgbsum(xc, yc); break; case 2: // brightness src = brightness(img.pixels[x+(y*img.width)]); dst = brightness(img.pixels[xc+(yc*img.width)]); break; default: // 'classic' or asdfish src = map(img.pixels[x+(y*img.width)], 0, 0xFFFFFF, 0.0, 255.0); dst = map(img.pixels[xc+(yc*img.width)], 0, 0xFFFFFF, 0.0, 255.0); break; } if (mode == 0 && (src < dst-tol-r || src > dst+tol+r)) return true; else if (mode == 1 && src > dst+tol-r) return true; else if (mode == 2 && src < dst-tol+r) return true; else return false; } float rgbsum(int x, int y) { int r = img.pixels[x+(y*img.width)] >> 24 & 0xff; int g = img.pixels[x+(y*img.width)] >> 16 & 0xff; int b = img.pixels[x+(y*img.width)] & 0xff; float result = (r + g + b) / 3; return result; } } /* SEGMENTER */ class SEGMENTER extends Shader { int thres = 64; // threshold int mode = 0; // lighter/darker, essentially 'reverses' the sort boolean diag = true; // diagonal/straight boolean v = true; // use to select initial direction. boolean h = true; // if cycling, use V=true H=false. boolean choice = false; int iterations; PImage img; int[] bounds = {0, 0, 0, 0}; boolean running = true; SEGMENTER() { name = "fxSegmenter"; params.add(new Param("threshold", INTVAL, 8, 252, new int[]{SINE, TRIANG})); params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("diagonal", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("horizontal", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); params.add(new Param("vertical", INTVAL, 0, 1, new int[] {RANDOM, SQUAR})); params.add(new Param("weirdo pattern mode", INTVAL, 0, 1, new int[] {RANDOM, SQUAR})); params.add(new Param("iterations", INTVAL, 1, 100, new int[] {SINE, TRIANG})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 7; img = createImage(canvas.width, canvas.height, ARGB); canvas.beginDraw(); canvas.colorMode(HSB); canvas.endDraw(); } int rw, rh; void apply() { if (rw != canvas.width || rh != canvas.height) { rw = canvas.width; rh = canvas.height; img.resize(rw, rh); bounds[0]= 0; bounds[1]= 0; bounds[2]= rw; bounds[3]= rh; } img = canvas.get(); thres = (int)params.get(0).value; mode = (int)params.get(1).value; diag = boolean((int)params.get(2).value); v = boolean((int)params.get(3).value); h = boolean((int)params.get(4).value); choice = boolean((int)params.get(5).value); iterations = (int)params.get(6).value; canvas.beginDraw(); canvas.image(img, canvas.width/2, canvas.height/2); canvas.endDraw(); canvas.beginDraw(); for (int i = 0; i < iterations; i++) { canvas.loadPixels(); for (int j = bounds[1]; j < bounds[3]-1; j++) { for (int k = bounds[0]; k < bounds[2]-1; k++) { float bright = canvas.brightness(canvas.get(k, j)); color c; if (!choice) { if (diag) { if (mode == 0) { if (h && bright < abs(thres)&& k > bounds[0]+1 && j > bounds[1]+1 && (bright < canvas.brightness(canvas.pixels[k-1+((j-1)*canvas.width)]))) { swap(k, j, k-1, j-1); } else if (v && bright < abs(thres*2) && j > bounds[1]+1 && k < bounds[2]-1 && (bright < canvas.brightness(canvas.pixels[k+1+((j-1)*canvas.width)]))) { swap(k, j, k+1, j-1); } else if (h && bright < abs(thres*3) && k < bounds[2]-1 && j < bounds[3]-1 && (bright < canvas.brightness(canvas.pixels[k+1+((j+1)*canvas.width)]))) { swap(k, j, k+1, j+1); } else if (v && k > bounds[0] && j < bounds[3]-1 && (bright < canvas.brightness(canvas.pixels[k-1+((j+1)*canvas.width)]))) { swap(k, j, k-1, j+1); } } else { // mode if (h && bright < abs(thres)&& k > bounds[0] && j > bounds[1] && (bright > canvas.brightness(canvas.pixels[k-1+((j-1)*canvas.width)]))) { swap(k, j, k-1, j-1); } else if (v && bright < abs(thres*2) && j > bounds[1] && k < bounds[2]-1 && (bright > canvas.brightness(canvas.pixels[k+1+((j-1)*canvas.width)]))) { swap(k, j, k+1, j-1); } else if (h && bright < abs(thres*3) && k < bounds[2]-1 && j < bounds[3]-1 && (bright > canvas.brightness(canvas.pixels[k+1+((j+1)*canvas.width)]))) { swap(k, j, k+1, j+1); } else if (v && k > bounds[0] && j < bounds[3]-1 && (bright > canvas.brightness(canvas.pixels[k-1+((j+1)*canvas.width)]))) { swap(k, j, k-1, j+1); } } // mode }//diag else { if (mode == 0) { if (h && bright < abs(thres)&& k > bounds[0] && (bright < canvas.brightness(canvas.get(k-1, j)))) { swap(k, j, k-1, j); } else if (v && bright < abs(thres*2) && j > bounds[1] && (bright < canvas.brightness(canvas.get(k, j-1)))) { swap(k, j, k, j-1); } else if (h && bright < abs(thres*3) && k < bounds[2]-1 && (bright < canvas.brightness(canvas.get(k+1, j)))) { swap(k, j, k+1, j); } else if (v && k > bounds[0] && j < bounds[3]-1 && (bright < canvas.brightness(canvas.get(k, j+1)))) { swap(k, j, k, j+1); } } else { // mode if (h && bright < abs(thres)&& k > bounds[0] && (bright > canvas.brightness(canvas.get(k-1, j)))) { swap(k, j, k-1, j); } else if (v && bright < abs(thres*2) && j > bounds[1] && (bright > canvas.brightness(canvas.get(k, j-1)))) { swap(k, j, k, j-1); } else if (h && bright < abs(thres*3) && k < bounds[2]-1 && (bright > canvas.brightness(canvas.get(k+1, j)))) { swap(k, j, k+1, j); } else if (v && k > bounds[0] && j < bounds[3]-1 && (bright > canvas.brightness(canvas.get(k, j+1)))) { swap(k, j, k, j+1); } } // mode } // diag } else { //choice //weirdo pattern mode if (mode == 0) { if (bright < thres && k-1+((j-1)*canvas.width) > 0) { swap(k, j, k-1, j-1); } else if (bright < abs(thres*2) && k+1+((j-1)*canvas.width) > 0) { swap(k, j, k+1, j-1); } else if (bright < abs(thres*3) && k+1+((j+1)*canvas.width) < canvas.width*canvas.height) { swap(k, j, k+1, j+1); } else if (k-1+((j+1)*canvas.width) < canvas.width*canvas.height) { swap(k, j, k-1, j+1); } } else { // mode if (bright > abs(thres*3) && k-1+((j-1)*canvas.width) > 0) { if (k-1+((j-1)*canvas.width) > 0) { swap(k, j, k-1, j-1); } } else if (bright > abs(thres*2) && k+1+((j-1)*canvas.width) > 0) { if (k+1+((j-1)*canvas.width) > 0) { swap(k, j, k+1, j-1); } } else if (bright < thres && k+1+((j+1)*canvas.width) < canvas.width*canvas.height) { swap(k, j, k+1, j+1); } else if (k-1+((j+1)*canvas.width) < canvas.width*canvas.height) { swap(k, j, k-1, j+1); } } // mode }//choice }//hori loop }//vert loop canvas.updatePixels(); }//iterations canvas.endDraw(); } void swap(int x, int y, int xc, int yc) { // if (x+(y*width) < width*height && xc+(yc*width) < width*height && xc+(yc*width) > -1) { color c = canvas.pixels[x+(y*canvas.width)]; canvas.pixels[x+(y*canvas.width)] = canvas.pixels[xc+(yc*canvas.width)]; canvas.pixels[xc+((yc)*canvas.width)] = c; // } } } /* COLORCRUSHER */ class COLORCRUSHER extends Shader { float c; int m = 5; COLORCRUSHER() { name = "fxColorCrusher"; params.add(new Param("multiplier", INTVAL, 2, 10, new int[]{SINE, TAN, SAWTOOTH, TRIANG})); } void apply() { m = (int)params.get(0).value; canvas.beginDraw(); canvas.loadPixels(); for (int i = 0; i < canvas.pixels.length; i++) { c = color(canvas.pixels[i]); canvas.pixels[i] = int(c*m); } canvas.updatePixels(); canvas.endDraw(); } } /* RAINBOWHUE */ //... /* JPGCorruption by Victor Giers */ class JPGCORRUPTION extends Shader { PImage img; byte[] brokenfile; JPGCORRUPTION() { name = "fxJPGHexGlitch"; params.add(new Param("byte amount to change probability", INTVAL, 2, 200, new int[]{RANDOM})); params.add(new Param("iterations", INTVAL, 2, 10, new int[]{RANDOM})); params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); directionParamIndex = 2; rw = canvas.width; rh = canvas.height; img = createImage(rw, rh, ARGB); } int rw, rh; void apply() { if (rw != canvas.width || rh != canvas.height) { rw = canvas.width; rh = canvas.height; img.resize(rw, rh); } int probparam = (int)params.get(0).value; int iterations = (int)params.get(1).value; img = canvas.get(); canvas.beginDraw(); for (int k = 0; k < iterations; k++) { canvas.image(img, canvas.width/2, canvas.height/2); canvas.save(dataPath("")+"/JPGHex.jpg"); //save as jpg brokenfile = loadBytes(dataPath("")+"/JPGHex.jpg"); //and reload. just in case it wasnt a jpg. double probability = float(probparam) / float(brokenfile.length); byte[] savebytes2 = new byte[brokenfile.length]; boolean headerEnd = false; boolean FFfound = false; int glitchCount = 0; for (int i = 0; i < brokenfile.length; i++) { String hexStr = hex(brokenfile[i]); if (FFfound && hexStr.equals("DA")) headerEnd = true; FFfound = false; if (hexStr.equals("FF")) FFfound = true; if (headerEnd && random(1) 10) { // skip header if (random(1)