Hi there,
I dunno if this the correct place to post this, but I'm having trouble figuring out the codes I'm using. For a Uni assignment, we are supposed to create a glitch. my aim is a threshold camera viewing it as real reflection, and there supposed to be a bug walking around. The bug has this detection, and once you touch it, a mirrored camera will appear but will constantly cross back and forth rapidly between the threshold camera and the real colour mirrored camera making it a glitch.
I managed to make the glitch in a processing.video.* format but with a keyPressed, but want the bug to have the detection which is in the hypermedia.video.* format... is there a way to combine it together?
the processing.video.* format with the bug and the glitchy camera
Code:float x;
float y;
float xa;
float ya;
float xz = 100;
float yz = 100;
float angle1 = 0.0;
float segLength = 10;
import processing.video.*;
color black = color(0);
color white = color(255);
int numPixels;
Capture video;
PImage displayFrame;
boolean mirror;
void setup() {
size (640, 480);
strokeWeight(20.0);
stroke(0, 255);
video = new Capture (this, width, height, 24);
numPixels = video.width * video.height;
noCursor();
smooth();
displayFrame = new PImage(width, height);
mirror = false;
}
void draw() {
displayFrame.copy(video,0, 0, width, height, 0, 0, width, height);
if(mirror)
translate(width, 0);
scale(-1, 1);
image(displayFrame, 0, 0);
if (video.available()) {
video.read();
video.loadPixels();
int threshold = 150;
float pixelBrightness;
loadPixels();
for (int i = 0; i < numPixels; i++) {
pixelBrightness = brightness(video.pixels[i]);
if (pixelBrightness > threshold) {
pixels[i] = white;
} else {
pixels[i] = black;
}
}
updatePixels();
int testValue = get (mouseX, mouseY);
float testBrightness = brightness(testValue);
if (testBrightness > threshold) {
fill (black);
} else {
fill (white);
}
}
// drawing shapes
float dx = x - xz;
float dy = y - yz;
angle1 = atan2(dy, dx);
xz = x - (cos(angle1) * segLength);
yz = y - (sin(angle1) * segLength);
translate(width/2,height/2);
segment(xz, yz, angle1);
// movement
xa=xa+random(-0.1,0.1);
ya=ya+random(-0.1,0.1);
x=x+xa;
y=y+ya;
// walls
if(x>=width/2-2){
x=x-0.1;
xa=-xa*0.5;
}if(x<=-width/2+2){
x=x+0.1;
xa=-xa*0.5;
}if(y>=height/2-2){
y=y-0.1;
ya=-ya*0.5;
}if(y<=-height/2+2){
y=y+0.1;
ya=-ya*0.5;
}
// speed limiter
if(xa>=2){
xa=xa-1;
}if(xa<=-2){
xa=xa+1;
}if(ya>=2){
ya=ya-1;
}if(ya<=-2){
ya=ya+1;
}
}
void segment(float xz, float yz, float a) {
pushMatrix();
translate(xz, yz);
rotate(a);
strokeWeight(20.0);
stroke(50, 255);
line(0, 0, segLength, 0);
strokeWeight(1.0);
stroke(255);
fill(255);
ellipse(15,3,1,1);//
ellipse(15,-3,1,1);
fill(255,0,0);
stroke(255,0,0);
ellipse(0,-2,2,2);
ellipse(0,2,2,2);
ellipse(-5,-4,2,2);
ellipse(-5,4,2,2);
ellipse(5,-4,2,2);
ellipse(5,4,2,2);
popMatrix();
}
void keyPressed () {
mirror = !mirror;
}