Files
manglr2/effects.pde

452 lines
11 KiB
Plaintext

/*
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;
}
}