// middle of the canvas,
// can be found as follows=>
// x_middle = getSize().width / 2;
// y_middle = getSize().height/ 2;
// length = getSize().width / 2 - 1; //Choose a length for the pendulum
x_middle = 150;
y_middle = 150;
length = 149;
degrees_to_radians = 3.14159 / 180.0;
// sin and cos work in units
// called RADIANS which are different from degrees.
// Basically there are 2 times pi of them (or 6.28) in 360 degrees
// which is a full circle.
// Draw a big circle
g.drawOval(0,0,299,299);
// Step the second hand through 360 degrees in 5 degree steps
for (int angle = 0 ; angle < 360; angle = angle + 5 )
{
// Draw second hand
g.drawLine(x_middle , y_middle ,
x_middle+(int)(Math.cos((double)angle*degrees_to_radians)*length),
y_middle+(int)(Math.sin((double)angle*degrees_to_radians)*length));
// put the delay loop here
} // end of for loop