2022-06-22 21:31:34 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
ASDFPIXELSORT
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class ASDFPIXELSORT extends Shader {
|
|
|
|
|
ASDFPIXELSORT() {
|
|
|
|
|
name = "fxASDFPixelSort";
|
2022-06-23 00:26:10 +02:00
|
|
|
params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
2022-06-22 21:31:34 +02:00
|
|
|
params.add(new Param("mode", INTVAL, 0, 2, new int[]{RANDOM}));
|
|
|
|
|
}
|
|
|
|
|
int previousMode;
|
|
|
|
|
|
|
|
|
|
void apply() {
|
|
|
|
|
if (previousMode != int(params.get(1).value)) {
|
2022-06-23 00:26:10 +02:00
|
|
|
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}));
|
2022-06-22 21:31:34 +02:00
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
PImage buffer;
|
|
|
|
|
|
|
|
|
|
int[][] distort = new int[2][512];
|
|
|
|
|
final static float tick = 1.0/512.0;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
DISTORTER() {
|
|
|
|
|
name = "fxDistorter";
|
|
|
|
|
/*
|
|
|
|
|
//params.add(new Param ("shifthue", 1)); //boolean shift_hue
|
|
|
|
|
params.add(new Param("hueshift", 0, 1)); //float shift_amt
|
|
|
|
|
params.add(new Param("scalex", 0.01, 1)); //float scalex
|
|
|
|
|
params.add(new Param("scaley", 0.01, 1)); //float scaley
|
|
|
|
|
//params.add(new Param ("blend", 1)); //boolean do_blend
|
|
|
|
|
params.add(new Param ("blendmode", blends.length)); //int blend_mode
|
|
|
|
|
params.add(new Param("channel", 12));*/
|
|
|
|
|
|
|
|
|
|
buffer = createImage(renderer.width, renderer.height, ARGB);
|
|
|
|
|
|
|
|
|
|
// prepare distortion pattern
|
|
|
|
|
for (int i=0; i<512; i++) {
|
|
|
|
|
distort[0][i] = (int)random(-128, 128);
|
|
|
|
|
distort[1][i] = (int)random(-128, 128);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void apply() {
|
|
|
|
|
buffer = renderer.get();
|
|
|
|
|
buffer.resize(renderer.width, renderer.height);
|
|
|
|
|
|
|
|
|
|
float neww = map(params.get(1).value, 0, 1, 1, buffer.width/4);
|
|
|
|
|
float newh = map(params.get(2).value, 0, 1, 1, buffer.height/4);
|
|
|
|
|
|
|
|
|
|
float totalnum = neww+newh;
|
|
|
|
|
float times = (totalnum/floor(totalnum/neww));
|
|
|
|
|
float offx = (totalnum%neww)/times;
|
|
|
|
|
float ratiox = neww/buffer.width;
|
|
|
|
|
|
|
|
|
|
renderer.beginDraw();
|
|
|
|
|
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), (int)params.get(4).value);
|
|
|
|
|
int sx = (int)((buffer.width+x+cx*rx*params.get(1).value*0.1)%buffer.width);
|
|
|
|
|
int sy = (int)((buffer.height+y+cy*params.get(0).value)%buffer.height);
|
|
|
|
|
|
|
|
|
|
color c=buffer.get(sx, sy);
|
|
|
|
|
|
|
|
|
|
//if (boolean((int)(params.get(0).value))) {
|
|
|
|
|
colorMode(HSB, 255);
|
|
|
|
|
c = color((hue(c)+params.get(0).value*255*noise(newh+y))%255.0, constrain(saturation(c)*1.2, 0, 255), constrain(brightness(c), 0, 255));
|
|
|
|
|
colorMode(RGB, 255);
|
|
|
|
|
//}
|
|
|
|
|
//renderer.fill(lerpColor(c,buffer.get(x,y),0.2));
|
|
|
|
|
renderer.fill(c);
|
|
|
|
|
renderer.rect(x, y, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if (boolean((int)(params.get(4).value)))
|
|
|
|
|
renderer.blend(buffer, 0, 0, buffer.width, buffer.height, 0, 0, renderer.width, renderer.height, (int)params.get(3).value);
|
|
|
|
|
|
|
|
|
|
colorMode(RGB);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|