import java.applet.*;
import java.awt.*;
import java.lang.*;
import java.awt.image.*;
public class Orbit1 extends Applet
{
public void init() {
add(new Orbit());
}
}
class Orbit extends Panel implements Runnable
{
// Initialisierung der Variablen
int appletsize_x = 600; // Größe des Applets in x - Richtung
int appletsize_y = 600; // Größe des Applets in y - Richtung
//BufferedImage image = new BufferedImage(appletsize_x,appletsize_y,BufferedImage.TYPE_INT_RGB);
int v1 = 11;
int v2 = 17;
int v3 = 25;
double t;
int Radius = 47;
int radius = 27;
int kradius = 10;
double ex_a_m = 0.5;
double ex_b_m = 0.25;
double ex_a_s = 0.25;
double ex_b_s = 0.5;
int xm;
int ym;
int xs;
int ys;
// Variablen für die Doppelpufferung
private Image dbImage;
private Graphics dbg;
public Orbit()
{
init();
}
public void init()
{
setBackground (Color.blue);
System.out.println("init drin");
}
public void start ()
{
// Schaffen eines neuen Threads, in dem das Spiel läuft
Thread th = new Thread (this);
// Starten des Threads
th.start ();
}
public void stop()
{
}
public void destroy()
{
}
public void run ()
{
// Erniedrigen der ThreadPriority um zeichnen zu erleichtern
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
// Solange true ist läuft der Thread weiter
while (true)
{
t += 0.02;
double xmtemp = (Math.cos((v2 * t)/radius)* radius)/ ex_a_m +( Math.cos((v1 * t)/Radius) * Radius)/ ex_a_s;
double ymtemp = (Math.sin((v2 * t)/radius)* radius)/ ex_b_m +( Math.sin((v1 * t)/Radius) * Radius)/ex_b_s;
xm = (int) xmtemp;
ym = (int) ymtemp;
double xstemp = (Math.cos((v1 * t)/Radius) * Radius) / ex_a_s;
double ystemp = (Math.sin((v1 * t)/Radius) * Radius) / ex_b_s;
xs = (int) xstemp;
ys = (int) ystemp;
//System.out.println(Math.sqrt((Math.abs((xmtemp - xstemp)) * Math.abs((xmtemp - xstemp))) + Math.abs(((ymtemp - ystemp)) * Math.abs((ymtemp - ystemp)))));
// Neuzeichnen des Applets
repaint();
try
{
// Stoppen des Threads für in Klammern angegebene Millisekunden
Thread.sleep (0);
}
catch (InterruptedException ex)
{
// do nothing
}
// Zurücksetzen der ThreadPriority auf Maximalwert
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
}
/** Update - Methode, Realisierung der Doppelpufferung zur Reduzierung des Bildschirmflackerns */
public void update (Graphics g)
{
// Initialisierung des DoubleBuffers
if (dbImage == null)
{
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics ();
}
// Bildschirm im Hintergrund löschen
dbg.setColor (getBackground ());
dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
// Auf gelöschten Hintergrund Vordergrund zeichnen
dbg.setColor (getForeground());
paint (dbg);
// Nun fertig gezeichnetes Bild Offscreen auf dem richtigen Bildschirm anzeigen
g.drawImage (dbImage, 0, 0, this);
paint(g);
}
public void paint (Graphics g)
{
g.setColor (Color.red);
g.fillOval (xm + appletsize_x/2 + 1, ym + appletsize_y / 2 + 1, 2, 2);
g.setColor (Color.black);
g.fillOval (appletsize_x/2 - 5, appletsize_y / 2 - 5, 10, 10);
g.setColor (Color.black);
g.fillOval (xs + appletsize_x/2 + 1, ys + appletsize_y / 2 + 1, 2, 2);
}
}