mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Sprache zu Englisch geändert
This commit is contained in:
@@ -1,21 +1,21 @@
|
|||||||
package schule.ngb.zm.partikel;
|
package schule.ngb.zm.partikel;
|
||||||
|
|
||||||
import schule.ngb.zm.Aktualisierbar;
|
import schule.ngb.zm.Updatable;
|
||||||
import schule.ngb.zm.Farbe;
|
import schule.ngb.zm.Color;
|
||||||
import schule.ngb.zm.Vektor;
|
import schule.ngb.zm.Vector;
|
||||||
import schule.ngb.zm.Zeichenbar;
|
import schule.ngb.zm.Drawable;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class Partikel implements Aktualisierbar, Zeichenbar {
|
public class Partikel implements Updatable, Drawable {
|
||||||
|
|
||||||
int maxLeben = 0;
|
int maxLeben = 0;
|
||||||
|
|
||||||
int leben = 0;
|
int leben = 0;
|
||||||
|
|
||||||
Vektor position, geschwindigkeit, beschleunigung;
|
Vector position, geschwindigkeit, beschleunigung;
|
||||||
|
|
||||||
Color farbe, farbeStart, farbeEnde;
|
Color farbe, farbeStart, farbeEnde;
|
||||||
|
|
||||||
@@ -23,52 +23,52 @@ public class Partikel implements Aktualisierbar, Zeichenbar {
|
|||||||
|
|
||||||
double masse = 1.0;
|
double masse = 1.0;
|
||||||
|
|
||||||
public Partikel( Vektor pPosition ) {
|
public Partikel( Vector pPosition ) {
|
||||||
position = pPosition.kopie();
|
position = pPosition.copy();
|
||||||
geschwindigkeit = new Vektor();
|
geschwindigkeit = new Vector();
|
||||||
beschleunigung = new Vektor();
|
beschleunigung = new Vector();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Partikel( Vektor pPosition, Vektor pGeschwindigkeit ) {
|
public Partikel( Vector pPosition, Vector pGeschwindigkeit ) {
|
||||||
position = pPosition.kopie();
|
position = pPosition.copy();
|
||||||
geschwindigkeit = pGeschwindigkeit.kopie();
|
geschwindigkeit = pGeschwindigkeit.copy();
|
||||||
beschleunigung = new Vektor();
|
beschleunigung = new Vector();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean istAktiv() {
|
public boolean isActive() {
|
||||||
return leben > 0;
|
return leben > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean istSichtbar() {
|
public boolean isVisible() {
|
||||||
return istAktiv();
|
return isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beschleunigen( Vektor pBeschleunigung ) {
|
public void beschleunigen( Vector pBeschleunigung ) {
|
||||||
beschleunigung.addieren(Vektor.dividieren(pBeschleunigung, masse));
|
beschleunigung.add(Vector.div(pBeschleunigung, masse));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void aktualisieren( double delta ) {
|
public void update( double delta ) {
|
||||||
if( istAktiv() ) {
|
if( isActive() ) {
|
||||||
geschwindigkeit.addieren(beschleunigung);
|
geschwindigkeit.add(beschleunigung);
|
||||||
position.addieren(Vektor.skalieren(geschwindigkeit, delta));
|
position.add(Vector.scale(geschwindigkeit, delta));
|
||||||
beschleunigung.skalieren(0.0);
|
beschleunigung.scale(0.0);
|
||||||
|
|
||||||
leben -= 1;
|
leben -= 1;
|
||||||
|
|
||||||
if( farbeStart != null ) {
|
if( farbeStart != null ) {
|
||||||
double t = 1.0 - (double) leben / (double) maxLeben;
|
double t = 1.0 - (double) leben / (double) maxLeben;
|
||||||
farbe = Farbe.morphen(farbeStart, farbeEnde, t);
|
farbe = Color.interpolate(farbeStart, farbeEnde, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void zeichnen( Graphics2D graphics ) {
|
public void draw( Graphics2D graphics ) {
|
||||||
if( istSichtbar() ) {
|
if( isVisible() ) {
|
||||||
graphics.setColor(farbe);
|
graphics.setColor(farbe.getJavaColor());
|
||||||
graphics.fillOval((int) position.x, (int) position.y, 4, 4);
|
graphics.fillOval((int) position.x, (int) position.y, 4, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package schule.ngb.zm.partikel;
|
package schule.ngb.zm.partikel;
|
||||||
|
|
||||||
import schule.ngb.zm.Aktualisierbar;
|
import schule.ngb.zm.Updatable;
|
||||||
import schule.ngb.zm.Vektor;
|
import schule.ngb.zm.Color;
|
||||||
import schule.ngb.zm.Zeichenbar;
|
import schule.ngb.zm.Vector;
|
||||||
|
import schule.ngb.zm.Drawable;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class PartikelGenerator implements Aktualisierbar, Zeichenbar {
|
public class PartikelGenerator implements Updatable, Drawable {
|
||||||
|
|
||||||
private int partikelProFrame;
|
private int partikelProFrame;
|
||||||
|
|
||||||
@@ -18,9 +19,9 @@ public class PartikelGenerator implements Aktualisierbar, Zeichenbar {
|
|||||||
|
|
||||||
private Partikel naechsterPartikel;
|
private Partikel naechsterPartikel;
|
||||||
|
|
||||||
public Vektor position;
|
public Vector position;
|
||||||
|
|
||||||
public Vektor richtung = new Vektor();
|
public Vector richtung = new Vector();
|
||||||
|
|
||||||
public int winkel = 0;
|
public int winkel = 0;
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ public class PartikelGenerator implements Aktualisierbar, Zeichenbar {
|
|||||||
private Vortex vortex = null;
|
private Vortex vortex = null;
|
||||||
|
|
||||||
public PartikelGenerator( double pX, double pY, int pPartikelLeben, int pPartikelProFrame ) {
|
public PartikelGenerator( double pX, double pY, int pPartikelLeben, int pPartikelProFrame ) {
|
||||||
position = new Vektor(pX, pY);
|
position = new Vector(pX, pY);
|
||||||
partikelProFrame = pPartikelProFrame;
|
partikelProFrame = pPartikelProFrame;
|
||||||
partikelLeben = pPartikelLeben;
|
partikelLeben = pPartikelLeben;
|
||||||
partikel = new Partikel[partikelProFrame*partikelLeben];
|
partikel = new Partikel[partikelProFrame*partikelLeben];
|
||||||
@@ -42,19 +43,19 @@ public class PartikelGenerator implements Aktualisierbar, Zeichenbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean istAktiv() {
|
public boolean isActive() {
|
||||||
return aktiv;
|
return aktiv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean istSichtbar() {
|
public boolean isVisible() {
|
||||||
return aktiv;
|
return aktiv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void starten() {
|
public void starten() {
|
||||||
// Partikel initialisieren
|
// Partikel initialisieren
|
||||||
for( int i = 0; i < partikel.length; i++ ) {
|
for( int i = 0; i < partikel.length; i++ ) {
|
||||||
partikel[i] = new Partikel(position.kopie());
|
partikel[i] = new Partikel(position.copy());
|
||||||
if( i > 0 ) {
|
if( i > 0 ) {
|
||||||
partikel[i-1].naechster = partikel[i];
|
partikel[i-1].naechster = partikel[i];
|
||||||
}
|
}
|
||||||
@@ -79,8 +80,8 @@ public class PartikelGenerator implements Aktualisierbar, Zeichenbar {
|
|||||||
);
|
);
|
||||||
p.position.set(position);
|
p.position.set(position);
|
||||||
|
|
||||||
p.geschwindigkeit.set(richtung.kopie().drehen(rotation));
|
p.geschwindigkeit.set(richtung.copy().rotate(rotation));
|
||||||
p.geschwindigkeit.skalieren(zufall());
|
p.geschwindigkeit.scale(zufall());
|
||||||
|
|
||||||
p.farbeStart = farbeStart;
|
p.farbeStart = farbeStart;
|
||||||
p.farbeEnde = farbeEnde;
|
p.farbeEnde = farbeEnde;
|
||||||
@@ -94,18 +95,18 @@ public class PartikelGenerator implements Aktualisierbar, Zeichenbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void aktualisieren( double delta ) {
|
public void update( double delta ) {
|
||||||
if( istAktiv() ) {
|
if( isActive() ) {
|
||||||
partikelGenerieren();
|
partikelGenerieren();
|
||||||
|
|
||||||
_aktiv = false;
|
_aktiv = false;
|
||||||
for( int i = 0; i < partikel.length; i++ ) {
|
for( int i = 0; i < partikel.length; i++ ) {
|
||||||
if( partikel[i] != null ) {
|
if( partikel[i] != null ) {
|
||||||
if( partikel[i].istAktiv() ) {
|
if( partikel[i].isActive() ) {
|
||||||
if( vortex != null ) {
|
if( vortex != null ) {
|
||||||
vortex.attract(partikel[i]);
|
vortex.attract(partikel[i]);
|
||||||
}
|
}
|
||||||
partikel[i].aktualisieren(delta);
|
partikel[i].update(delta);
|
||||||
_aktiv = true;
|
_aktiv = true;
|
||||||
} else {
|
} else {
|
||||||
partikel[i].naechster = naechsterPartikel;
|
partikel[i].naechster = naechsterPartikel;
|
||||||
@@ -125,17 +126,17 @@ public class PartikelGenerator implements Aktualisierbar, Zeichenbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void zeichnen( Graphics2D graphics ) {
|
public void draw( Graphics2D graphics ) {
|
||||||
if( istSichtbar() ) {
|
if( isActive() ) {
|
||||||
Color current = graphics.getColor();
|
java.awt.Color current = graphics.getColor();
|
||||||
for( int i = 0; i < partikel.length; i++ ) {
|
for( int i = 0; i < partikel.length; i++ ) {
|
||||||
if( partikel[i] != null ) {
|
if( partikel[i] != null ) {
|
||||||
partikel[i].zeichnen(graphics);
|
partikel[i].draw(graphics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( vortex != null ) {
|
if( vortex != null ) {
|
||||||
graphics.setColor(Color.BLACK);
|
graphics.setColor(java.awt.Color.BLACK);
|
||||||
double vscale = (4*vortex.scale);
|
double vscale = (4*vortex.scale);
|
||||||
graphics.fillOval((int)(vortex.position.x-vscale*.5), (int)(vortex.position.y-vscale*.5), (int)vscale, (int)vscale);
|
graphics.fillOval((int)(vortex.position.x-vscale*.5), (int)(vortex.position.y-vscale*.5), (int)vscale, (int)vscale);
|
||||||
}
|
}
|
||||||
@@ -147,17 +148,17 @@ public class PartikelGenerator implements Aktualisierbar, Zeichenbar {
|
|||||||
|
|
||||||
|
|
||||||
class Vortex {
|
class Vortex {
|
||||||
Vektor position;
|
Vector position;
|
||||||
double speed = 1.0, scale = 1.0;
|
double speed = 1.0, scale = 1.0;
|
||||||
|
|
||||||
public Vortex( Vektor pPosition ,double pSpeed, double pScale ) {
|
public Vortex( Vector pPosition ,double pSpeed, double pScale ) {
|
||||||
this.position = pPosition.kopie();
|
this.position = pPosition.copy();
|
||||||
this.scale = pScale;
|
this.scale = pScale;
|
||||||
this.speed = pSpeed;
|
this.speed = pSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attract( Partikel pPartikel ) {
|
public void attract( Partikel pPartikel ) {
|
||||||
Vektor diff = Vektor.subtrahieren(pPartikel.position, this.position);
|
Vector diff = Vector.sub(pPartikel.position, this.position);
|
||||||
double dx = -diff.y * this.speed;
|
double dx = -diff.y * this.speed;
|
||||||
double dy = diff.x * this.speed;
|
double dy = diff.x * this.speed;
|
||||||
double f = 1.0 / (1.0 + (dx*dx+dy*dy)/scale);
|
double f = 1.0 / (1.0 + (dx*dx+dy*dy)/scale);
|
||||||
|
|||||||
Reference in New Issue
Block a user