Viele weitere Beispielprojekt für verschiedene Anwendungen

This commit is contained in:
ngb
2022-06-19 22:26:01 +02:00
parent dc6b7ee351
commit a2d883305a
97 changed files with 2535 additions and 61 deletions

View File

@@ -75,8 +75,8 @@ public class Attractor extends Mover {
if( pMover != this && isActive() ) {
Vector force = new Vector(this.x, this.y);
force.sub(pMover.getX(), pMover.getY());
double v = G * mass / force.lenSq();
force.setLen(v).limit(1.0, 4 * G);
double v = G * mass / force.lengthSq();
force.setLength(v).limit(1.0, 4 * G);
pMover.applyForce(force);
}
}

View File

@@ -77,10 +77,11 @@ public class Gravity extends Zeichenmaschine {
* Welt zurück.
*/
public void mouseClicked() {
background.setColor(randomNiceColor());
for( Mover m : movers ) {
m.moveTo(random(10, width - 10), 30);
m.setVelocity(mouseX-m.getX(), mouseY-m.getY());
m.getVelocity().setLen(4.0);
m.getVelocity().setLength(4.0);
}
}

View File

@@ -23,7 +23,7 @@ public class Mover extends Circle implements Updatable {
/**
* Ob die momentane Geschwindigkeit der Objekte als Pfeil dargestellt werden soll.
*/
public static final boolean SHOW_VELOCITY = false;
public static final boolean SHOW_VELOCITY = true;
/**
@@ -163,8 +163,10 @@ public class Mover extends Circle implements Updatable {
velocity.add(acceleration);
acceleration.scale(0.0);
this.x += velocity.x;
this.y += velocity.y;
if( velocity.length() > 0.5 ) {
this.x += velocity.x;
this.y += velocity.y;
}
}
@Override