Zum Inhalt springen

markint

Mitglieder
  • Gesamte Inhalte

    3
  • Benutzer seit

  • Letzter Besuch

  1. markint

    Animation berechnen

    Danke, habs jetzt endlich geschafft.
  2. markint

    Animation berechnen

    Der Kreis sollte sich von der Mitte aus bewegen. Wenn man zielx und ziely auf 350 setzt bewegt sich der Kreis wie er sollte.
  3. Hallo, ich habe ein Problem mit der Bewegung auf meinem Radar. Der Kreis der sich bewegt ist bei einer hohen Steigung zu schnell und man sieht nicht mehr die Bewegung. Hat jemand eine Idee wie man das lösen kann, sodass immer die gleiche Bewegungsgeschwindigkeit vollzogen wird? import javax.swing.*; import java.awt.*; public class Animation { private int startx = 300;//Startpunkt private int starty = 300;//Startpunkt private int zielx = 100;//Zielpunkt private int ziely = 440;//Zielpunkt public static void main(String[] args){ Animation a = new Animation(); a.go(); } public void go(){ JFrame frame = new JFrame(); frame.setSize(577, 597); frame.setResizable(false); MyPanel panel = new MyPanel(); frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); double m = calculateAlterationRate(startx, starty, zielx, ziely); //Steigung einer Geraden. //Routenberechnung(FEHLERHAFT!!) //Der If-Block macht überhaupt nichts richtig. if (Math.abs(m) < 1){ double reciprocal = 1/m; if(ziely >= starty){ while(!(zielx-10 <= startx && startx <= zielx+10) || !(ziely-10 <= starty && starty <= ziely)){ startx = (int)Math.round(startx - reciprocal); starty++; panel.repaint(); try{ Thread.sleep(200); } catch(InterruptedException e){ e.printStackTrace(); } } } else{ while(!(zielx-10 <= startx && startx <= zielx+10) || !(ziely-10 <= starty && starty <= ziely)){ startx = (int)Math.round(startx - reciprocal); starty--; panel.repaint(); try{ Thread.sleep(200); } catch(InterruptedException e){ e.printStackTrace(); } } } } //Dieser Else-Block hier scheint(!) korrekt zu laufen. Zumindest habe ich noch kein Gegenbeispiel gefunden. else{ if(zielx >= startx){ while(!(zielx-10 <= startx && startx <= zielx+10) || !(ziely-10 <= starty && starty <= ziely)){ starty = (int)Math.round(m + starty); startx++; panel.repaint(); try{ Thread.sleep(200); } catch(InterruptedException e){ e.printStackTrace(); } } } else{ while(!(zielx-10 <= startx && startx <= zielx+10) || !(ziely-10 <= starty && starty <= ziely)){ starty = (int)Math.round(starty - m); startx--; panel.repaint(); try{ Thread.sleep(200); } catch(InterruptedException e){ e.printStackTrace(); } } } } } private double calculateAlterationRate(int startx,int starty,int zielx,int ziely){ return (ziely - starty)/(zielx - startx); //Steigung einer Gerade } class MyPanel extends JPanel { //der Radar mit einem Kreis public void paint(Graphics g){ g.setColor(Color.gray); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.setColor(new Color((float)0.2, (float)0.2, (float)0.2)); g.fillOval(0, 0, 570, 570); g.setColor(Color.black); g.fillOval(35, 35, 500, 500); g.setColor(Color.white); g.drawOval(35, 35, 500, 500); g.setColor(new Color((float)0.0, (float)1.0, (float)0.5)); drawCircles(g); g.setColor(Color.white); g.fillOval(startx, starty, 20, 20); } private void drawCircles(Graphics g){ g.drawOval(235, 235, 100, 100); g.drawOval(185, 185, 200, 200); g.drawOval(135, 135, 300, 300); g.drawOval(85, 85, 400, 400); } } }

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...