Browse Source

initial commit

master
Victor Giers 7 months ago
commit
23f37c2558
28 changed files with 4260 additions and 0 deletions
  1. 293
    0
      ASDFPIXELSORT.pde
  2. 60
    0
      AUECHO.pde
  3. 83
    0
      BRIGHTER.pde
  4. 74
    0
      DARKER.pde
  5. 142
    0
      DISTORTER.pde
  6. 119
    0
      DRAWGENERATIVE.pde
  7. 209
    0
      DRAWSTROKES.pde
  8. 249
    0
      FM.pde
  9. 56
    0
      GRAUZONE.pde
  10. 188
    0
      SLITSCAN.pde
  11. 250
    0
      WZIP.pde
  12. 800
    0
      colorspaces.pde
  13. BIN
      data/0.mp4
  14. BIN
      data/0.png
  15. BIN
      data/1.png
  16. BIN
      data/mask.png
  17. BIN
      data/potrace
  18. 2
    0
      data/saves.sav
  19. 47
    0
      ffmpeg.txt
  20. 48
    0
      fx.pde
  21. 155
    0
      mangler2_0001.pde
  22. 40
    0
      mint.pde
  23. 136
    0
      net.pde
  24. 114
    0
      oscillator.pde
  25. 751
    0
      render_airis.pde
  26. 112
    0
      shader.pde
  27. 153
    0
      source.pde
  28. 179
    0
      ui.pde

+ 293
- 0
ASDFPIXELSORT.pde View File

@@ -0,0 +1,293 @@


class ASDFPIXELSORT extends Shader {

ASDFPIXELSORT() {
name = "fxASDFPixelSort";
params.add(new Param("black", 0, 200, new int[]{SIN, LINE, RAMPUPDOWN, TAN, COS}));
params.add(new Param("white", -20000000, -6000000, new int[]{SIN, LINE, RAMPUPDOWN, TAN, COS}));
params.add(new Param("brightness", -15000000, 2000000, new int[]{SIN, LINE, RAMPUPDOWN, TAN, COS}));
params.add(new Param("mode", 3, new int[]{RANDOM}));
}
/*
float playSpeed = 4;
float inc1, inc2, inc3;
void animate() {
inc1+=playSpeed/400;
inc2+=playSpeed/300;
inc3+=playSpeed/350;
if ((frameCount % int(map(playSpeed, 0, 4, 15, 120))) == 0) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
}
params.get(0).setValue((sin(inc1)+1)/2);
params.get(2).setValue((sin(inc2)+1)/2);
params.get(1).setValue((sin(inc3)+1)/2);
}
*/
void apply() {
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(3).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(3).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(2).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(2).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(1).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(1).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(2).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(2).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(2).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(1).value) {
y++;
if (y >= renderer.height) return renderer.height-1;
}
}
return y-1;
}
}

+ 60
- 0
AUECHO.pde View File

@@ -0,0 +1,60 @@
class AUECHO extends Shader {
AUECHO() {
name = "fxAUecho";
params.add(new Param("mode", 2, new int[]{RANDOM}));
params.add(new Param("echo", 0, 255, new int[]{SIN, LINE, RAMPUPDOWN, TAN, COS}));
params.add(new Param("decay", 0, 255, new int[]{SIN, LINE, RAMPUPDOWN, TAN, COS}));
}
/*
float inc1, inc2;
void animate() {
inc1+=.00003;
inc2+=.04;
params.get(1).setValue((sin(inc1)+1)/4);
params.get(2).setValue((sin(inc2)+1)/2);
if (random(1) > .99) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
}
}
*/
void apply() {
renderer.beginDraw();
if (params.get(0).value == 0) {
renderer.colorMode(HSB);
colorMode(HSB);
} else {
renderer.colorMode(RGB);
colorMode(RGB);
}
renderer.loadPixels();
float _delay = map(params.get(1).getValue(params.get(1).value, true), 0, 1, 0.001, 1.0);
float decay = map(params.get(2).getValue(params.get(2).value, true), 0, 1, 0.0, 1.0);
int delay = (int)(renderer.pixels.length * _delay);
color[] history = new color[renderer.pixels.length];
int blendMode = BLEND;
for ( int i = 0, l = renderer.pixels.length; i<l; i++) {
history[i] = renderer.pixels[i];
}
for ( int i = 0, l = renderer.pixels.length; i<l; i++) {
int fromPos = i-delay < 0 ? l-abs(i-delay) : i-delay;
color fromColor = history[fromPos];
float r = red(fromColor) * decay;
float g = green(fromColor) * decay;
float b = blue(fromColor) * decay;
color origColor = history[i];
color toColor = color(
r = r + red(origColor) > 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) );

renderer.pixels[i] = history[i] = toColor; //blendColor(origColor, toColor, blendMode);
}
renderer.updatePixels();
if (params.get(0).value == 0) {
renderer.colorMode(RGB);
colorMode(RGB);
}
renderer.endDraw();
}
}

+ 83
- 0
BRIGHTER.pde View File

@@ -0,0 +1,83 @@

class BRIGHTER extends Shader {

BRIGHTER() {
name = "fxBRIGHTER";

params.add(new Param("mode", 2, new int[]{RANDOM}));
params.add(new Param("thresh", 60, 180, new int[]{SIN, LINE, RAMPUPDOWN, TAN, COS}));
params.add(new Param("thresh2", 120, 200, new int[]{SIN, LINE, RAMPUPDOWN, TAN, COS}));
params.add(new Param("brighten", 140, 220, new int[]{SIN, LINE, RAMPUPDOWN, TAN, COS}));
/*
params.add(new Param("mode", 2));
params.add(new Param("thresh", 60, 180));
params.add(new Param("thresh2", 120, 200));
params.add(new Param("brighten", 140, 220));*/
}

/*
float inc1, inc2, inc3;
float speed;
void animate() {
inc1+=(speed + .006);
inc2+=(speed + .0045);
inc3+=(speed + .002);
//gui.brickP5.getController("knobOne-"+str(brick)).setValue(int(map(sin(inc1), 2, -1, 0, 255)));
//gui.brickP5.getController("knobTwo-"+str(brick)).setValue(int(map(cos(inc2), -1, 1, 0, 255)));
//if (mode == 0) {
// gui.brickP5.getController("knobThree-"+str(brick)).setValue(int(map(cos(inc2), -1, 1, 0, int(map(cos(inc2), -1, 1, 0, 255)))));
//} else if (mode == 1) {

// gui.brickP5.getController("knobThree-"+str(brick)).setValue(int(map(cos(inc2), -1, 1, int(map(cos(inc2), -1, 1, 0, 255)), 255 )));
//}

if (random(1) > .99) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
}
}
*/
void apply() {
int mode = (int)params.get(0).value;
float brighten = params.get(1).value;
float thresh = params.get(2).value;
float thresh2 = params.get(3).value;



renderer.beginDraw();
renderer.colorMode(HSB);
colorMode(HSB);
renderer.loadPixels();
if (mode == 0) {
for (int i = 0; i < renderer.width*renderer.height; i++) {
float hue = hue(renderer.pixels[i]);
float sat = saturation(renderer.pixels[i]);
float bright = brightness(renderer.pixels[i]);
if (bright < thresh && bright > thresh2) {
bright += brighten;
constrain(bright, 0, 255);
}
color c = color(hue, sat, bright);
renderer.pixels[i] = c;
}
} else if (mode == 1) {
for (int i = 0; i < renderer.width*renderer.height; i++) {
float hue = hue(renderer.pixels[i]);
float sat = saturation(renderer.pixels[i]);
float bright = brightness(renderer.pixels[i]);
if (bright > thresh && bright < thresh2) {
bright += brighten;
constrain(bright, 0, 255);
}
color c = color(hue, sat, bright);
renderer.pixels[i] = c;
}
}
renderer.updatePixels();
renderer.colorMode(RGB);
colorMode(RGB);
renderer.endDraw();
}
}

+ 74
- 0
DARKER.pde View File

@@ -0,0 +1,74 @@

class DARKER extends Shader {

DARKER() {
name = "fxDARKER";
/*
params.add(new Param ("layers", 5));
params.add(new Param ("thresh", 0, 255));
params.add(new Param ("value", 0, 255));
params.add(new Param ("mode", 2));*/
}

float inc1, inc2;
float playSpeed = 4;

void animate() {
inc1+=playSpeed/400;
inc2+=playSpeed/300;
if ((frameCount % int(map(playSpeed, 0, 4, 15, 120))) == 0) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
}
params.get(1).setValue((sin(inc1)+1)/2);
params.get(2).setValue((sin(inc2)+1)/2);
}

void apply() {
float h, s, b;
renderer.beginDraw();
renderer.colorMode(HSB);
renderer.loadPixels();
colorMode(HSB);
if (params.get(3).value == 0) {
for (int j = 1; j < params.get(0).value+1; j++) {
for (int i = 0; i < renderer.width*renderer.height; i++) {
h = hue(renderer.pixels[i]);
s = saturation(renderer.pixels[i]);
b = brightness(renderer.pixels[i]);
if (b > params.get(1).value/j);
{
if (!(h == 85.0 && s == 255.0 && b == 255.0)) {
b -= params.get(2).value/j;
constrain(b, 0, 255);
color c = color(h, s, b);
renderer.pixels[i] = c;
}
}
}
}
} else if (params.get(3).value == 1) {
for (int j = 1; j < params.get(0).value+1; j++) {
for (int i = 0; i < renderer.width*renderer.height; i++) {
h = hue(renderer.pixels[i]);
s = saturation(renderer.pixels[i]);
b = brightness(renderer.pixels[i]);

if (b < params.get(1).value/j) {
if (!(h == 85.0 && s == 255.0 && b == 255.0));
{
b -= params.get(2).value/j;
constrain(b, 0, 255);
}
}
color c = color(h, s, b);
renderer.pixels[i] = c;
}
}
}
renderer.updatePixels();
renderer.colorMode(RGB);
renderer.endDraw();
colorMode(RGB);
}
}

+ 142
- 0
DISTORTER.pde View File

@@ -0,0 +1,142 @@
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);
}
}

float inc1, inc2;
void animate() {
inc1+=.03;
inc2+=.04;
params.get(1).setValue((sin(inc1)+1)/2);
params.get(2).setValue((sin(inc2)+1)/2);
if (random(1) > .99) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
}
}

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

+ 119
- 0
DRAWGENERATIVE.pde View File

@@ -0,0 +1,119 @@
class DRAWGENERATIVE extends Shader {

// choose channel
int channel = HUE;

// run, after 30 iterations result will be saved automatically
// or press SPACE


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

int n=2000;
float [] cx=new float[n];
float [] cy=new float[n];

int len;

// working buffer
PGraphics buffer;


int tick = 0;


DRAWGENERATIVE() {
name = "fxDrawGenerative";
buffer = createGraphics(renderer.width, renderer.height);
buffer.noFill();
buffer.beginDraw();
buffer.strokeWeight(0.3);
//buffer.background(0); //ENABLE THIS TO DRAW FROM BLANK
buffer.endDraw();
rw = renderer.width;
len = (renderer.width<renderer.height?renderer.width:renderer.height)/6;

for (int i=0; i<n; i++) {
cx[i]=random(renderer.width);
cy[i]=random(renderer.height);
}
}

int rw;
void apply() {
if (rw != renderer.width) {
rw = renderer.width;
PGraphics save = createGraphics(renderer.width, renderer.height);
save.beginDraw();
save.image(buffer, 0, 0, save.width, save.height);
save.endDraw();
buffer.setSize(renderer.width, renderer.height);
buffer.beginDraw();
buffer.image(save,0,0,buffer.width,buffer.height);
buffer.endDraw();
}
buffer.beginDraw();
for (int i=1; i<n; i++) {
color c = renderer.get((int)cx[i], (int)cy[i]);
buffer.stroke(c);
buffer.point(cx[i], cy[i]);
// you can choose channels: red(c), blue(c), green(c), hue(c), saturation(c) or brightness(c)
cy[i]+=sin(map(getChannel(c), 0, 255, 0, TWO_PI));
cx[i]+=cos(map(getChannel(c), 0, 255, 0, TWO_PI));
}
if (frameCount>len) {
frameCount=0;
println("iteration: " + tick++);
for (int i=0; i<n; i++) {
cx[i]=random(renderer.width);
cy[i]=random(renderer.height);
}
}
buffer.endDraw();
renderer.beginDraw();
renderer.image(buffer, 0, 0, renderer.width, renderer.height);
renderer.endDraw();
}


float getChannel(color c) {
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;
}
}

+ 209
- 0
DRAWSTROKES.pde View File

@@ -0,0 +1,209 @@
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 calcDiff(PImage img1, PImage img2) {
int err = 0;
for (int i=0; i<img1.pixels.length; i++)
err += getStat(img1.pixels[i], img2.pixels[i]);
return err;
}

DRAWSTROKES() {
name = "fxDrawStrokes";
/*
params.add(new Param ("stat_type", 6)); //0 bis 5, 4 und 5 sind mit abstand am schnellsten
params.add(new Param ("stroke_len", 1, 15));
params.add(new Param ("angles_no", 2, 50));
params.add(new Param ("segments", 50, 1500));
params.add(new Param ("stroke_width", 0.5, 3));
params.add(new Param ("stroke_alpha", 50, 200));
*/
params.get(0).randomize();
params.get(1).randomize();
params.get(2).randomize();
params.get(3).randomize();
params.get(4).randomize();
params.get(5).randomize();




len = (renderer.width<renderer.height?renderer.width:renderer.height)/3;

buffer = createGraphics(renderer.width, renderer.height);
//buffer.smooth(8);
buffer.beginDraw();
buffer.background(255);
buffer.noFill();
buffer.endDraw();

rw = renderer.width;


reinit();
}

void reinit() {
buffer.beginDraw();
buffer.strokeWeight(stroke_width);
//buffer.background(background_color); //ENABLE THIS TO DRAW FROM BLANK
buffer.endDraw();

currx = (int)random(renderer.width);
curry = (int)random(renderer.height);

sintab = new int[angles_no];
costab = new int[angles_no];

for (int i=0; i<angles_no; i++) {
sintab[i] = (int)(stroke_len * sin(TWO_PI*i/(float)angles_no));
costab[i] = (int)(stroke_len * cos(TWO_PI*i/(float)angles_no));
}

sqwidth = stroke_len * 2 + 4;
}

void animate() {
if (random(1) > .99) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
stat_type = (int)params.get(0).value;
stroke_len = (int)params.get(1).value;
angles_no = (int)params.get(2).value;
segments = (int)params.get(3).value;
stroke_width = params.get(4).value;
stroke_alpha = (int)params.get(5).value;
reinit();
}
}

int rw;
void apply() {
if (rw != renderer.width) {
rw = renderer.width;
PGraphics save = createGraphics(renderer.width, renderer.height);
save.beginDraw();
save.image(buffer, 0, 0, save.width, save.height);
save.endDraw();
buffer.setSize(renderer.width, renderer.height);
buffer.beginDraw();
buffer.image(save, 0, 0, buffer.width, buffer.height);
buffer.endDraw();
}
currx = (int)random(renderer.width);
curry = (int)random(renderer.height);

buffer.beginDraw();
//draw whole segment using current color
buffer.stroke(renderer.get(currx, curry), stroke_alpha);

for (int iter=0; iter<segments; iter++) {
// corners of square containing new strokes
int corx = currx-stroke_len-2;
int cory = curry-stroke_len-2;

// take square from image and current screen
PImage imgpart = renderer.get(corx, cory, sqwidth, sqwidth);
PImage mypart = buffer.get(corx, cory, sqwidth, sqwidth);
imgpart.loadPixels();
mypart.loadPixels();

// calc current diff
float localerr = calcDiff(imgpart, mypart);

// chosen stroke will be here
PImage destpart = null;
int _nx=currx, _ny=curry;

// start with random angle
int i = (int)random(angles_no);
int iterangles = angles_no;

while (iterangles-- > 0) {
// take end points
int nx = currx + costab[i];
int ny = curry + sintab[i];

// if not out of the screen
if (nx>=0 && nx<renderer.width-1 && ny>=0 && ny<renderer.height-1) {
// clean region and draw line
buffer.image(mypart, corx, cory);
buffer.line(currx, curry, nx, ny);

// take region with line and calc diff
PImage curr = buffer.get(corx, cory, sqwidth, sqwidth);
curr.loadPixels();
int currerr = calcDiff(imgpart, curr);

// if better, remember this region and line endpoint
if (currerr < localerr) {
destpart = curr;
_nx = nx;
_ny = ny;
localerr = currerr;
}
}

// next angle
i = (i+1)%angles_no;
}

// if we have new stroke, draw it
if (destpart != null) {
buffer.image(destpart, corx, cory);
currx = _nx;
curry = _ny;
} else {
break; // skip
}
}

buffer.endDraw();
renderer.beginDraw();
renderer.image(buffer, 0, 0, renderer.width, renderer.height);
renderer.endDraw();
}

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;
final static int ABSDIST2 = 5;

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));
case ABSDIST2:
return abs( (red(c1)+blue(c1)+green(c1)) - (red(c2)+blue(c2)+green(c2)) );
default:
return sq(red(c1)-red(c2)) + sq(green(c1)-green(c2)) + sq(blue(c1)-blue(c2));
}
}
}

+ 249
- 0
FM.pde View File

@@ -0,0 +1,249 @@
// FM - frequency modulator
// 2016 Tomasz Sulej, generateme.blog@gmail.com, http://generateme.tumblr.com
// Licence: http://unlicense.org/

// Frequency modulation and demodulation of the image
// process goes in following way:
// - convert RGB into desired colorspace (GS - grayscale)
// For every channel
// - modulate signal
// - quantize and dequantize signal (if quantval > 0)
// - demodulate signal using derivative method
// - apply 3 lowpass filters in a chain to remove carrier (if possible)
// Combine channels and convert back to RGB

// Usage:
// * move mouse X axis - change the carrier wave frequency
// * move mouse Y axis - change bandwidth
// * click mouse to fix setup (click again to release)
// * press N to negate image
// * press SPACE to save


class FM extends Shader {
// configuration
int colorspace = RGB;
final static boolean first_channel_only = false; // for L.. or Y.. colorspaces set true to modulate only luma;
final static int quantval = 30; // 0 - off, less - more glitch, more - more precision
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;

boolean do_blend = true; // blend image after process
int blend_mode = OVERLAY; // blend type

// working buffer
PGraphics buffer;

// image
//PImage img;

// 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";
//img = loadImage(foldername+filename+fileext);
params.add(new Param ("blend_mode", 11, new int[]{RANDOM}));
params.add(new Param ("omega", 0, 1, new int[]{SIN, LINE}));
params.add(new Param ("phase", 0, 1, new int[]{LINE, SIN, TAN, RAMPUPDOWN, RAMP}));
params.get(0).randomize();
params.get(1).randomize();
params.get(2).randomize();

buffer = createGraphics(renderer.width, renderer.height);
buffer.beginDraw();
buffer.noStroke();
//buffer.smooth(8);
//buffer.background(0);
// buffer.image(renderer, 0, 0);
buffer.endDraw();

//img.loadPixels();

min_omega = TWO_PI/(0.05*renderer.width);
max_omega = TWO_PI/(300.0*renderer.width);

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);

rw = renderer.width;
prepareData();
}
//float inc1, inc2;
//float playSpeed = 4;
/*
void animate() {
blend_mode = (int)params.get(0).value + 2;
inc1+=playSpeed/400;
inc2+=playSpeed/300;
if ((frameCount % int(map(playSpeed, 0, 4, 15, 120))) == 0) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
}
params.get(1).setValue((sin(inc1)+1)/2);
params.get(2).setValue((sin(inc2)+1)/2);
}
*/
void prepareData() {
pxls = new int[3][renderer.pixels.length];
for (int i=0; i<renderer.pixels.length; i++) {
int cl = toColorspace(renderer.pixels[i], colorspace);
pxls[0][i] = (cl >> 16) & 0xff;
pxls[1][i] = (cl >> 8) & 0xff;
pxls[2][i] = (cl) & 0xff;
}
}

float omega, min_phase, max_phase;


int rw, rh;
void apply() {
if (rw != renderer.width || rh != renderer.height) {
rw = renderer.width;
rh = renderer.height;
min_omega = TWO_PI/(0.05*renderer.width);
max_omega = TWO_PI/(300.0*renderer.width);
prepareData();
}
buffer.setSize(renderer.width, renderer.height);

omega = map(sqrt(params.get(1).value), 0, 1, min_omega, max_omega);

float phase = map(sq(params.get(2).value), 0, 1, min_phase_mult, max_phase_mult);
max_phase = phase * omega;
min_phase = -max_phase;

processImage();
}

void processImage() {
buffer.beginDraw();
buffer.loadPixels();

int [][] dest_pxls = new int[3][renderer.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<renderer.height; y++) {
int off = y * renderer.width;

//reset filters each line
lpf1.resetFilter(map(pxls[i][off], 0, 255, min_phase, max_phase));
lpf2.resetFilter(map(pxls[i][off], 0, 255, min_phase, max_phase));
lpf3.resetFilter(map(pxls[i][off], 0, 255, min_phase, max_phase));

float sig_int = 0; // integral of the signal
float pre_m = 0; // previous value of modulated signal

for (int x=0; x<renderer.width; x++) {

/////////////////////////
// FM part starts here
/////////////////////////

float sig = map(pxls[i][x+off], 0, 255, min_phase, max_phase); // current signal value
sig_int += sig; // current value of signal integral

float m = cos(omega * x + sig_int); // modulate signal

if ( quantval > 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; i<buffer.pixels.length; i++) {
buffer.pixels[i] = fromColorspace(0xff000000 | (dest_pxls[0][i] << 16) | (dest_pxls[1][i] << 8) | (dest_pxls[2][i]), colorspace);
}

buffer.updatePixels();

if (do_blend)
buffer.blend(renderer, 0, 0, renderer.width, renderer.height, 0, 0, buffer.width, buffer.height, blend_mode);

buffer.endDraw();
renderer.beginDraw();
renderer.image(buffer, 0, 0, renderer.width, renderer.height);
renderer.endDraw();
}


//

final int[] blends = {
ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN
};

class LowpassFilter {
float alpha;
float prev;

public LowpassFilter(float rate, float hz) {
alpha = 0.0;
prev = 0.0;
setFilter(rate, hz);
}

void setFilter(float rate, float hz) {
float timeInterval = 1.0/rate;
float tau = 1.0 / (hz * TWO_PI);
alpha = timeInterval / (tau + timeInterval);
}

void resetFilter(float val) {
prev = val;
}

void resetFilter() {
resetFilter(0);
}

float lowpass(float sample) {
float stage1 = sample * alpha;
float stage2 = prev - (prev * alpha);
prev = (stage1 + stage2);
return prev;
}

float highpass(float sample) {
return sample - lowpass(sample);
}
}
}

+ 56
- 0
GRAUZONE.pde View File

@@ -0,0 +1,56 @@
class GRAUZONE extends Shader {
float inc1, inc2;
int nFrames = 20;
int iWrite = 0, iRead = 1;
PImage[] buffer;
PGraphics grauz;
GRAUZONE() {
name = "fxGRAUZONE";
//params.add(new Param ("discance", 3, 100));
params.get(0).setValue(.2);
buffer = new PImage[nFrames];
}
void animate() {
inc1+=.03;
inc2+=.04;
//params.get(0).setValue((sin(inc1)+1)/2);
if (random(1) > .99) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
}

iWrite++;
iRead++;
if (iRead >= nFrames-1) {
iRead = 0;
}
if (iWrite >= nFrames-1) {
iWrite = 0;
}
}
void apply() {



//buffer[iWrite] = renderer.get();
grauz = createGraphics(renderer.width, renderer.height);
grauz.beginDraw();
// grauz.resize(renderer.width, renderer.height);
buffer[iWrite] = renderer.get();
if (buffer[iRead] != null) {
grauz.tint(255, 127);
if (this.animating) {
buffer[iRead].filter(INVERT);
}
grauz.image(buffer[iRead], 0, 0, renderer.width, renderer.height);
grauz.tint(255, 255);
}
grauz.endDraw();



renderer.beginDraw();
renderer.image(grauz, 0, 0, renderer.width, renderer.height);
renderer.endDraw();
}
}

+ 188
- 0
SLITSCAN.pde View File

@@ -0,0 +1,188 @@

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(renderer.width, renderer.height, ARGB);
for (int i=0; i<32; i++) {
ft[0][i] = pow(2.0, i);
ft[1][i] = 0.5*1.0/ft[0][i];
}
}

void animate() {

buffer.resize(renderer.width, renderer.height);
buffer = renderer.get(0, 0, renderer.width, renderer.height);
int s = buffer.width>buffer.height?buffer.height:buffer.width;
depth = (int)(log(s)/log(2));
fxnum = (int)random(depth);
fynum = (int)random(depth);


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<fxnum; i++) {
//fx[i]=(int)random(6);
fx[i]=(int)random(6);
phx[i] = random(1);
skipfx[i] = random(1)<0.2;
sx[i] = random(1)<0.2?-1:1;
}
for (int i=0; i<fynum; i++) {
fy[i]=(int)random(6);
//fy[i]=6;
phy[i] = random(1);
skipfy[i] = random(1)<0.2;
sy[i] = random(1)<0.2?-1:1;
}
dox = random(1)<0.8;
doy = dox?random(1)<0.8:true;
}


void apply() {
renderer.beginDraw();
renderer.colorMode(RGB);
renderer.noStroke();
colorMode(RGB);
renderer.fill(255);
if (!this.animating) {
// buffer = createImage(renderW, renderH, ARGB);
buffer.resize(renderer.width, renderer.height);
buffer = renderer.get(0, 0, renderer.width, renderer.height);
// int s = buffer.width>buffer.height?buffer.height:buffer.width;
// depth = (int)(log(s)/log(2));
// fxnum = (int)map(knobZero, 0, 255, 0, depth);
// fynum = (int)map(knobOne, 0, 255, 0, depth);
// 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<fxnum; i++) {
// fx[i]=(int)random(6);
// phx[i] = random(1);
// skipfx[i] = random(1)<0.2;
// sx[i] = random(1)<0.2?-1:1;
// }
// for (int i=0; i<fynum; i++) {
// fy[i]=(int)random(6);
// phy[i] = random(1);
// skipfy[i] = random(1)<0.2;
// sy[i] = random(1)<0.2?-1:1;
// }
// dox = random(1)<0.8;
// doy = dox?random(1)<0.8:true;
// } else {
// println("ratatata");
// buffer = createImage(renderW, renderH, ARGB);
// buffer = renderer.get(0, 0, renderer.width, renderer.height);
}


float v=0;
for (int y=0; y<buffer.height; y++)
for (int x=0; x<buffer.width; x++) {
float iy = map(y, 0, buffer.height, 0, 1);

v=0;
if (doy) for (int i=0; i<fy.length; i++)
if (!skipfy[i]) v+=sy[i]*getValue(fy[i], iy, i, phy[i]);

float ry = 2*iy+v;
float y2 = (3*buffer.height+ry * buffer.height/2)%buffer.height;

float ix = map(x, 0, buffer.width, 0, 1);
v=0;
if (dox) for (int i=0; i<fx.length; i++)
if (!skipfx[i]) v+=sx[i]*getValue(fx[i], ix, i, phx[i]);


float rx = 2*ix+v;
float x2 = (3*buffer.width+rx * buffer.width/2)%buffer.width;

renderer.fill(buffer.get((int)x2, (int)y2));
renderer.rect(x, y, 1, 1);
}
renderer.endDraw();
}

float getValue(int fun, float idx, int freq, float phase) {
switch(fun) {
case 0:
return getSin(idx, freq, phase);
case 1:
return getSaw(idx, freq, phase);
case 2:
return getTriangle(idx, freq, phase);
case 3:
return getCutTriangle(idx, freq, phase);
case 4:
return getSquare(idx, freq, phase);
case 5:
return getNoise(idx, freq, phase);
default:
return getSin(idx, freq, phase);
}
}

float getNoise(float idx, int freq, float phase) {
return 2*ft[1][freq]*(noise((idx+phase)*ft[0][freq])-0.5);
}

float getSin(float idx, int freq, float phase) {
float p = ft[0][freq];
return ft[1][freq] * sin(idx*TWO_PI*p+phase*TWO_PI);
}

float getSaw(float idx, int freq, float phase) {
float p = ft[0][freq];
float rp = 2.0*ft[1][freq];
float p2 = p*((idx+phase+ft[1][freq])%1.0);
return rp*(p2-floor(p2)-0.5);
}

float getSquare(float idx, int freq, float phase) {
float p = ft[0][freq];
float rp = ft[1][freq];
return (((idx*p)+phase)%1.0)<0.5?rp:-rp;
}

float getTriangle(float idx, int freq, float phase) {
return 2*abs(getSaw(idx, freq, phase+0.5*ft[1][freq]))-ft[1][freq];
}

float getCutTriangle(float idx, int freq, float phase) {
return constrain(getTriangle(idx, freq, phase), -ft[1][freq+1], ft[1][freq+1]);
}
}

+ 250
- 0
WZIP.pde View File

@@ -0,0 +1,250 @@
class WZIP extends Shader {


final float sqrt05 = sqrt(0.5);

float[] raw, raw1, raw2, raw3;
float[] in, w, out;
float[] in1, in2, in3, out1, out2, out3;
int n, n2, s;
float scalingfactorin, scalingfactorout;

PImage img;
String sessionid;



WZIP() {

name = "fxWZIP";/*
params.add(new Param ("scale", 0, 1000));
params.add(new Param ("factor1", 0, 1));
params.add(new Param ("factor2", 0, 1));
params.add(new Param ("hsb", 2));
params.add(new Param ("mode", 2));
*/

sessionid = hex((int)random(0xffff), 4);
img = createImage(renderer.width, renderer.height, ARGB);
img = renderer.get(0, 0, renderer.width, renderer.height);



// printOption();
// printScale();
}

/*
float inc1, inc2;
void animate() {
inc1+=.03;
inc2+=.04;
//gui.brickP5.getController("knobZero-"+str(brick)).setValue( map(sin(inc1), -1, 1, 0, 255));
//gui.brickP5.getController("knobOne-"+str(brick)).setValue(map(cos(inc2), -1, 1, 0, 255));
if (random(1) > .99) {
for (int i = 0; i < params.size(); i++)
params.get(i).randomize();
}
}
*/
void apply() {
// img = createImage(renderer.width, renderer.height, ARGB);
img.resize(renderer.width, renderer.height);
img = renderer.get(0, 0, renderer.width, renderer.height);

s = img.width*img.height;
raw = new float[s*3];
raw1 = new float[s];
raw2 = new float[s];
raw3 = new float[s];
renderer.beginDraw();
renderer.background(0);
renderer.noStroke();
if (boolean((int)params.get(3).value)) {
renderer.colorMode(HSB, 255);
colorMode(HSB, 255);
} else {
renderer.colorMode(RGB, 255);
colorMode(RGB, 255);
}

scalingfactorin = map(params.get(1).value, 0, 1, 0, params.get(0).value);
scalingfactorout = map(params.get(2).value, 0, 1, 0, params.get(0).value);
int iter=0;
int iter2 = 0;
for (int y=0; y<img.height; y++) {
for (int x=0; x<img.width; x++) {
color c = img.get(x, y);
float r, g, b;
if (boolean((int)params.get(3).value)) {
r = hue(c)>127?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; i<n; i++) in[i] = raw[raw.length-1];

arrayCopy(raw1, 0, in1, 0, s);
arrayCopy(raw2, 0, in2, 0, s);
arrayCopy(raw3, 0, in3, 0, s);

for (int i=s; i<n2; i++) {
in1[i] = raw1[s-1];
in2[i] = raw2[s-1];
in3[i] = raw3[s-1];
}
if (boolean((int)params.get(4).value)) option1();
else option2();
renderer.colorMode(RGB);
colorMode(RGB);
renderer.endDraw();
}
// void printOption() {
// String str1, str2;
// if (do_hsb) {
// str1 = "HSBHSBHSB...";
// str2 = "HHH...SSS...BBB...";
// } else {
// str1 = "RGBRGBRGB...";
// str2 = "RRR...GGG...BBB...";
// }
// if (option1) println("channels combined: " + str1);
// else println("channels separated: " + str2);
// }
//
// void printScale() {
// println("Scale: 0.."+sc);
// }

float clamp(float c) {
return(abs(c<0?256+c:c)%255.0);
}
void option2() {
wtrafo(in1, n2);
wbtrafo(out1, n2);

wtrafo(in2, n2);
wbtrafo(out2, n2);

wtrafo(in3, n2);
wbtrafo(out3, n2);

for (int i=0; i<s; i++) {
float r = clamp(out1[i]);
float g = clamp(out2[i]);
float b = clamp(out3[i]);
renderer.fill(r, g, b);
renderer.rect(i%img.width, i/img.width, 1, 1);
}
}
void option1() {
wtrafo(in, n);
wbtrafo(out, n);

float r=0, g=0, b=0;
int state = 0;

for (int i=0; i<raw.length; i++) {
float c = clamp(out[i]);
switch(state) {
case 0:
r = c;
break;
case 1:
g = c;
break;
case 2:
b = c;
break;
default:
{
r = c;
renderer.fill(r, g, b);
renderer.rect(floor(i/3.0)%img.width, floor(i/3.0)/img.width, 1, 1);
state = 0;
}
}
state++;
}
}




void wbtrafo(float[] y, int n) {
float[] d = new float[n];
d[n-2] = w[n-1];
int b1 = n-4;
int b2 = n-2;
int a=1;
while (a<n/2) {
for (int i=0; i<a; i++) {
d[2*i+b1]=(d[i+b2]+w[i+b2])*sqrt05;
d[2*i+1+b1]=(d[i+b2]-w[i+b2])*sqrt05;
}
b2=b1;
b1=b1-4*a;
a*=2;
}

for (int i=0; i<a; i++) {
y[2*i]=(d[i]+w[i])*sqrt05;
y[2*i+1]=(d[i]-w[i])*sqrt05;
}

for (int i=0; i<n; i++) y[i] *= scalingfactorout;
}

void wtrafo(float[] y, int n) {
float[] d = new float[n];
int a = n/2;
for (int i=0; i<a; i++) {
w[i] = (y[2*i]-y[2*i+1])*sqrt05;
d[i] = (y[2*i]+y[2*i+1])*sqrt05;
}
int b1 = 0;
int b2 = a;
a/=2;
while (a>0) {
for (int i=0; i<a; i++) {
w[i+b2]=(d[2*i+b1]-d[2*i+1+b1])*sqrt05;
d[i+b2]=(d[2*i+b1]+d[2*i+1+b1])*sqrt05;
}
b1=b2;
b2=b2+a;
a/=2;
}
w[b2] = d[b1];

for (int i=0; i<n-1; i++) w[i] = (int)(w[i]/scalingfactorin);
if (w[n-1]>0) w[n-1] = (int)(w[n-1]/scalingfactorin+0.5);
else w[n-1] = (int)(w[n-1]/scalingfactorin-0.5);
}
}

+ 800
- 0
colorspaces.pde View File

@@ -0,0 +1,800 @@
//from tomasz sulej's FM effect

final static int COLORSPACES = 16;

final static int OHTA = 0;
// RGB == 1; defined in processing
final static int CMY = 2;
// HSB == 3; defined in processing
final static int XYZ = 4;
final static int YXY = 5;
final static int HCL = 6;
final static int LUV = 7;
final static int LAB = 8;
final static int HWB = 9;
final static int RGGBG = 10;
final static int YPbPr = 11;
final static int YCbCr = 12;
final static int YDbDr = 13;
final static int GS = 14;
final static int YUV = 15;

// name
String getColorspaceName(int cs) {
switch(cs) {
case OHTA:
return "OHTA";
case CMY:
return "CMY";
case XYZ:
return "XYZ";
case YXY:
return "YXY";
case HCL:
return "HCL";
case LUV:
return "LUV";
case LAB:
return "LAB";
case HWB:
return "HWB";
case HSB:
return "HSB";
case RGGBG:
return "R-GGB-G";
case YPbPr:
return "YPbPr";
case YCbCr:
return "YCbCr";
case YDbDr:
return "YDbDr";
case GS:
return "Greyscale";
case YUV:
return "YUV";
default:
return "RGB";
}
}

// colorspace converters
color fromColorspace(color c, int cs) {
switch(cs) {
case OHTA:
return fromOHTA(c);
case CMY:
return fromCMY(c);
case XYZ:
return fromXYZ(c);
case YXY:
return fromYXY(c);
case HCL:
return fromHCL(c);
case LUV:
return fromLUV(c);
case LAB:
return fromLAB(c);
case HWB:
return fromHWB(c);
case HSB:
return fromHSB(c);
case RGGBG:
return fromRGGBG(c);
case YPbPr:
return fromYPbPr(c);
case YCbCr:
return fromYCbCr(c);
case YDbDr:
return fromYDbDr(c);
case GS:
return tofromGS(c);
case YUV:
return fromYUV(c);
default:
return c;
}
}

color toColorspace(color c, int cs) {
switch(cs) {
case OHTA:
return toOHTA(c);
case CMY:
return toCMY(c);
case XYZ:
return toXYZ(c);
case YXY:
return toYXY(c);
case HCL:
return toHCL(c);
case LUV:
return toLUV(c);
case LAB:
return toLAB(c);
case HWB:
return toHWB(c);
case HSB:
return toHSB(c);
case RGGBG:
return toRGGBG(c);
case YPbPr:
return toYPbPr(c);
case YCbCr:
return toYCbCr(c);
case YDbDr:
return toYDbDr(c);
case YUV:
return toYUV(c);
case GS:
return tofromGS(c);
default:
return c;
}
}

// Colorspace converters

final int getR(color c) {
return (c & 0xff0000) >> 16;
}
final int getG(color c) {
return (c & 0xff00) >> 8;
}
final int getB(color c) {
return c & 0xff;
}

final int getLuma(color c) {
return constrain((int)(0.2126*getR(c)+0.7152*getG(c)+0.0722*getB(c)), 0, 255);
}

int getChannel(color c, int ch) {
switch(ch) {
case 0 :
return getR(c);
case 1 :
return getG(c);
case 2 :
return getB(c);
default:
return 0;
}
}

// normalized versions
final float getNR(color c) {
return r255[(c & 0xff0000) >> 16];
}
final float getNG(color c) {
return r255[(c & 0xff00) >> 8];
}
final float getNB(color c) {
return r255[c & 0xff];
}
final float getNLuma(color c) {
return r255[getLuma(c)];
}

color blendRGB(color c, int r, int g, int b) {
return (c & 0xff000000) | (constrain(r, 0, 255) << 16) | (constrain(g, 0, 255) << 8 ) | constrain(b, 0, 255);
}

color blendRGB(color c, float r, float g, float b) {
return blendRGB(c, (int)(r*255), (int)(g*255), (int)(b*255));
}

/**************
* Greyscale
**************/

color tofromGS(color c) {
int l = getLuma(c);
return blendRGB(c, l, l, l);
}

/**************
* YUV
**************/

final static float Umax = 0.436 * 255.0;
final static float Vmax = 0.615 * 255.0;

color toYUV(color c) {
int R = getR(c);
int G = getG(c);
int B = getB(c);
int Y = (int)( 0.299*R+0.587*G+0.114*B);
int U = (int)map(-0.14713*R-0.28886*G+0.436*B,-Umax,Umax,0,255);
int V = (int)map(0.615*R-0.51499*G-0.10001*B,-Vmax,Vmax,0,255);

return blendRGB(c, Y, U, V);
}

color fromYUV(color c) {
int Y = getR(c);
float U = map(getG(c),0,255,-Umax,Umax);
float V = map(getB(c),0,255,-Vmax,Vmax);
int R = (int)(Y + 1.13983*V);
int G = (int)(Y - 0.39465*U - 0.58060*V);
int B = (int)(Y + 2.03211*U);
return blendRGB(c, R, G, B);
}

/**************
* YDbDr
**************/

color toYDbDr(color c) {
int R = getR(c);
int G = getG(c);
int B = getB(c);
int Y = (int)( 0.299*R+0.587*G+0.114*B);
int Db = (int)(127.5+(-0.450*R-0.883*G+1.333*B)/2.666);
int Dr = (int)(127.5+(-1.333*R+1.116*G+0.217*B)/2.666);

return blendRGB(c, Y, Db, Dr);
}

color fromYDbDr(color c) {
int Y = getR(c);
float Db = (getG(c)-127.5)*2.666;
float Dr = (getB(c)-127.5)*2.666;
int R = (int)(Y + 9.2303716147657e-05*Db-0.52591263066186533*Dr);
int G = (int)(Y - 0.12913289889050927*Db+0.26789932820759876*Dr);
int B = (int)(Y + 0.66467905997895482*Db-7.9202543533108e-05*Dr);
return blendRGB(c, R, G, B);
}

/**************
* YCbCr
**************/

color toYCbCr(color c) {
int R = getR(c);
int G = getG(c);
int B = getB(c);
int Y = (int)( 0.2988390*R+0.5868110*G+0.1143500*B);
int Cb = (int)(-0.168736*R-0.3312640*G+0.5000000*B+127.5);
int Cr = (int)( 0.5000000*R-0.4186880*G-0.0813120*B+127.5);

return blendRGB(c, Y, Cb, Cr);
}

color fromYCbCr(color c) {
int Y = getR(c);
float Cb = getG(c) - 127.5;
float Cr = getB(c) - 127.5;
int R = (int)(Y + 1.402*Cr)+1; // some fix
int G = (int)(Y-0.344136*Cb-0.714136*Cr);
int B = (int)(Y+1.772000*Cb)+1; // some fix
return blendRGB(c, R, G, B);
}

/**************
* YPbPr
**************/

color toYPbPr(color c) {
int R = getR(c);
int B = getB(c);
int Y = getLuma(c);
int Pb = B - Y;
int Pr = R - Y;
if(Pb<0) Pb+=256;
if(Pr<0) Pr+=256;
return blendRGB(c, Y, Pb, Pr);
}

color fromYPbPr(color c) {
int Y = getR(c);
int B = getG(c) + Y;
int R = getB(c) + Y;
if(R>255) R-=256;
if(B>255) B-=256;
int G = (int)((Y-0.2126*R-0.0722*B)/0.7152);
return blendRGB(c, R, G, B);
}


/**************
* R-G,G,B-G
**************/

color toRGGBG(color c) {
int G = getG(c);
int R = getR(c)-G;
int B = getB(c)-G;
if(R<0) R+=256;
if(B<0) B+=256;
return blendRGB(c, R, G, B);
}

color fromRGGBG(color c) {
int G = getG(c);
int R = getR(c)+G;
int B = getB(c)+G;
if(R>255) R-=256;
if(B>255) B-=256;
return blendRGB(c, R, G, B);
}

/**************
* HWB
**************/

color toHSB(color c) {
int R = getR(c);
int G = getG(c);
int B = getB(c);

int _min = min(R, G, B);
int _max = max(R, G, B);
float delta = _max-_min;
float saturation = delta/_max;
float brightness = r255[_max];
if (delta == 0.0) return blendRGB(c, 0.0, saturation, brightness);
float hue = 0;
if (R == _max) hue = (G-B)/delta;
else if (G == _max) hue = 2.0 + (B-R)/delta;
else hue = 4.0 + (R-G)/delta;
hue /= 6.0;
if (hue < 0.0) hue += 1.0;
return blendRGB(c, hue, saturation, brightness);
}

color fromHSB(color c) {
float S = getNG(c);
float B = getNB(c);
if (S == 0.0) return blendRGB(c, B, B, B);

float h = 6.0 * getNR(c);
float f = h-floor(h);
float p = B*(1.0-S);
float q = B*(1.0-S*f);
float t = B*(1.0-(S*(1.0-f)));

float r, g, b;
switch((int)h) {
case 1:
r=q;
g=B;
b=p;
break;
case 2:
r=p;
g=B;
b=t;
break;
case 3:
r=p;
g=q;
b=B;
break;
case 4:
r=t;
g=p;
b=B;
break;
case 5:
r=B;
g=p;
b=q;
break;
default:
r=B;
g=t;
b=p;
break;
}
return blendRGB(c, r, g, b);
}



/**************
* HWB
**************/

color toHWB(color c) {
int R = getR(c);
int G = getG(c);
int B = getB(c);

int w = min(R, G, B);
int v = max(R, G, B);

int hue;
if (v == w) hue = 255;
else {
float f = ((R == w) ? G-B : ((G == w) ? B-R : R-G));
float p = (R == w) ? 3.0 : ((G == w) ? 5.0 : 1.0);
hue = (int)map((p-f/(v-w))/6.0, 0, 1, 0, 254);
}
return blendRGB(c, hue, w, 255-v);
}

color fromHWB(color c) {
int H = getR(c);
int B = 255-getB(c);
if (H == 255) return blendRGB(c, B, B, B);
else {
float hue = map(H, 0, 254, 0, 6);
float v = r255[B];
float whiteness = getNG(c);
int i = (int)floor(hue);
float f = hue-i;
if ((i&0x01)!= 0) f=1.0-f;
float n = whiteness+f*(v-whiteness);
float r, g, b;
switch(i) {
case 1:
r=n;
g=v;
b=whiteness;
break;
case 2:
r=whiteness;
g=v;
b=n;
break;
case 3:
r=whiteness;
g=n;
b=v;
break;
case 4:
r=n;