Restaring a sketch timed, with a webcam?
in
Core Library Questions
•
1 year ago
Hello All!
I'm reasonably new to processing, haven’t picked it up in a while and really wanted to finish something i was tinkering with a few months ago!
I'm wondering if someone can show me how to create a timed restart of a sketch, (example; after 20 minutes the programs restarts from the first pixel in the sequence).
Using my webcam seems to be a major issue, as it stops working with any attempt I’ve made to restart it
here's the code
import processing.video.*;
Capture loo;
int cellsize = 10;
int cols, rows;
ArrayList<PVector> points = new ArrayList<PVector>();
void setup() {
size(1920, 1200, P2D);
frameRate(500);
println("processing.video ");
loo = new Capture(this, width, height, 24);
cols = width/cellsize;
rows = height/cellsize;
rectMode(CENTER);
noStroke();
background(0);
// Create an array list with the positions where we want the rects
for (int i = 0; i < cols;i++) {
for (int j = 0; j < rows;j++) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*width; // Pixel array location
PVector p = new PVector(x, y, loc);
points.add(p);
}
}
// And now randomize the array!
//Collections.shuffle(points);
}
int idx;
void draw() {
if (loo.available()) {
// When using video to manipulate the screen, use video.available() and
// video.read() inside the draw() method so that it's safe to draw to the screen
loo.read();
PVector p = points.get(idx++);
color c = loo.pixels[int(p.z)]; // Grab the color
fill(c);
ellipse(p.x, p.y, cellsize, cellsize);
if (idx >= points.size()) {
noLoop();
println("Done");
}
}
}
any help would be wonderful!
Thanks
Sam
I'm reasonably new to processing, haven’t picked it up in a while and really wanted to finish something i was tinkering with a few months ago!
I'm wondering if someone can show me how to create a timed restart of a sketch, (example; after 20 minutes the programs restarts from the first pixel in the sequence).
Using my webcam seems to be a major issue, as it stops working with any attempt I’ve made to restart it
here's the code
import processing.video.*;
Capture loo;
int cellsize = 10;
int cols, rows;
ArrayList<PVector> points = new ArrayList<PVector>();
void setup() {
size(1920, 1200, P2D);
frameRate(500);
println("processing.video ");
loo = new Capture(this, width, height, 24);
cols = width/cellsize;
rows = height/cellsize;
rectMode(CENTER);
noStroke();
background(0);
// Create an array list with the positions where we want the rects
for (int i = 0; i < cols;i++) {
for (int j = 0; j < rows;j++) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*width; // Pixel array location
PVector p = new PVector(x, y, loc);
points.add(p);
}
}
// And now randomize the array!
//Collections.shuffle(points);
}
int idx;
void draw() {
if (loo.available()) {
// When using video to manipulate the screen, use video.available() and
// video.read() inside the draw() method so that it's safe to draw to the screen
loo.read();
PVector p = points.get(idx++);
color c = loo.pixels[int(p.z)]; // Grab the color
fill(c);
ellipse(p.x, p.y, cellsize, cellsize);
if (idx >= points.size()) {
noLoop();
println("Done");
}
}
}
any help would be wonderful!
Thanks
Sam
1