We are about to switch to a new forum software. Until then we have removed the registration on this forum.
get error like these: ==== JavaSound Minim Error ==== ==== Couldn't find a sketchPath method on the file loading object provided! ==== File recording will be disabled.
==== JavaSound Minim Error ==== ==== Couldn't find a createInput method in the file loading object provided! ==== File loading will be disabled.
==== JavaSound Minim Error ==== ==== Error invoking createInput on the file loader object: null
here is my code:
import processing.video.*; Capture cam; Vehicle[] v=new Vehicle[5]; color trackColor; int time; int wait =60;
void setup() { size(800, 800); for (int i=0; i<v.length; i++) { float r=random(TWO_PI); v[i]=new Vehicle(width/2+sin(r)500, height/2+cos(r)500); } smooth(); cam = new Capture(this, 640, 480, "FaceTime HD Camera", 30); trackColor = color(255, 0, 0); cam.start();
}
void draw() { background(0);
PVector center = new PVector(width/2, height/2);
// Draw an ellipse at the mouse location fill(#2CFFCC); stroke(0); strokeWeight(2); ellipse(center.x, center.y, 48, 48);
// Call the appropriate steering behaviors for our agents
for (int i=0; i<v.length; i++) {
v[i].arrive(center);
v[i].update();
v[i].display();
v[i].youLose();
v[i].youWin();
}
if (cam.available()) {
cam.read();
}
cam.loadPixels();
image(cam, 672, 704,128,96);
float worldRecord = 500;
int closestX = 0;
int closestY = 0;
for (int x = 0; x < cam.width; x ++ ) {
for (int y = 0; y < cam.height; y ++ ) {
int loc = x + y*cam.width;
// What is current color
color currentColor = cam.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float b1 = blue(currentColor);
float r2 = red(trackColor);
float g2 = green(trackColor);
float b2 = blue(trackColor);
float d = dist(r1, g1, b1, r2, g2, b2);
if (d < worldRecord) {
worldRecord = d;
closestX = x;
closestY = y;
}
}
}
if (worldRecord < 120) {
for (int i=0; i<v.length; i++) {
// Draw a circle at the tracked pixel
v[i].pause();
}
} else if(worldRecord >120){
for (int i=0; i<v.length; i++) {
v[i].arrive(center);
v[i].update();
v[i].display();
v[i].youLose();
v[i].youWin();
}
}
}
void mouseClicked(){
setup();
}
import ddf.minim.*; import ddf.minim.signals.*;
class Vehicle {
AudioSample yay;
Minim minim;
AudioOutput out;
PulseWave wav;
PVector location;
PVector velocity;
PVector acceleration;
float r;
float maxforce;
float maxspeed;
float speed=100;
Vehicle(float x, float y) { acceleration = new PVector(random(-5, 5), random(-5, 5)); velocity = new PVector(random(-5, 5), random(-5, 5)); location = new PVector(x, y); r = 6; maxspeed = 1.5; maxforce = 0.1; minim = new Minim(this); yay = minim.loadSample("yay.mp3",512);
out = minim.getLineOut(Minim.STEREO);
wav = new PulseWave(550, 0.5, out.sampleRate());
wav.portamento(400);
out.addSignal(wav);
}
void update() {
velocity.add(acceleration);
velocity.limit(maxspeed);
location.add(velocity);
acceleration.mult(0);
speed=map(velocity.mag(), 0, maxspeed, 50, 100);
println(speed);
wav.setFreq(speed);
}
void applyForce(PVector force) {
acceleration.add(force);
}
void arrive(PVector target) {
PVector desired = PVector.sub(target, location);
float d = desired.mag();
desired.normalize();
if (d < 100) {
float m = map(d, 0, 100, 0, maxspeed);
desired.mult(m);
} else {
desired.mult(maxspeed);
}
PVector steer = PVector.sub(desired, velocity);
steer.limit(maxforce);
applyForce(steer);
}
void display() {
float theta = velocity.heading2D() + PI/2;
fill(255);
stroke(0);
strokeWeight(1);
pushMatrix();
translate(location.x, location.y);
rotate(theta);
beginShape();
vertex(0, 0);
vertex(-r, sqrt(3)*r);
vertex(r, sqrt(3)*r );
endShape(CLOSE);
popMatrix();
} void youLose() { if (dist(location.x, location.y, width/2, height/2)<24) { fill(255, 0, 0); ellipse(width/2, height/2, 48, 48); textSize(20); textAlign(CENTER); text("YOU LOSE", width/2, 300); } } void youWin() { if (key=='p') { textSize(20); textAlign(CENTER); fill(255, 0, 0); text("YOU WIN", width/2, 300); acceleration.mult(0); velocity.mult(0); maxspeed=0;
yay.trigger();
}
} void pause() { acceleration.mult(0); velocity.mult(0); } }