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();
print("Preparing... ");
//print("Preparing... ");
img.loadPixels();
int iter=0;
@@ -3124,28 +3124,27 @@ class LZ7 extends Shader {
}
iter++;
}
println("done");
//println("done");
print("Glitching channel 1... ");
//print("Glitching channel 1... ");
comp1.doCompress(cr);
comp1.glitch( (int)number_of_glitches[0][0], number_of_glitches[0][1] );
comp1.doDecompress(cr);
println("done");
//println("done");
print("Glitching channel 2... ");
//print("Glitching channel 2... ");
comp2.doCompress(cg);
comp2.glitch( (int)number_of_glitches[1][0], number_of_glitches[1][1] );
comp2.doDecompress(cg);
println("done");
//println("done");
print("Glitching channel 3... ");
//print("Glitching channel 3... ");
comp3.doCompress(cb);
comp3.glitch( (int)number_of_glitches[2][0], number_of_glitches[2][1] );
comp3.doDecompress(cb);
println("done");
//println("done");
for (int i = 0; i < 3; i++) {
println("Channel "+(i+1)+" = ("+compressor_attributes[i][0]+","+compressor_attributes[i][1]+")"
+ ", glitches = ("+number_of_glitches[i][0]+","+number_of_glitches[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]+")");
}
buffer.loadPixels();
@@ -3576,8 +3575,8 @@ class SLICER extends Shader {
stat_type = (int)params.get(11).value;
fixed_rotation = boolean((int)params.get(12).value);
println("");
println("Processing...");
//println("");
//println("Processing...");
edges.clear();
makeEdges();
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)
boolean recording; //save every frame?
int renderSize = 500; //px
float renderFrameRate;
String[] saveData;
int w, h;
boolean spawnPlaying = true;
boolean videoRecord;
boolean spawnPlaying = false;
boolean autoPlay = false;
boolean videoRecord = false;
boolean webcamMode = false;
String[] params;
@@ -59,7 +61,7 @@ void setup() {
}
fallbackImage = loadImage(dataPath("0.png"));
bin = loadImage(dataPath("bin.png"));
cam = new Capture(this, 800, 600);
String[] args = {"SecondFrame"};
gui = new SecondApplet();
@@ -74,15 +76,17 @@ void setup() {
void draw() {
uptime+=1;
renderFrameRate = frameRate;
background(255);
sourceManager.update(); //will write some image to the renderer
sourceManager.setSource();
if (autoPlay) gui.robot();
gui.shaderManager.applyShader(); //boolean animate (iterative calcs), boolean apply (draw)
background(color(0));
viewport = renderer.get();
int imgw, imgh;
if (renderer.width < renderer.height) {
imgh = height;

View File

@@ -17,7 +17,7 @@ public class SecondApplet extends PApplet {
public void settings() {
size(275, 120);
}
Toggle webcam, auto;
public void setup() {
surface.setLocation(285, 240);
List l = Arrays.asList(availableFx);
@@ -30,30 +30,50 @@ public class SecondApplet extends PApplet {
.plugTo(this, "CP5_listActions")
.addItems(l)
.setType(ControlP5.LIST);
Toggle rec = cp5.addToggle("record")
.setPosition(100, height-105)
.setSize(15, 15)
.setPosition(100, height-110)
.setSize(12, 12)
.plugTo(this, "CP5_recordAction");
rec.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
Toggle auto = cp5.addToggle("spawn playing")
.setPosition(100, height-85)
.setSize(15, 15)
.setValue(true)
auto = cp5.addToggle("spawn playing")
.setPosition(100, height-95)
.setSize(12, 12)
.setValue(false)
.plugTo(this, "CP5_spawnPlayingAction");
auto.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
Bang pauseAll = cp5.addBang("pause all")
.setPosition(100, height-65)
.setSize(15, 15)
.setPosition(100, height-80)
.setSize(12, 12)
.plugTo(this, "CP5_pauseAllAction");
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")
.setPosition(220, height-35)
.setSize(15, 15)
.setSize(12, 12)
.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")
@@ -69,6 +89,20 @@ public class SecondApplet extends PApplet {
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() {
renderSize = max(nativeResoX, nativeResoY);
//renderer.setSize(nativeResoX, nativeResoY);
@@ -91,14 +125,15 @@ public class SecondApplet extends PApplet {
int totalBrickHeight;
public void draw() {
background(68, 68, 68);
background(68, 68, 68);
pushMatrix();
if (heightOverLimit) {
translate(0, scrollAmount);
}
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).display();
//bricks.get(i).y = totalBrickHeight; ????? what was that for
@@ -119,7 +154,7 @@ public class SecondApplet extends PApplet {
strokeWeight(1);
textSize(25);
fill(255);
text(renderer.width + "x" + renderer.height, 100, height-18);
text(renderer.width + "x" + renderer.height, 100, height-15);
textSize(10);
line(0, height-120, width, height-120);
@@ -530,8 +565,45 @@ public class SecondApplet extends PApplet {
//CP5
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) {
switch(n) {
switch(id) {
case(0):
shaderManager.addShader(new ASDFPIXELSORT());
break;
@@ -659,7 +731,7 @@ public class SecondApplet extends PApplet {
bricks.get(pressedBrick).dragging = true;
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;
} else {
bricks.get(i).dragHovering = false;
@@ -674,17 +746,19 @@ public class SecondApplet extends PApplet {
for (int i = 0; i < bricks.size(); i++) {
bricks.get(i).dragHovering = false;
if (pressedBrick != i) {
if (bricks.get(i).hovering && !bricks.get(i).hoveringLineAbove && !bricks.get(i).hoveringLineBelow) {
shaderManager.swapShader(pressedBrick, i);
}
if (mouseY < height-120) {
if (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) {
shaderManager.moveShader(pressedBrick, i);
break;
}
if (bricks.get(i).hoveringLineBelow) {
shaderManager.moveShader(pressedBrick, bricks.size()); //move to last
if (pressedBrick != i-1 && bricks.get(i).hoveringLineAbove) {
shaderManager.moveShader(pressedBrick, i);
break;
}
if (bricks.get(i).hoveringLineBelow) {
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
imageChanged = true;
source = img.get();
fallbackImage = source;
//fallbackImage = source;
nativeResoX = source.width;
nativeResoY = source.height;
println(nativeResoX);
//println(nativeResoX);
}
void fallback() {
@@ -49,7 +49,25 @@ class SourceManager { //no constructor
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() {
if (webcamMode) {
if (cam.available()) {
cam.read();
setImage(cam);
}
}
if (source == null) {
fallback();
}
@@ -105,6 +123,7 @@ class SourceManager { //no constructor
if (isImage(path) || isVideo(path)) {
println("Importing file " + path);
if (moviePlaying) movie.stop();
if (webcamMode) gui.webcam.setValue(false);
if (isImage(path)) {
moviePlaying = false;
setImage(loadImage(path));