Above is a new Box2D Processing example that demonstrates two key aspects of working with Box2D:
1) Though tempting as it may be, you cannot set the location manually of an object in the Box2D world and expect the physics to continue to work. Box2D doesn’t understand teleportation (which is the equivalent of telling an object to disappear and then reappear at a different pixel). Rather, if you want to move an object manually, you can attach a joint to the object and tug it around. This way, you control its motion and yet it still lives within the world of Box2D physics. The example demonstrates how this is done with a MouseJoint. The object moves according to an perlin noise algorithm (unless the mouse is pressed in which case it follows the mouse).
2) The example also demonstrates how to use Box2D’s ContactListener to know when objects have collided. The circles turn red when they encounter the square.
It’s my intention to eventually add this example with further explanation to the Box2D tutorial.