Hi, ich bin gerad dabei eine 2D grafische Pendel Uhr zu erstellen. Funktioniert auch soweit bei einer Periode von 1000 Millisekunden, nun möchte ich aber eine langsamere Periode haben, dass funktioniert leider nicht so wie es sein sollte. Hab zwar auch schon ne lösung dafür gefunden.
Wollte hier mal nachfragen wie ich das einfacher machen kann einfach nur die Geschwindigkeit der Pendel einstellen. Im Anhang mein Code.
Periode 1000:
und Periode 2000:
Wollte hier mal nachfragen wie ich das einfacher machen kann einfach nur die Geschwindigkeit der Pendel einstellen. Im Anhang mein Code.
Periode 1000:
Java:
public void DrawPendulum(Graphics g, double milisecond){
Graphics2D g2d = (Graphics2D) g;
int pend_x = center_x; //start of pendulum
int pend_y = center_y * 2; //end of pendulum
int pend_size = r_outer / 3; // pendulum size
//max pendulum angle when 1 sec rad = 0.5 -->30° (Amplitude)
double max_angle= (Math.PI *30 / 180);/*
double angle = (milisecond - 500)*max_angle/500;
if(0 == second % 2)
angle = angle*-1;*/
double angle = max_angle * Math.sin((2 * Math.PI * (milisecond)/ 1000));
// coordinates from pendulum circle for time t
pend_x += (int) (center_y * Math.sin(angle));
pend_y += (int) (center_y * Math.cos(angle));
//Draw circle
Ellipse2D.Double pendulumCircle = new Ellipse2D.Double(pend_x - (pend_size / 2), pend_y - (pend_size / 2), pend_size, pend_size);
g2d.setColor(Color.gray);
g2d.fill(pendulumCircle);
g2d.draw(pendulumCircle);
//Draw Line
Line2D.Double pendulum = new Line2D.Double();
pendulum.x1 = center_x;
pendulum.y1 = r_outer + center_y;
pendulum.x2 = pend_x;
pendulum.y2 = pend_y;
System.out.println(milisecond);
//System.out.println(angle);
//System.out.println(pend_x + ", " + pend_y);
g2d.draw(pendulum);
}
und Periode 2000:
Java:
public void DrawPendulum(Graphics g, double milisecond,double second){
Graphics2D g2d = (Graphics2D) g;
int pend_x = center_x; //start of pendulum
int pend_y = center_y * 2; //end of pendulum
int pend_size = r_outer / 3; // pendulum size
//max pendulum angle when 1 sec rad = 0.5 -->30° (Amplitude)
double max_angle= (Math.PI *30 / 180);/*
double angle = (milisecond - 500)*max_angle/500;
if(0 == second % 2)
angle = angle*-1;*/
double angle = max_angle * Math.sin((2 * Math.PI * (milisecond)/ 2000));
if (0 == second % 2)
angle = angle * -1;
// coordinates from pendulum circle for time t
pend_x += (int) (center_y * Math.sin(angle));
pend_y += (int) (center_y * Math.cos(angle));
//Draw circle
Ellipse2D.Double pendulumCircle = new Ellipse2D.Double(pend_x - (pend_size / 2), pend_y - (pend_size / 2), pend_size, pend_size);
g2d.setColor(Color.gray);
g2d.fill(pendulumCircle);
g2d.draw(pendulumCircle);
//Draw Line
Line2D.Double pendulum = new Line2D.Double();
pendulum.x1 = center_x;
pendulum.y1 = r_outer + center_y;
pendulum.x2 = pend_x;
pendulum.y2 = pend_y;
System.out.println(milisecond);
//System.out.println(angle);
//System.out.println(pend_x + ", " + pend_y);
g2d.draw(pendulum);
}