mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Beispielprojekte
This commit is contained in:
27
examples/zm_forces/Attractor.java
Normal file
27
examples/zm_forces/Attractor.java
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
import schule.ngb.zm.*;
|
||||
|
||||
public class Attractor extends Mover {
|
||||
|
||||
private int mass = 0;
|
||||
|
||||
public Attractor( int x, int pY, int pMass ) {
|
||||
this(x, pY, pMass, new Vector());
|
||||
}
|
||||
|
||||
public Attractor( int x, int pY, int pMass, Vector pVelocity ) {
|
||||
super(x, pY, pVelocity);
|
||||
mass = pMass;
|
||||
|
||||
setFillColor(YELLOW);
|
||||
}
|
||||
|
||||
public void attract( Mover pMover ) {
|
||||
if( pMover != this ) {
|
||||
Vector force = new Vector(this.x, this.y);
|
||||
force.sub(pMover.getX(), pMover.getY()).scale(mass*Gravity.G).limit(0, 50*Gravity.G);
|
||||
pMover.applyForce(force);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user