Browse Source

added fxSegmenter, made it easier to implement new effects

master
Victor Giers 2 years ago
parent
commit
776ef38ec8
6 changed files with 263 additions and 158 deletions
  1. 1
    1
      data/saves.sav
  2. 190
    14
      effects.pde
  3. 6
    1
      manglr2.pde
  4. 28
    107
      secondapplet.pde
  5. 4
    1
      shader.pde
  6. 34
    34
      statics_and_lists.pde

+ 1
- 1
data/saves.sav View File

@@ -1,2 +1,2 @@
//globals
uptime = 116912351
uptime = 116968492

+ 190
- 14
effects.pde View File

@@ -1009,22 +1009,27 @@ class SLITSCAN extends Shader {
boolean dox, doy;
PImage buffer;
float[][] ft = new float[2][32];
int depth; // number of octaves
//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;

buffer = createImage(canvas.width, canvas.height, ARGB);
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);
@@ -1035,12 +1040,20 @@ class SLITSCAN extends Shader {
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 = 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}));
}

fxnum = (int)random(depth); ////
fynum = (int)random(depth); ////
//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];
@@ -1050,24 +1063,27 @@ class SLITSCAN extends Shader {
phy = new float[fynum+1];
skipfx = new boolean[fxnum+1];
skipfy = new boolean[fynum+1];
for (int i=0; i<fxnum; i++) {



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;

//dox = random(1)<0.8;
//doy = dox?random(1)<0.8:true;
dox = true;
doy = true;


float v=0;
@@ -3311,8 +3327,8 @@ class LENS extends Shader {
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, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
params.add(new Param("curvature factor y", FLOATVAL, 0, 1, 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;

@@ -4061,3 +4077,163 @@ class STREAKER extends Shader {
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;
// }
}
}

+ 6
- 1
manglr2.pde View File

@@ -8,6 +8,7 @@ import java.awt.event.KeyListener;
import processing.video.*;
import com.hamoid.*;

Class<?> sketchClass;
VideoExport videoExport;

int maxFx = 15; //possible amount of effect layers
@@ -38,8 +39,11 @@ void dropEvent(DropEvent theDropEvent) {
}

SecondApplet gui;
PApplet mainApplet;
void setup() {
mainApplet = this;
sketchClass = getClass();
println(sketchClass);
size(800, 600);
w = width;
h = height;
@@ -64,6 +68,7 @@ void setup() {
cam = new Capture(this, 1280, 768);

String[] args = {"SecondFrame"};
//gui = new SecondApplet(this);
gui = new SecondApplet();
PApplet.runSketch(args, gui);


+ 28
- 107
secondapplet.pde View File

@@ -14,13 +14,21 @@ public class SecondApplet extends PApplet {
ArrayList<Brick> bricks = new ArrayList<Brick>();
ArrayList<Slider> slider = new ArrayList<Slider>(); //brick
int binX, binY, binS;
//PApplet parent;
/*SecondApplet(PApplet _parent){
super();
this.parent = _parent;
}*/
public void settings() {
size(275, 120);
}
Toggle webcam, auto;
public void setup() {
surface.setLocation(285, 240);
List l = Arrays.asList(availableFx);
//List l = Arrays.asList(availableFx);
List l = Arrays.asList(FX);
cp5 = new ControlP5(this);
cp5.addScrollableList("")
.setPosition(10, height-110)
@@ -264,17 +272,17 @@ public class SecondApplet extends PApplet {
else
renderSizeChanged = false;
for (int i = 0; i < shaderList.size(); i++) {
try {
//try {

shaderList.get(i).getValuesFromGUI();
if (bricks.get(i).active) {
//shaderList.get(i).getValuesFromGUI();
shaderList.get(i).shade();
}
}
catch(Exception e) {
println("Warning: Brick not yet loaded");
}
//}
//catch(Exception e) {
// println("Warning: Brick not yet loaded");
//}
if (i > maxFx) break;
}
}
@@ -600,108 +608,21 @@ public class SecondApplet extends PApplet {
}
}

void addByID(int id) {
if (shaderList.size() < maxFx) {
switch(id) {
case(0):
shaderManager.addShader(new ASDFPIXELSORT());
break;
case(1):
shaderManager.addShader(new DISTORTER());
break;
case(2):
shaderManager.addShader(new FM());
break;
case(3):
shaderManager.addShader(new WZIP());
break;
case(4):
shaderManager.addShader(new AUECHO());
break;
case(5):
shaderManager.addShader(new SLITSCAN());
break;
case(6):
shaderManager.addShader(new WAHWAH());
break;
case(7):
shaderManager.addShader(new PHASER());
break;
case(8):
shaderManager.addShader(new ECHO());
break;
case(9):
shaderManager.addShader(new DARKER());
break;
case(10):
shaderManager.addShader(new BRIGHTER());
break;
case(11):
shaderManager.addShader(new AMPLIFY());
break;
case(12):
shaderManager.addShader(new BROKENCOLORROT());
break;
case(13):
shaderManager.addShader(new POSTER());
break;
case(14):
shaderManager.addShader(new DUAL());
break;
case(15):
shaderManager.addShader(new GRAUZONE());
break;
case(16):
shaderManager.addShader(new COPYZOOM());
break;
case(17):
shaderManager.addShader(new SUBTLESORT());
break;
case(18):
shaderManager.addShader(new SCANKER());
break;
case(19):
shaderManager.addShader(new MASK());
break;
case(20):
shaderManager.addShader(new DRAWSTROKES());
break;
case(21):
shaderManager.addShader(new DRAWGENERATIVE());
break;
case(22):
shaderManager.addShader(new PIXELDRIFTER());
break;
case(23):
shaderManager.addShader(new DRIPDRIP());
break;
case(24):
shaderManager.addShader(new WRONGQSORT());
break;
case(25):
shaderManager.addShader(new VHS());
break;
case(26):
shaderManager.addShader(new LZ7());
break;
case(27):
shaderManager.addShader(new LENS());
break;
case(28):
shaderManager.addShader(new SLICER());
break;
case(29):
shaderManager.addShader(new STREAKER());
break;
/*
case(4):
shaderManager.addShader(new AUECHO());
break;
*/
default:
break;
}
void addByName(String name) {
Class<?> shaderChildClass = null;
Shader s = null;
try {
shaderChildClass = Class.forName(sketchClass.getName() + "$" + name);
s = (Shader) shaderChildClass.getDeclaredConstructor(sketchClass).newInstance(mainApplet);
shaderManager.addShader(s);
}
catch (final ReflectiveOperationException ex) {
System.err.println(ex);
}
}

void addByID(int id) {
addByName(FX[id]);
}

void mousePressed() {

+ 4
- 1
shader.pde View File

@@ -135,7 +135,7 @@ class Shader {
result.endDraw();
if (pos == gui.bricks.size()-1) {
//println("Finished rendering");
if (imageChanged) { //kind of hacky but it does synchronize the threads.
if (imageChanged) { //kind of hacky but it does synchronize the threads. sometimes.
stepOne++;
if (stepOne == 2) {
stepOne = 0;
@@ -144,5 +144,8 @@ class Shader {
}
}
}
@ Override String toString() {
return getClass().getName();
}
}
int stepOne = 0;

+ 34
- 34
statics_and_lists.pde View File

@@ -1,3 +1,37 @@
String FX[] = {
"ASDFPIXELSORT",
"DISTORTER",
"FM",
"WZIP",
"AUECHO",
"SLITSCAN",
"WAHWAH",
"PHASER",
"ECHO",
"DARKER",
"BRIGHTER",
"AMPLIFY",
"POSTER",
"DUAL",
"GRAUZONE",
"COPYZOOM",
"SUBTLESORT",
"SCANKER",
"MASK",
"DRAWSTROKES",
"DRAWGENERATIVE",
"PIXELDRIFTER",
"DRIPDRIP",
"WRONGQSORT",
"VHS",
"LZ7",
"LENS",
"SLICER",
"STREAKER",
"SEGMENTER"
};


//parameter return values
final static int INTVAL = 100;
final static int FLOATVAL = 101;
@@ -69,40 +103,6 @@ final static int GS = 14;
final static int YUV = 15;


//available shaders
String availableFx[] = {
"fxASDFPixelSort",
"fxDistorter",
"fxFM",
"fxWZIP",
"fxAuEcho",
"fxSlitscan",
"fxWahWah",
"fxPhaser",
"fxEcho",
"fxDarker",
"fxBrighter",
"fxAmplify",
"fxBrokenColorRot",
"fxPosterize",
"fxDual",
"fxGrauzone",
"fxCopyZoom",
"fxSubtleSort",
"fxScanker",
"Mask",
"fxDrawStrokes",
"fxDrawGenerative",
"fxPixelDrifter",
"fxDripDrip",
"fxWrongQSort",
"fxVHS",
"fxLZ77",
"fxLens",
"fxSlicer",
"fxStreaker"
};



// helper functions and classes

Loading…
Cancel
Save