Having trouble with drawing a Car with TurtleGraphics
hey guys
i need help on a program that should draw a car, erase it, and draw it again but in a different spot on the window. Now I have all of this except when the car is drawn again the wheels aren't moved with the car.
Heres the main:
import TurtleGraphics.StandardPen;
import java.awt.Color;
import TerminalIO.KeyboardReader;
publicclass TestCar
{
publicstaticvoid main(String[] args)
{
KeyboardReader reader =new KeyboardReader();
Car firstCar =new Car();
firstCar.drawCar();
reader.pause();
firstCar.eraseCar();
reader.pause();
Car secondCar =new Car(100, 100);
secondCar.drawCar();
}
}
Here is the class:
import TurtleGraphics.StandardPen;
import java.awt.Color;
publicclass Car{
private StandardPen pen;
privatedouble xPosition, yPosition;
public Car ()
{
xPosition = 0;
yPosition = 0;
pen =new StandardPen();
pen.setColor(Color.red);
}
public Car(double x,double y)
{
this();
xPosition = x;
yPosition = y;
}
publicvoid drawCar()
{
drawRectangle (-150,75, 300, 150);
drawRectangle (-50, 125, 100, 50);
drawCircle (124, -230, 40);
drawCircle (-124, -230, 40);
}
publicvoid drawRectangle (double x,double y,double length,double width)
{
pen.up();
pen.move(x + xPosition, y + yPosition);
pen.down();
pen.setDirection(270);
pen.move(width);
pen.turn(90);
pen.move(length);
pen.turn(90);
pen.move(width);
pen.turn(90);
pen.move(length);
}
publicvoid drawCircle(double x,double y,double radius)
{
double side = 2.0 * Math.PI * radius / 120.0;
pen.up();
pen.move((xPosition + x + radius), ((yPosition + y) - side)/ 2.0);
pen.setDirection(90);
pen.down();
for(int i = 0; i< 120; i++)
{
pen.move(side);
pen.turn(3);
}
}
publicvoid eraseCar()
{
pen.setColor(Color.white);
drawCar();
pen.setColor(Color.red);
}
}
Also the car is supposed to move across the screen once drawn the second time but i haven't figured that out yet. Maybe with a thread:
publicvoid oneSec()
{
try
{
Thread.currentThread().sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
If anyone can help it'd help alot thanks

