FWorld world;
FPoly poly;
PGraphics g;
void setup() {
size(400, 400);
smooth();
Fisica.init(this);
world = new FWorld();
world.setGravity(0, 800);
world.setEdges();
world.remove(world.left);
world.remove(world.right);
world.remove(world.top);
world.setEdgesRestitution(0.5);
g = createGraphics(width, height);
}
void draw() {
background(255);
world.step();
world.draw();
// Draw the polygon while
// while it is being created
// and hasn't been added to the
// world yet
if (poly != null) {
poly.draw(Fisica.parentGraphics());
}
}
void mousePressed() {
if (world.getBody(mouseX, mouseY) != null) {
return;
}
poly = new FPoly();
poly.setStrokeWeight(3);
poly.setFill(120, 30, 90);
poly.setDensity(10);
poly.setRestitution(0.5);
poly.vertex(mouseX, mouseY);
}
void mouseDragged() {
if (poly!=null) {
poly.vertex(mouseX, mouseY);
}
}
void mouseReleased() {
if (poly!=null) {
world.add(poly);
poly = null;
}
}
void keyPressed() {
if (key == BACKSPACE) {
FBody hovered = world.getBody(mouseX, mouseY);
if ( hovered != null &&
hovered.isStatic() == false ) {
world.remove(hovered);
}
}
else {
try {
saveFrame("screenshot.png");
}
catch (Exception e) {
}
}
}