Browse Source

added fxVHS

master
Victor Giers 1 year ago
parent
commit
79aa5861cd
3 changed files with 193 additions and 29 deletions
  1. 185
    28
      effects.pde
  2. 6
    0
      secondapplet.pde
  3. 2
    1
      statics_and_lists.pde

+ 185
- 28
effects.pde View File

@@ -2722,8 +2722,6 @@ class DRIPDRIP extends Shader {
*/

class WRONGQSORT extends Shader {
int max_display_size = 800; // viewing window size (regardless image size)

boolean mode = L; // L or R, which sort part is broken

boolean do_blend = false; // blend image after process
@@ -2740,51 +2738,69 @@ class WRONGQSORT extends Shader {

float random_point = 0.5;
int len;
int rw, rh;

//bei mausmove
WRONGQSORT() {
name = "fxWrongQSort";
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}));
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 = 3;
/*
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();
*/
buffer.beginDraw();
buffer.noStroke();
buffer.smooth(8);
buffer.background(0);
buffer.image(img, 0, 0);
buffer.endDraw();
}

void apply() {
float x = params.get(0).value;
float y = params.get(1).value;
int v = (int)map(x*y, 0, 1, 1, len-1);
random_point = params.get(2).value;
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();

canvas.beginDraw();
canvas.image(img, 0, 0);
canvas.endDraw();
len = rw * rh;
int v = (int)map(params.get(0).value, 0, 1, 1, len-1);

canvas.loadPixels();
buffer.beginDraw();
buffer.image(img, 0, 0);
buffer.endDraw();

buffer.loadPixels();
int x = 0;
while (x<len) {
if (x+v<len) quicksort(canvas.pixels, x, x+v);
else quicksort(canvas.pixels, x, len-1);
if (x+v<len) quicksort(buffer.pixels, x, x+v);
else quicksort(buffer.pixels, x, len-1);
x+=v;
}
canvas.updatePixels();
buffer.updatePixels();

buffer.beginDraw();
if (do_blend) {
canvas.beginDraw();
canvas.blend(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height, blend_mode);
canvas.endDraw();
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();
}


@@ -2828,8 +2844,149 @@ class WRONGQSORT extends Shader {



/*

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<h; y++) {
for ( int x = 0, w = img.width; x<w; x++, ctr++) {
int pos = x + y * w;
color c = img.pixels[pos];
int epos = (int)(( x + sin(y/ylength)*xlength)+ y * w);
if ( epos < result.pixels.length )
result.pixels[epos] = c;
else
result.pixels[pos] = c;
}
}
result.updatePixels();
return result;
}

PImage basstreble(PImage img, int xp, int yp) {
float dB_bass = xp;
float dB_treble = yp;
PImage result = createImage(img.width, img.height, RGB);
float slope = 0.4;
double hzBass = 250.0;
double hzTreble = 4000.0;
float b0, b1, b2, a0, a1, a2, xn2Bass, xn1Bass, yn2Bass, yn1Bass, b0Bass, b1Bass, b2Bass, xn1Treble, xn2Treble, yn1Treble, yn2Treble, a0Bass, a1Bass, a2Bass, a0Treble, a1Treble, a2Treble, b0Treble, b1Treble, b2Treble;
double mMax = 0.0;
double mSampleRate = 44000;

xn1Bass = xn2Bass = yn1Bass = yn2Bass = 0.0;
xn1Treble = xn2Treble = yn1Treble = yn2Treble = 0.0;

float w = (float)(2 * PI * hzBass / mSampleRate);
float a = exp((float)(log(10.0) * dB_bass / 40));
float b = sqrt((float)((a * a + 1) / slope - (pow((float)(a - 1), 2))));

b0Bass = a * ((a + 1) - (a - 1) * cos(w) + b * sin(w));
b1Bass = 2 * a * ((a - 1) - (a + 1) * cos(w));
b2Bass = a * ((a + 1) - (a - 1) * cos(w) - b * sin(w));
a0Bass = ((a + 1) + (a - 1) * cos(w) + b * sin(w));
a1Bass = -2 * ((a - 1) + (a + 1) * cos(w));
a2Bass = (a + 1) + (a - 1) * cos(w) - b * sin(w);

w = (float)(2 * PI * hzTreble / mSampleRate);
a = exp((float)(log(10.0) * dB_treble / 40));
b = sqrt((float)((a * a + 1) / slope - (pow((float)(a - 1), 2))));



b0Treble = a * ((a + 1) + (a - 1) * cos(w) + b * sin(w));
b1Treble = -2 * a * ((a - 1) + (a + 1) * cos(w));
b2Treble = a * ((a + 1) + (a - 1) * cos(w) - b * sin(w));
a0Treble = ((a + 1) - (a - 1) * cos(w) + b * sin(w));
a1Treble = 2 * ((a - 1) - (a + 1) * cos(w));
a2Treble = (a + 1) - (a - 1) * cos(w) - b * sin(w);


img.loadPixels();
result.loadPixels();
for ( int i = 0, l = img.pixels.length; i<l; i++) {
int[] rgb = new int[3];
rgb[0] = (int)red(img.pixels[i]);
rgb[1] = (int)green(img.pixels[i]);
rgb[2] = (int)blue(img.pixels[i]);
for ( int ri = 0; ri<3; ri++ ) {
float in = map(rgb[ri], 0, 255, 0, 1);

float out = (b0Bass * in + b1Bass * xn1Bass + b2Bass * xn2Bass - a1Bass * yn1Bass - a2Bass * yn2Bass ) / a0Bass;
//println(a0Bass);
xn2Bass = xn1Bass;
xn1Bass = in;
yn2Bass = yn1Bass;
yn1Bass = out;
//treble filter
in = out;
out = (b0Treble * in + b1Treble * xn1Treble + b2Treble * xn2Treble - a1Treble * yn1Treble - a2Treble * yn2Treble) / a0Treble;
xn2Treble = xn1Treble;
xn1Treble = in;
yn2Treble = yn1Treble;
yn1Treble = out;

//retain max value for use in normalization
if ( mMax < abs(out))
mMax = abs(out);




rgb[ri] = (int)map(out, 0, 1, 0, 255);
}
result.pixels[i] = color(rgb[0], rgb[1], rgb[2]);
}
result.updatePixels();

return result;
}
}





+ 6
- 0
secondapplet.pde View File

@@ -604,6 +604,12 @@ public class SecondApplet extends PApplet {
case(23):
shaderManager.addShader(new DRIPDRIP());
break;
case(24):
shaderManager.addShader(new WRONGQSORT());
break;
case(25):
shaderManager.addShader(new VHS());
break;
/*
case(4):
shaderManager.addShader(new AUECHO());

+ 2
- 1
statics_and_lists.pde View File

@@ -73,5 +73,6 @@ String availableFx[] = {
"fxDrawGenerative",
"fxPixelDrifter",
"fxDripDrip",
"fxWrongQSort"
"fxWrongQSort",
"fxVHS"
};

Loading…
Cancel
Save