Okay so I have an ellipse and I could like to have a "racecar" (actually just a 10x10 rectangle) follow the ellipse around the edge. The point that is always touching the ellipse is the upper left hand corner of the "racecar." I'm not even sure where to begin writing this code. I want to make it move a random distance along the edge of the ellipse. so i guess the code could look something like this:
while(!raceOver)
{
car.moveRandomDistance();
repaint();
waitSomeTime(500);
}
This is a thread so this would be inside the run() method and also inside try{}catch{}
The only advice I got was to use angles and to update the angle each loop but not sure about that.
Any help would be awesome. Thanks.
Some more info:
- the waitSomeTime() is simply made into a method in order to synchronize the methods and ensure one finishes before moving on
- car is the variable that holds a racecar object
- The car.move() method takes two ints, the x coordinate and y coordinate of its next location. They make up the point of the upper left hand corner.