We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am working on a sketch with the contributed library, Fisica. I am trying to use the function of anchor and contact resize. But I don't know why my codes are not working with the contact resize part. Please....I really need your help, it frustrates me for a few days.
Here are my codes,
import fisica.*;
float frequency = -35;
float damping = -5;
float puenteY;
FBody[] steps = new FBox[15];
FWorld world;
int boxWidth = 500/(steps.length) -20;
void setup() {
size(600, 600);
smooth();
puenteY = height/4;
Fisica.init(this);
world = new FWorld();
world.setGravity(0, 100);
world.setEdges();
world.remove(world.left);
world.remove(world.right);
world.remove(world.top);
world.setGrabbable(false);
FCircle bola = new FCircle(40);
bola.setPosition(width/2, puenteY-50);
bola.setDensity(0.2);
bola.setFill(random(50,200));
bola.setNoStroke();
world.add(bola);
for (int i=0; i<steps.length; i++) {
steps[i] = new FBox(boxWidth,10);
steps[i].setPosition(map(i, 0, steps.length-1, boxWidth, width-steps.length), puenteY);
// steps[i].setPosition(boxWidth*i+50, puenteY);
steps[i].setNoStroke();
steps[i].setFill(183, 218, 232);
world.add(steps[i]);
}
for (int i=1; i<steps.length; i++) {
FDistanceJoint junta = new FDistanceJoint(steps[i-1], steps[i]);
junta.setAnchor1(boxWidth/2, 0);
junta.setAnchor2(-boxWidth/2, 0);
junta.setFrequency(frequency);
junta.setDamping(damping);
junta.setFill(118);
junta.setNoStroke();
junta.calculateLength();
world.add(junta);
}
FCircle left = new FCircle(10);
left.setStatic(true);
left.setPosition(0, puenteY);
left.setDrawable(false);
world.add(left);
FCircle right = new FCircle(10);
right.setStatic(true);
right.setPosition(width, puenteY);
right.setDrawable(false);
world.add(right);
FDistanceJoint juntaPrincipio = new FDistanceJoint(steps[0], left);
juntaPrincipio.setAnchor1(-boxWidth/2, 0);
juntaPrincipio.setAnchor2(0, 0);
juntaPrincipio.setFrequency(frequency);
juntaPrincipio.setDamping(damping);
juntaPrincipio.calculateLength();
juntaPrincipio.setFill(118);
juntaPrincipio.setNoStroke();
world.add(juntaPrincipio);
FDistanceJoint juntaFinal = new FDistanceJoint(steps[steps.length-1], right);
juntaFinal.setAnchor1(boxWidth/2, 0);
juntaFinal.setAnchor2(0, 0);
juntaFinal.setFrequency(frequency);
juntaFinal.setDamping(damping);
juntaFinal.calculateLength();
juntaFinal.setFill(118);
juntaFinal.setNoStroke();
world.add(juntaFinal);
}
void draw() {
background(255);
world.step();
world.draw();
if(keyPressed){
if(key==' '){
world.setGravity(0, -100);}
else {
world.setGravity(0, 100);}
}
if (frameCount % 100 == 0) {
FCircle b = new FCircle(random(10, 40));
b.setPosition(random(0,width), 50);
b.setVelocity(0, 100);
b.setRestitution(0);
b.setNoStroke();
b.setFill(random(50,200));
world.add(b);
}
}
void contactEnded(FContact c) {
if (!c.getBody1().isStatic()) {
FCircle b = (FCircle)c.getBody1();
if (b.getSize()>5) {
b.setSize(b.getSize()*0.9);
}
}
if (!c.getBody2().isStatic()) {
FCircle b = (FCircle)c.getBody2();
if (b.getSize()>5) {
b.setSize(b.getSize()*0.9);
}
}
}
void mousePressed() {
float radius = random(10, 40);
FCircle bola = new FCircle(radius);
bola.setPosition(mouseX, mouseY);
bola.setDensity(0.2);
bola.setFill(random(50,200));
bola.setNoStroke();
world.add(bola);
}
void keyReleased(){
if(key==' '){
world.setGravity(0, 100);}
else {
world.setGravity(0, -100);}
}
void keyPressed() {
if (key == 's' || key == 'S') saveFrame("_##.png");
}
Answers
please help!!!!!!!!!!!!!!!