Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Trying to compile two sketches on one

$
0
0
Hi
I couldn't follow what you were suggesting me before, so i tried something different and it is more simple now...
So I was advancing a little on the idea. No I have other problem. I need the sample color data to go to a text file (colors.txt) in a single line everytime I press SPACE (take a picture) so I use the output.println to add the hex data color to the text file but it only works once per session.

So my question is how can I make the println value to overwrite the last value?
Or, how I add a single line of the println to the text file?

Thanks

/**
 * Getting Started with Capture.
 *
 * Reading and displaying an image from an attached Capture device.
 */

PImage img;
PrintWriter output;
import processing.video.*;

Capture cam;

void setup() {
  size(640, 480, P2D);
  output = createWriter("colors.txt");

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

    // The camera can be initialized directly using an element
    // from the array returned by list():
    cam = new Capture(this, cameras[0]);
    cam.start();
  }
}

void draw() {
  if (cam.available() == true) {
    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(0, 0, cam);

  img = loadImage("../pics/1.jpg");
  colorMode(RGB);
  color cp = img.get(320, 360);
  fill(cp);
  rect(30, 20, 55, 55);
  println(hex(cp, 6));
  output.println(hex(cp, 6));
  output.flush();
  output.close();
}

 
void keyPressed() {
  if (key == ' ')
    saveFrame("../pics/1.jpg");
}


Viewing all articles
Browse latest Browse all 1768

Trending Articles