added webcam-mode and autoplay-mode

This commit is contained in:
2022-07-28 11:02:32 +02:00
parent 700f2593dc
commit 3b59eb8827
4 changed files with 142 additions and 46 deletions

View File

@@ -3107,7 +3107,7 @@ class LZ7 extends Shader {
buffer.beginDraw(); buffer.beginDraw();
print("Preparing... "); //print("Preparing... ");
img.loadPixels(); img.loadPixels();
int iter=0; int iter=0;
@@ -3124,28 +3124,27 @@ class LZ7 extends Shader {
} }
iter++; iter++;
} }
println("done"); //println("done");
print("Glitching channel 1... "); //print("Glitching channel 1... ");
comp1.doCompress(cr); comp1.doCompress(cr);
comp1.glitch( (int)number_of_glitches[0][0], number_of_glitches[0][1] ); comp1.glitch( (int)number_of_glitches[0][0], number_of_glitches[0][1] );
comp1.doDecompress(cr); comp1.doDecompress(cr);
println("done"); //println("done");
print("Glitching channel 2... "); //print("Glitching channel 2... ");
comp2.doCompress(cg); comp2.doCompress(cg);
comp2.glitch( (int)number_of_glitches[1][0], number_of_glitches[1][1] ); comp2.glitch( (int)number_of_glitches[1][0], number_of_glitches[1][1] );
comp2.doDecompress(cg); comp2.doDecompress(cg);
println("done"); //println("done");
print("Glitching channel 3... "); //print("Glitching channel 3... ");
comp3.doCompress(cb); comp3.doCompress(cb);
comp3.glitch( (int)number_of_glitches[2][0], number_of_glitches[2][1] ); comp3.glitch( (int)number_of_glitches[2][0], number_of_glitches[2][1] );
comp3.doDecompress(cb); comp3.doDecompress(cb);
println("done"); //println("done");
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
println("Channel "+(i+1)+" = ("+compressor_attributes[i][0]+","+compressor_attributes[i][1]+")" //println("Channel "+(i+1)+" = ("+compressor_attributes[i][0]+","+compressor_attributes[i][1]+")" + ", glitches = ("+number_of_glitches[i][0]+","+number_of_glitches[i][1]+")");
+ ", glitches = ("+number_of_glitches[i][0]+","+number_of_glitches[i][1]+")");
} }
buffer.loadPixels(); buffer.loadPixels();
@@ -3576,8 +3575,8 @@ class SLICER extends Shader {
stat_type = (int)params.get(11).value; stat_type = (int)params.get(11).value;
fixed_rotation = boolean((int)params.get(12).value); fixed_rotation = boolean((int)params.get(12).value);
println(""); //println("");
println("Processing..."); //println("Processing...");
edges.clear(); edges.clear();
makeEdges(); makeEdges();
calculateSegmentation(); calculateSegmentation();
@@ -3811,7 +3810,7 @@ class SLICER extends Shader {
} }
} }
println("Segments: " +num); //println("Segments: " +num);
} }

View File

@@ -20,12 +20,14 @@ String frameName; //to save frame as image
int uptime; //logs how many frames this software has rendered before (inaccurate, it's actually way, way more) int uptime; //logs how many frames this software has rendered before (inaccurate, it's actually way, way more)
boolean recording; //save every frame? boolean recording; //save every frame?
int renderSize = 500; //px int renderSize = 500; //px
float renderFrameRate;
String[] saveData; String[] saveData;
int w, h; int w, h;
boolean spawnPlaying = true; boolean spawnPlaying = false;
boolean autoPlay = false;
boolean videoRecord; boolean videoRecord = false;
boolean webcamMode = false;
String[] params; String[] params;
@@ -59,7 +61,7 @@ void setup() {
} }
fallbackImage = loadImage(dataPath("0.png")); fallbackImage = loadImage(dataPath("0.png"));
bin = loadImage(dataPath("bin.png")); bin = loadImage(dataPath("bin.png"));
cam = new Capture(this, 800, 600);
String[] args = {"SecondFrame"}; String[] args = {"SecondFrame"};
gui = new SecondApplet(); gui = new SecondApplet();
@@ -74,10 +76,12 @@ void setup() {
void draw() { void draw() {
uptime+=1; uptime+=1;
renderFrameRate = frameRate;
background(255); background(255);
sourceManager.update(); //will write some image to the renderer sourceManager.update(); //will write some image to the renderer
sourceManager.setSource(); sourceManager.setSource();
if (autoPlay) gui.robot();
gui.shaderManager.applyShader(); //boolean animate (iterative calcs), boolean apply (draw) gui.shaderManager.applyShader(); //boolean animate (iterative calcs), boolean apply (draw)
background(color(0)); background(color(0));

View File

@@ -17,7 +17,7 @@ public class SecondApplet extends PApplet {
public void settings() { public void settings() {
size(275, 120); size(275, 120);
} }
Toggle webcam, auto;
public void setup() { public void setup() {
surface.setLocation(285, 240); surface.setLocation(285, 240);
List l = Arrays.asList(availableFx); List l = Arrays.asList(availableFx);
@@ -30,30 +30,50 @@ public class SecondApplet extends PApplet {
.plugTo(this, "CP5_listActions") .plugTo(this, "CP5_listActions")
.addItems(l) .addItems(l)
.setType(ControlP5.LIST); .setType(ControlP5.LIST);
Toggle rec = cp5.addToggle("record") Toggle rec = cp5.addToggle("record")
.setPosition(100, height-105) .setPosition(100, height-110)
.setSize(15, 15) .setSize(12, 12)
.plugTo(this, "CP5_recordAction"); .plugTo(this, "CP5_recordAction");
rec.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20); rec.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
Toggle auto = cp5.addToggle("spawn playing") auto = cp5.addToggle("spawn playing")
.setPosition(100, height-85) .setPosition(100, height-95)
.setSize(15, 15) .setSize(12, 12)
.setValue(true) .setValue(false)
.plugTo(this, "CP5_spawnPlayingAction"); .plugTo(this, "CP5_spawnPlayingAction");
auto.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20); auto.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
Bang pauseAll = cp5.addBang("pause all") Bang pauseAll = cp5.addBang("pause all")
.setPosition(100, height-65) .setPosition(100, height-80)
.setSize(15, 15) .setSize(12, 12)
.plugTo(this, "CP5_pauseAllAction"); .plugTo(this, "CP5_pauseAllAction");
pauseAll.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20); pauseAll.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
webcam = cp5.addToggle("webcam")
.setPosition(100, height-65)
.setSize(12, 12)
.setValue(false)
.plugTo(this, "CP5_webcamAction");
webcam.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
Toggle robot = cp5.addToggle("autoPlay")
.setPosition(100, height-50)
.setSize(12, 12)
.setValue(false)
.plugTo(this, "CP5_robotAction");
robot.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
Bang nativeReso = cp5.addBang("native reso") Bang nativeReso = cp5.addBang("native reso")
.setPosition(220, height-35) .setPosition(220, height-35)
.setSize(15, 15) .setSize(12, 12)
.plugTo(this, "CP5_nativeResoAction"); .plugTo(this, "CP5_nativeResoAction");
//nativeReso.getCaptionLabel().getStyle().setMargin(-17,0,0,20); nativeReso.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
/* /*
Toggle saveParams = cp5.addToggle("save parameters") Toggle saveParams = cp5.addToggle("save parameters")
@@ -69,6 +89,20 @@ public class SecondApplet extends PApplet {
binS = 40; binS = 40;
} }
void CP5_robotAction()  {
startRobot = true;
autoPlay = !autoPlay;
}
void CP5_webcamAction()  {
webcamMode = !webcamMode;
if (webcamMode) sourceManager.startWebcam();
else {
sourceManager.stopWebcam();
source = null;
}
}
void CP5_nativeResoAction() { void CP5_nativeResoAction() {
renderSize = max(nativeResoX, nativeResoY); renderSize = max(nativeResoX, nativeResoY);
//renderer.setSize(nativeResoX, nativeResoY); //renderer.setSize(nativeResoX, nativeResoY);
@@ -91,14 +125,15 @@ public class SecondApplet extends PApplet {
int totalBrickHeight; int totalBrickHeight;
public void draw() { public void draw() {
background(68, 68, 68);
background(68, 68, 68);
pushMatrix(); pushMatrix();
if (heightOverLimit) { if (heightOverLimit) {
translate(0, scrollAmount); translate(0, scrollAmount);
} }
totalBrickHeight = 0; totalBrickHeight = 0;
for (int i = 0; i < shaderList.size(); i++) { for (int i = 0; i < bricks.size(); i++) {
bricks.get(i).update(); bricks.get(i).update();
bricks.get(i).display(); bricks.get(i).display();
//bricks.get(i).y = totalBrickHeight; ????? what was that for //bricks.get(i).y = totalBrickHeight; ????? what was that for
@@ -119,7 +154,7 @@ public class SecondApplet extends PApplet {
strokeWeight(1); strokeWeight(1);
textSize(25); textSize(25);
fill(255); fill(255);
text(renderer.width + "x" + renderer.height, 100, height-18); text(renderer.width + "x" + renderer.height, 100, height-15);
textSize(10); textSize(10);
line(0, height-120, width, height-120); line(0, height-120, width, height-120);
@@ -530,8 +565,45 @@ public class SecondApplet extends PApplet {
//CP5 //CP5
void CP5_listActions(int n) { void CP5_listActions(int n) {
addByID(n);
}
boolean startRobot;
void robot() {
if (startRobot) {
if (!spawnPlaying) {
auto.setValue(true);
}
}
startRobot = false;
println(renderFrameRate);
if (renderFrameRate > 5) {
renderSize+=2;
} else {
if (renderSize >= 45) renderSize-=15;
}
if (shaderList.size() == 0) {
println("adding");
addByID((int)random(29));
}
if (random(1)<0.01) {
println("adding");
addByID((int)random(29));
}
if (random(1)<0.01) {
int removeMe = int(random(shaderList.size()-1));
println("removing" + removeMe);
bricks.get(removeMe).press();
shaderManager.removeShader(removeMe);
pressedBrick = -1;
}
}
void addByID(int id) {
if (shaderList.size() < maxFx) { if (shaderList.size() < maxFx) {
switch(n) { switch(id) {
case(0): case(0):
shaderManager.addShader(new ASDFPIXELSORT()); shaderManager.addShader(new ASDFPIXELSORT());
break; break;
@@ -659,7 +731,7 @@ public class SecondApplet extends PApplet {
bricks.get(pressedBrick).dragging = true; bricks.get(pressedBrick).dragging = true;
for (int i = 0; i < bricks.size(); i++) { for (int i = 0; i < bricks.size(); i++) {
if (pressedBrick != i && bricks.get(i).hovering) { if (pressedBrick != i && bricks.get(i).hovering && mouseY < height-120) {
bricks.get(i).dragHovering = true; bricks.get(i).dragHovering = true;
} else { } else {
bricks.get(i).dragHovering = false; bricks.get(i).dragHovering = false;
@@ -674,17 +746,19 @@ public class SecondApplet extends PApplet {
for (int i = 0; i < bricks.size(); i++) { for (int i = 0; i < bricks.size(); i++) {
bricks.get(i).dragHovering = false; bricks.get(i).dragHovering = false;
if (pressedBrick != i) { if (mouseY < height-120) {
if (bricks.get(i).hovering && !bricks.get(i).hoveringLineAbove && !bricks.get(i).hoveringLineBelow) { if (pressedBrick != i) {
shaderManager.swapShader(pressedBrick, i); if (bricks.get(i).hovering && !bricks.get(i).hoveringLineAbove && !bricks.get(i).hoveringLineBelow) {
} shaderManager.swapShader(pressedBrick, i);
}
if (pressedBrick != i-1 && bricks.get(i).hoveringLineAbove) { if (pressedBrick != i-1 && bricks.get(i).hoveringLineAbove) {
shaderManager.moveShader(pressedBrick, i); shaderManager.moveShader(pressedBrick, i);
break; break;
} }
if (bricks.get(i).hoveringLineBelow) { if (bricks.get(i).hoveringLineBelow) {
shaderManager.moveShader(pressedBrick, bricks.size()); //move to last shaderManager.moveShader(pressedBrick, bricks.size()); //move to last
}
} }
} }
} }

View File

@@ -38,10 +38,10 @@ class SourceManager { //no constructor
void setImage(PImage img) { //set image to source void setImage(PImage img) { //set image to source
imageChanged = true; imageChanged = true;
source = img.get(); source = img.get();
fallbackImage = source; //fallbackImage = source;
nativeResoX = source.width; nativeResoX = source.width;
nativeResoY = source.height; nativeResoY = source.height;
println(nativeResoX); //println(nativeResoX);
} }
void fallback() { void fallback() {
@@ -49,7 +49,25 @@ class SourceManager { //no constructor
setImage(fallbackImage); //fallbackImage should always be a copy of the last image that worked setImage(fallbackImage); //fallbackImage should always be a copy of the last image that worked
} }
void startWebcam() {
String[] cameras = Capture.list();
println(cameras);
cam.start();
webcamMode = true;
}
void stopWebcam() {
cam.stop();
webcamMode = false;
}
void update() { void update() {
if (webcamMode) {
if (cam.available()) {
cam.read();
setImage(cam);
}
}
if (source == null) { if (source == null) {
fallback(); fallback();
} }
@@ -105,6 +123,7 @@ class SourceManager { //no constructor
if (isImage(path) || isVideo(path)) { if (isImage(path) || isVideo(path)) {
println("Importing file " + path); println("Importing file " + path);
if (moviePlaying) movie.stop(); if (moviePlaying) movie.stop();
if (webcamMode) gui.webcam.setValue(false);
if (isImage(path)) { if (isImage(path)) {
moviePlaying = false; moviePlaying = false;
setImage(loadImage(path)); setImage(loadImage(path));