Browse Source

mit sinus und cosinus implementiert

master
ahren 11 months ago
parent
commit
53c8ddabb9
3 changed files with 24 additions and 20 deletions
  1. 1
    0
      .gitignore
  2. 3
    3
      src/aufgabe8_grafik2d/Start.java
  3. 20
    17
      src/aufgabe8_grafik2d/Zeiger.java

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
/build/

+ 3
- 3
src/aufgabe8_grafik2d/Start.java View File

@@ -23,10 +23,10 @@ public class Start
Container c = frm.getContentPane();
c.setLayout(new OverlayLayout(c));
for (int i = 0; i < 100; i++)
for (int zeigerLaenge = 1; zeigerLaenge <=3; zeigerLaenge++)
{
long schlafzeit = (long)(1 + 100*Math.random());
Zeiger papier = new Zeiger(schlafzeit);
long schlafzeit = (long)(100*zeigerLaenge);
Zeiger papier = new Zeiger(schlafzeit, zeigerLaenge);
papier.setOpaque(false);
c.add(papier);
papier.start();

+ 20
- 17
src/aufgabe8_grafik2d/Zeiger.java View File

@@ -11,6 +11,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import static java.lang.Math.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -26,19 +27,23 @@ public class Zeiger extends JComponent implements Runnable
private Line2D.Float linie;
private BasicStroke stift;
private volatile float radius;
private volatile float minRadius;
private volatile float maxRadius;
private volatile float xMitte;
private volatile float yMitte;
private volatile double xAussen;
private volatile double yAussen;
private volatile double alpha;
private long schlafzeit;
private int zeigerlaenge;
private ExecutorService eService;
private Future task;
public Zeiger(long schlafzeit)
public Zeiger(long schlafzeit, int zeigerlaenge)
{
this.schlafzeit = schlafzeit;
this.zeigerlaenge = zeigerlaenge;
linie = new Line2D.Float();
stift = new BasicStroke(DICKE);
radius = 100;
minRadius = DICKE;
alpha = 0;
eService = Executors.newSingleThreadExecutor();
task = null;
}
@@ -51,9 +56,9 @@ public class Zeiger extends JComponent implements Runnable
{
synchronized(this)
{
if (radius > maxRadius) delta = -1f;
if (radius < minRadius) delta = +1f;
radius += delta;
alpha += 0.1;
xAussen = xMitte +cos(2*PI*alpha) * radius;
yAussen = yMitte + sin(2*PI*alpha) * radius;
}
this.repaint();
try
@@ -86,20 +91,18 @@ public class Zeiger extends JComponent implements Runnable
float breite = this.getWidth() - 1;
float hoehe = this.getHeight() - 1;
synchronized(this)
{
maxRadius = -DICKE/2 + Math.min(breite, hoehe) / 2;
}

float radius = (min(hoehe, breite)/2 - 50) * 1/ zeigerlaenge;
float x = breite/2 - radius;
float y = hoehe/2 - radius;
xMitte = breite/2;
yMitte = hoehe/2;
xAussen = xMitte +cos(2*PI*alpha) * radius;
yAussen = yMitte + sin(2*PI*alpha) * radius;
linie.setFrame(x, y, 2*radius, 2*radius);
linie.setLine(xMitte, yMitte, xAussen, yAussen);
g2.setStroke(stift);
g2.setPaint(Color.RED);
// g2.fill(ellipse);
// g2.setPaint(Color.BLACK);
g2.draw(linie);
}

Loading…
Cancel
Save