mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Viele weitere Beispielprojekt für verschiedene Anwendungen
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user