Switching modes on webcam
in
Contributed Library Questions
•
4 months ago
Hello, guys
I have a programming question,
I have created this code, interacting webcam and sound.
It works with sound, but it doesn't switch modes.
What I can't do is this:
if percent >0.9, switch to Mode 2 ( and don't come back to default Mode)
and if percent >0.9 again switch to Mode 3(and don't come back to default Mode)
and if percent> 0.9 again switch to Mode 1
And default mode is Mode 1
Please help me.
Mode1(ellipse)
Mode2(rect)
Mode3(star)
and this is my code(it doesen't work):
can anybody fix my code or give me a new code please??
I really need code.
thank you^^
- import processing.video.*;
import krister.Ess.*;
FFT myfft;
AudioInput myinput;
int bufferSize=512;
import processing.video.*; - // Size of each cell in the grid
int cellSize = 8;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;
PShape star; - void setup() {
- size(1920,900, P3D);
// Set up columns and rows
cols = width/2 / cellSize;
rows = height/2 / cellSize;
colorMode(RGB, 255, 255, 255, 70);
ellipseMode(CENTER);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, 640, 480);
video.start();
frameRate(2);
// filter(BLUR,30);
smooth(); - Ess.start(this);
myinput=new AudioInput(bufferSize);
myfft=new FFT(bufferSize*2);
myinput.start(); - myfft.damp(.5);
myfft.equalizer(true);
myfft.limits(.005,.01);
}
void draw() {
float percent= myfft.averages[0];
- if (video.available()) {
video.read();
video.loadPixels();
background(0,0,0);
//filter(BLUR,10);
// Begin loop for columns
for (int i = 0; i < cols;i++) {
// Begin loop for rows
for (int j = 0; j < rows;j++) { - // Where are we, pixel-wise?
int x = i*cellSize + cellSize/2;
int y = j*cellSize + cellSize/2;
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
// Each rect is colored white with a size determined by brightness
color c = video.pixels[loc];
float sz = ((percent)*2500/ float(width)) * brightness(video.pixels[loc]) + 20.0;
float sy = brightness(video.pixels[loc])+20.0;
pushMatrix();
println("percent : "+percent);
translate(x , y , sz);
fill(c);
noStroke();
// default mode is Mode 1
//if percent >0.9, switch to Mode 2 ( and don't come back to default Mode)
// and if percent >0.9 again switch to Mode 3(and don't come back to default Mode)
// and if percent> 0.9 again switxh to Mode 1
//(default Mode) Mode 1
ellipse(x + cellSize/2, y + cellSize/2,cellSize*sy/100, cellSize*sy/100);
// Mode 2
// rect(x + cellSize/2, y + cellSize/2,cellSize*sy/100, cellSize*sy/100);
//Mode 3
/* star = createShape();
star.vertex(0.5, -8);
star.vertex(2, -3.5);
star.vertex(5.5, -2.5);
star.vertex(2.5, 1);
star.vertex(3.5, 5);
star.vertex(0, 3);
star.vertex(-3.5, 5);
star.vertex(-2.5, 1);
star.vertex(-5.5, -2.5);
star.vertex(-2, -3.5);
star.end(CLOSE);
shape(star);
*/
popMatrix(); -
}
}
}
}
public void audioInputData(AudioInput theInput) {
myfft.getSpectrum(myinput);
}
1