//globals | //globals | ||||
uptime = 117464831 | |||||
uptime = 118948355 |
/* | |||||
Webcam | |||||
*/ | |||||
boolean webcamRunning; | |||||
void startWebcam() { | |||||
String[] cameras = Capture.list(); | |||||
println("Hi"); | |||||
println(cameras); | |||||
cam.start(); | |||||
webcamRunning = true; | |||||
} | |||||
void stopWebcam() { | |||||
cam.stop(); | |||||
webcamRunning = false; | |||||
} | |||||
class WEBCAM extends Shader { | |||||
PImage img; | |||||
int rw, rh, x, y, w, h, croptop, cropbottom, cropleft, cropright, contrast, brightness, hue, saturation; | |||||
final int[] blends = {BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN}; | |||||
WEBCAM() { | |||||
rw = canvas.width; | |||||
rh = canvas.height; | |||||
name = "Webcam"; | |||||
img = createImage(rw, rh, ARGB); | |||||
if (!webcamRunning) startWebcam(); | |||||
//params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); | |||||
params.add(new Param("x", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN, })); | |||||
params.add(new Param("y", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("w", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("h", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("croptop", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("cropbottom", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("cropleft", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("cropright", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("contrast", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("brightness", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("hue", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("saturation", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN })); | |||||
params.add(new Param("blend mode", INTVAL, 0, this.blends.length-1, new int[]{RANDOM })); | |||||
} | |||||
void apply() { | |||||
rw = canvas.width; | |||||
rh = canvas.height; | |||||
x = int(params.get(0).value*rw); | |||||
y = int(params.get(1).value*rh); | |||||
w = int(params.get(2).value*(rw*2)); | |||||
h = int(params.get(3).value*(rh*2)); | |||||
if(cam.available()) img = cam.get(); | |||||
img = webcamImg.get(); | |||||
canvas.beginDraw(); | |||||
canvas.image(img, x, y, w, h); | |||||
//for ( int i = 0, l = canvas.pixels.length; i<l; i++) { | |||||
//} | |||||
canvas.endDraw(); | |||||
} | |||||
void getParams() { | |||||
} | |||||
} | |||||
/* | /* | ||||
ASDFPIXELSORT | ASDFPIXELSORT | ||||
params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | ||||
params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | ||||
params.add(new Param("seconds", FLOATVAL, 0.001, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | params.add(new Param("seconds", FLOATVAL, 0.001, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | ||||
} | |||||
} | |||||
void getParams() { | void getParams() { | ||||
gain = (int)params.get(9).value; | gain = (int)params.get(9).value; | ||||
frequency = (int)params.get(10).value; | frequency = (int)params.get(10).value; |
/* todo: | /* todo: | ||||
- implement all sox effects | |||||
- don't rerender on change of blend-mode | |||||
- add blending option everywhere | |||||
- add blend-effect to blend a selected layer | |||||
- add png corruption | |||||
- add png, jpg, gif and fractal compression artifact effects | |||||
*/ | |||||
- implement all sox effects | |||||
- don't rerender on change of blend-mode | |||||
- add blending option everywhere | |||||
- add blend-effect to blend a selected layer | |||||
- add png corruption | |||||
- add png, jpg, gif and fractal compression artifact effects | |||||
*/ | |||||
import drop.*; | import drop.*; | ||||
import controlP5.*; | import controlP5.*; | ||||
boolean spawnPlaying = false; | boolean spawnPlaying = false; | ||||
boolean autoPlay = false; | boolean autoPlay = false; | ||||
boolean videoRecord = false; | boolean videoRecord = false; | ||||
boolean webcamMode = false; | |||||
//boolean webcamMode = false; | |||||
String[] params; | String[] params; | ||||
} | } | ||||
fallbackImage = loadImage(dataPath("0.png")); | fallbackImage = loadImage(dataPath("0.png")); | ||||
bin = loadImage(dataPath("bin.png")); | bin = loadImage(dataPath("bin.png")); | ||||
cam = new Capture(this, 1280, 768); | |||||
String[] cameras = Capture.list(); | |||||
cam = new Capture(this, 1920,1080, "pipeline:autovideosrc"); | |||||
//falls du nicht mit mir in die oper möchtest gehe ich mit pe, sie hat morgen abend keine termine und würde sich natürlich in beiden fällen freuen. von ihr auch noch alles gute zum geburtstag hatte ich vergessen zu sagen. | |||||
//ich bin auch aufgeregt. vielleicht doch lieber mit dem zug. einfach versuchen sich einfach was zu gönnen. zu deinem schwarzen kleid ziehe ich | |||||
OS = getOS(); | OS = getOS(); | ||||
String[] args = {"SecondFrame"}; | String[] args = {"SecondFrame"}; | ||||
gui = new SecondApplet(); | gui = new SecondApplet(); | ||||
PApplet.runSketch(args, gui); | PApplet.runSketch(args, gui); | ||||
renderer = createGraphics(width, height); | renderer = createGraphics(width, height); | ||||
renderer.noSmooth(); | renderer.noSmooth(); | ||||
viewport = createImage(renderer.width, renderer.height, ARGB); | viewport = createImage(renderer.width, renderer.height, ARGB); | ||||
//sourceManager.importURI("/home/giers/.local/bin/fast-style-transfer/data/train2014"); | //sourceManager.importURI("/home/giers/.local/bin/fast-style-transfer/data/train2014"); | ||||
} | } | ||||
PImage webcamImg; | |||||
void captureEvent(Capture c) { | |||||
c.read(); | |||||
webcamImg = cam.get(); | |||||
} | |||||
void draw() { | void draw() { | ||||
uptime+=1; | uptime+=1; | ||||
renderFrameRate = frameRate; | renderFrameRate = frameRate; | ||||
//if(webcamRunning){ | |||||
//webcamImg = | |||||
// } | |||||
background(255); | background(255); | ||||
sourceManager.update(); //will write some image to the renderer | sourceManager.update(); //will write some image to the renderer | ||||
fill(#ff0000); | fill(#ff0000); | ||||
ellipse(width-100, height-100, 30, 30); | ellipse(width-100, height-100, 30, 30); | ||||
} | } | ||||
if (recording) { | if (recording) { |
public void settings() { | public void settings() { | ||||
size(275, 120); | size(275, 120); | ||||
} | } | ||||
Toggle webcam, auto; | |||||
//Toggle webcam, auto; | |||||
Toggle 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); | ||||
webcam = cp5.addToggle("webcam") | |||||
/* webcam = cp5.addToggle("webcam") | |||||
.setPosition(100, height-65) | .setPosition(100, height-65) | ||||
.setSize(12, 12) | .setSize(12, 12) | ||||
.setValue(false) | .setValue(false) | ||||
.plugTo(this, "CP5_webcamAction"); | .plugTo(this, "CP5_webcamAction"); | ||||
webcam.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20); | |||||
webcam.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);*/ | |||||
Toggle robot = cp5.addToggle("autoPlay") | Toggle robot = cp5.addToggle("autoPlay") | ||||
.setPosition(100, height-50) | .setPosition(100, height-50) | ||||
startRobot = true; | startRobot = true; | ||||
autoPlay = !autoPlay; | autoPlay = !autoPlay; | ||||
} | } | ||||
/* | |||||
void CP5_webcamAction() { | void CP5_webcamAction() { | ||||
webcamMode = !webcamMode; | webcamMode = !webcamMode; | ||||
if (webcamMode) sourceManager.startWebcam(); | if (webcamMode) sourceManager.startWebcam(); | ||||
else { | else { | ||||
sourceManager.stopWebcam(); | sourceManager.stopWebcam(); | ||||
source = null; | |||||
source = null; //to trigger auto-fallback next frame | |||||
} | } | ||||
} | } | ||||
*/ | |||||
void CP5_nativeResoAction() { | void CP5_nativeResoAction() { | ||||
renderSize = max(nativeResoX, nativeResoY); | renderSize = max(nativeResoX, nativeResoY); | ||||
//renderer.setSize(nativeResoX, nativeResoY); | //renderer.setSize(nativeResoX, nativeResoY); |
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(); | ||||
if(!webcamMode)fallbackImage = source; | |||||
//if(!webcamMode) fallbackImage = source; | |||||
fallbackImage = source; | |||||
nativeResoX = source.width; | nativeResoX = source.width; | ||||
nativeResoY = source.height; | nativeResoY = source.height; | ||||
//println(nativeResoX); | //println(nativeResoX); | ||||
println("Fallback"); | println("Fallback"); | ||||
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() { | void startWebcam() { | ||||
String[] cameras = Capture.list(); | String[] cameras = Capture.list(); | ||||
println(cameras); | println(cameras); | ||||
void stopWebcam() { | void stopWebcam() { | ||||
cam.stop(); | cam.stop(); | ||||
webcamMode = false; | webcamMode = false; | ||||
} | |||||
}*/ | |||||
void update() { | void update() { | ||||
/* | |||||
if (webcamMode) { | if (webcamMode) { | ||||
if (cam.available()) { | if (cam.available()) { | ||||
cam.read(); | cam.read(); | ||||
setImage(cam); | setImage(cam); | ||||
} | } | ||||
} | } | ||||
*/ | |||||
if (source == null) { | if (source == null) { | ||||
fallback(); | fallback(); | ||||
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 (webcamMode) gui.webcam.setValue(false); | |||||
if (isImage(path)) { | if (isImage(path)) { | ||||
moviePlaying = false; | moviePlaying = false; | ||||
setImage(loadImage(path)); | setImage(loadImage(path)); |
String FX[] = { | String FX[] = { | ||||
"WEBCAM", | |||||
"ASDFPIXELSORT", | "ASDFPIXELSORT", | ||||
"DISTORTER", | "DISTORTER", | ||||
"FM", | "FM", |