We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I had posted a similar question but I still have not solved the problem. I am currently trying to get different glitches to happen while using the webcam to distort the image. My problem is that I have found a few different codes, but I am very new to the program. Basically I want the Webcam to run as normal, but every 10 seconds I wan a glitch to go off for about 2 seconds. I have found different codes for different glitches, but I cannot put them together for the life of me. I have looked up online and have found nothing that can help me so far. So basically, I would need help with three things: 1)How do I get the glitch to activate every 10 seconds for 2 seconds automatically? 2)Can I get two or more glitches to alternate randomly? 3)How do I put them together in one code?
Here's the first code that I have. This is the camera running, and white noise that goes off for a millisecond (I don't know how to make it longer) when I press the mouse button. I want the white noise to activate on its own. This is the most important part, if you can help me with this then I'd be the happiest man on earth.
import processing.video.*;
Capture cam;
void setup() {
size(1024, 768);
cam = new Capture(this);
cam.start();
}
void draw() {
if (cam.available()) {
// Reads the new frame
cam.read();
}
image(cam, 0, 0);
}
void mousePressed() {
loadPixels();
for( int i=0; i<pixels.length; i++)
pixels[i] = color( random(255) );
updatePixels();
}
This is a bit of extra help I need, but is not as important as the previous one. How can I add this effect, to the previous code so the white nose and this one alternates? I don't need the part of the code that saves the image when you click.
import processing.video.*;
Capture cam;
int N=0;
void setup(){
size (851,315);
background(255);
colorMode(HSB);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
cam = new Capture(this, cameras[0]);
cam.start();
}
}
void draw(){
Set();
if (cam.available() == true) {
if(frameCount==2||frameCount%150==0){
cam.read();
image(cam, 0, 0);
set(width, height, cam);
for (int i=0; i<100;i++){
noStroke();
fill(random(0,360),300,300,100);
rect ((random (0, width)),(random (0, height)),(random (0,50)),(random(0,50)));
}
}
}
}
int r(int a){
return int(random(a));
}
void mouseReleased (){
N++;
save("glitchCamera"+ (N)+".tif");
}
void Set() {
for (int i=0; i<10; i++) {
int x = r(width);
int y = r(height);
set(x+r(50)-1,y+r(3)-1,get(x,y,r(99),r(30)));
}
}
Honestly if you can help me out, I swear that you can pm me and I'll go to you and get you a beer. (J.k. I don't own a car, but I will gladly give credits in my final project).
Answers
Study the following code.
Kf
Alright, I was able to make some changes to the code. Here is what I am trying to do:
The problem now is that I can't have the camera running for the second statement. Do you think you could help me?
No, you shouldn't access the cam as you do in line 83. Everything is being done by the callback function captureEvent(). Instead, just access the cam object directly. The capture class extends from PImage, so you manage your cam object as any other PImage object. Try this:
Kf