Monday, November 26, 2012

Processing glitch camera


<Running with Processing 1.5.1!!>


//glitch camera still generator
//click to save image
 
import processing.video.*;
 
Capture cam;
 
int N=0;
 
void setup(){
size (851,315);
background(255);
colorMode(HSB);
 
 
// If no device is specified, will just use the default.
  cam = new Capture(this, 851, 315);
 
  // To use another device (i.e. if the default device causes an error),  
  // list all available capture devices to the console to find your camera.
  //String[] devices = Capture.list();
  //println(devices);
   
  // Change devices[0] to the proper index for your camera.
  //cam = new Capture(this, width, height, devices[0]);
 
  // Opens the settings page for this capture device.
  //camera.settings();
}
 
void draw(){
 
  Set();
    if (cam.available() == true) {
      if(frameCount==2||frameCount%150==0){
    cam.read();
    image(cam, 0, 0);
    // The following does the same, and is faster when just drawing the image
    // without any additional resizing, transformations, or tint.
    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)));
  }
}

6 comments:

  1. i get this error, my main camara is [0]
    Nov 26 12:57:53 iMac-de-Oso.local java[18965] : CGContextGetCTM: invalid context 0x0
    Nov 26 12:57:53 iMac-de-Oso.local java[18965] : CGContextSetBaseCTM: invalid context 0x0
    Nov 26 12:57:53 iMac-de-Oso.local java[18965] : CGContextGetCTM: invalid context 0x0
    Nov 26 12:57:53 iMac-de-Oso.local java[18965] : CGContextSetBaseCTM: invalid context 0x0

    heeeeelp, :)

    ReplyDelete
    Replies
    1. Try to run with Processing 1.5.1!

      Delete
    2. it works, its magic, you are god. thanks

      Delete
  2. funcionou em parte, usando webcam e o Processing 2.0b8

    ReplyDelete
  3. Pois é, parece que só funciona no Processing 1.5.1.

    ReplyDelete
  4. WORKS BETTER FOR ME; LIVE CAM GLITCH

    //glitch camera still generator
    //click to save image

    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]);
    }

    // If no device is specified, will just use the default.
    // Initialize Camera
    cam = new Capture(this, cameras[0]);
    cam.start();
    }
    }

    // To use another device (i.e. if the default device causes an error),
    // list all available capture devices to the console to find your camera.
    //String[] devices = Capture.list();
    //println(devices);

    // Change devices[0] to the proper index for your camera.
    //cam = new Capture(this, width, height, devices[0]);

    // Opens the settings page for this capture device.
    //camera.settings();


    void draw(){

    Set();
    if (cam.available() == true) {
    if(frameCount==2||frameCount%150==0){
    cam.read();
    image(cam, 0, 0);
    // The following does the same, and is faster when just drawing the image
    // without any additional resizing, transformations, or tint.
    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)));
    }
    }

    ReplyDelete