59 lines
1.0 KiB
Plaintext
Raw Normal View History

2015-03-04 11:42:07 +01:00
import teilchen.Physics;
import teilchen.force.Spring;
import teilchen.force.ViscousDrag;
final int CANVAS_WIDTH = 500;
final int CANVAS_HEIGHT = 500;
final int NBR_CREATURES = 75;
Physics physics;
Spring spring;
Creature t;
Creature c;
void setup() {
size(CANVAS_WIDTH, CANVAS_HEIGHT);
background(23, 68, 250);
frameRate(30);
physics = new Physics();
// create a global drag
ViscousDrag drag = new ViscousDrag();
drag.coefficient = 0.25f;
2015-03-04 13:26:26 +01:00
//physics.add(drag);
2015-03-04 11:42:07 +01:00
t = new TriangleCreature((int)random(width), (int)random(height), 20);
c = new CircleCreature((int)random(width), (int)random(height), 20);
physics.add(t); physics.add(c);
spring = physics.makeSpring(t, c);
2015-03-04 13:26:26 +01:00
2015-03-04 11:42:07 +01:00
spring.restlength(20);
}
void draw() {
physics.step(1.0 / frameRate);
background(23, 68, 250);
stroke(255);
noFill();
c.display();
t.display();
stroke(255, 0, 0);
line(c.position().x, c.position().y, t.position().x, t.position().y);
}
void mouseDragged() {
spring.b().position().set(mouseX, mouseY);
}