I am newbie and i need help
in
Contributed Library Questions
•
2 years ago
Hi!
I am really new using processing or any programming languages but i have been playing for fews days with processing and i really like it and i saw what can be done so i will give it a try. So the first step was to get a book so i got Getting Started with Processing. Its very good for real beginners.
My Question is how can i insert live feed from a webcam into the 500 rectangles that is reacting with the music?
It works with images and also i got the live feed but it blink a lot so i couldnt really see what was going on.
- import processing.opengl.*;
- import codeanticode.gsvideo.*;
- import ddf.minim.*;
- import ddf.minim.signals.*;
- import ddf.minim.analysis.*;
- import ddf.minim.effects.*;
- Minim minim;
- AudioPlayer music;
- GSCapture cam;
- FFT fft;
- Square[] square;
- PImage a;
- int numItems = 700;
- void setup(){
- size(800, 600, OPENGL);
- a = loadImage("jelly.jpg");
- minim = new Minim(this);
- music = minim.loadFile("Sound.mp3");
- music.play();
- fft = new FFT(music.bufferSize(), music.sampleRate());
- square = new Square[numItems];
- for(int i=0; i<numItems; i++){
- square[i] = new Square();
- }
- smooth();
- hint(DISABLE_DEPTH_TEST);
- }
- void draw(){
- background(0);
- fft.forward(music.mix);
- pushMatrix();
- translate(width/2, height/2, 0);
- for(int i=0; i<square.length; i++){
- square[i].update();
- square[i].display();
- }
- popMatrix();
- println(frameRate);
- }
- void stop(){
- music.close();
- minim.stop();
- super.stop();
- }
- class Square{
- int band;
- float radio;
- float sizes;
- float rotationX, rotationY;
- Square(){
- band = (int)random(0, 256);
- rotationX = random(0, 360);
- rotationY = random(0, 360);
- radio = 100;
- sizes = 10;
- }
- void update(){
- float fftVal = fft.getBand(band);
- float radioMim = 20;
- float radioTarget = fftVal * 2;
- radio += radioMim+ (radioTarget - radio) / 10;
- float sizeTarget = fftVal / 2;
- if(sizes < sizeTarget){
- sizes = sizeTarget;
- }
- else {
- sizes *= 0.95;
- }
- rotationY += 0.01;
- }
- void display(){
- pushMatrix();
- rotateX(rotationX);
- rotateY(rotationY);
- stroke(255, 0, 0, 20);
- translate(0, 0, radio);
- stroke(255);
- fill(100,0,0);
- rect(-sizes/2, -sizes/2, sizes, sizes);
- popMatrix();
- }
- }
If somebody can help please let me know.
Thanks and sorry for my English.
1