We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I keep getting this error, and I don't know why it is not working.
// Daniel Shiffman // Tracking the average location beyond a given depth threshold // Thanks to Dan O'Sullivan
// https://github.com/shiffman/OpenKinect-for-Processing // http://shiffman.net/p5/kinect/
ParticleSystem ps; import org.openkinect.freenect.*; import org.openkinect.processing.*;
PImage texture; // The kinect stuff is happening in another class KinectTracker tracker; Kinect kinect;
void setup() { size(640, 640); kinect = new Kinect(this); tracker = new KinectTracker(); ps = new ParticleSystem(0,new PVector(width/2,height-60),texture); }
void draw() { background(0); // Run the tracking analysis tracker.track(); // Show the image tracker.display(); PVector v1 = tracker.getPos(); PImage texture = loadImage("texture.png"); texture.resize(200, 200); image(texture, v1.x -100, v1.y -100); // fill(#ff9999); //ellipse(v1.x, v1.y, 100, 100);
// Display some info int t = tracker.getThreshold(); fill(255); text("threshold: " + t + " " + "framerate: " + int(frameRate) + " " + "UP increase threshold, DOWN decrease threshold", 10, 500);
// Calculate a "wind" force based on mouse horizontal position float dx = map(mouseX,0,width,-0.2,0.2); PVector wind = new PVector(dx,0); ps.applyForce(wind); ps.run(); for (int i = 0; i < 2; i++) { ps.addParticle(); }
// Draw an arrow representing the wind force drawVector(wind, new PVector(width/2,50,0),500);
}
// Renders a vector object 'v' as an arrow and a location 'loc' void drawVector(PVector v, PVector loc, float scayl) { pushMatrix(); float arrowsize = 4; // Translate to location to render vector translate(loc.x,loc.y); stroke(255); // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate rotate(v.heading()); // Calculate length of vector & scale it to be bigger or smaller if necessary float len = v.mag()*scayl; // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
popMatrix(); }
class ParticleSystem {
ArrayList particles; // An arraylist for all the particles PVector origin; // An origin point for where particles are birthed PImage img;
ParticleSystem(int num, PVector v, PImage img_) { particles = new ArrayList(); // Initialize the arraylist origin = v.get(); // Store the origin point img = img_; for (int i = 0; i < num; i++) { particles.add(new Particle(origin, img)); // Add "num" amount of particles to the arraylist } }
void run() { for (int i = particles.size()-1; i >= 0; i--) { Particle p = particles.get(i); p.run(); if (p.isDead()) { particles.remove(i); } } }
void run() { for (int i = particles.size()-1; i >= 0; i--) { Particle p = particles.get(i); p.run(); if (p.isDead()) { particles.remove(i); } } }
// Method to add a force vector to all particles currently in the system void applyForce(PVector dir) { // Enhanced loop!!! for (Particle p: particles) { p.applyForce(dir); }
}
void addParticle() { particles.add(new Particle(origin,img)); }
}
void run() { update(); render(); }
// Method to apply a force vector to the Particle object // Note we are ignoring "mass" here void applyForce(PVector f) { acc.add(f); }
// Method to update location void update() { vel.add(acc); loc.add(vel); lifespan -= .5; acc.mult(0); // clear Acceleration }
// Method to display void render() { tint(255,lifespan); image(texture,loc.x,loc.y-200); // Drawing a circle instead // fill(255,lifespan); // noStroke(); // ellipse(loc.x,loc.y,img.width,img.height); }
// Is the particle still useful? boolean isDead() { if (lifespan <= 0.0) { return true; } else { return false; }
}
// Adjust the threshold with key presses void keyPressed() { int t = tracker.getThreshold(); if (key == CODED) { if (keyCode == UP) { t+=5; tracker.setThreshold(t); } else if (keyCode == DOWN) { t-=1000; tracker.setThreshold(t); } }
}
Answers
@FlyBurgerFly
To help others read your problem (and copy / test your code) please edit your post, highlight your code, format your code with CTRL-o, and save.
Did you create a folder named EXAMPLE and put the sketch file in it, then try to run it in the Processing IDE?
Don't do that. Instead, open a new sketch, paste the code in. When you save it, the enclosing folder and the main file will be renamed to have the same name. E.g.:
It needs to be this way to compile; Processing handles making the folder and file names match automatically when you start in Processing.
@jeremydouglass I tried doing that, but now I get this error.
Exception in thread "Thread-245" java.lang.NullPointerException at processing.app.SketchCode.getDocumentText(SketchCode.java:228) at processing.app.ui.Editor.prepareRun(Editor.java:2716) at processing.mode.java.JavaEditor.prepareRun(JavaEditor.java:1781) at processing.mode.java.JavaEditor$34.run(JavaEditor.java:1095) at java.lang.Thread.run(Thread.java:745)
I don't know. Maybe try: