在Java初学者中绘制矩形



我正在尝试修改绘制正方形的当前方法:

length = 100;
            int index = 1;
            while (index <= 4) {
                    tParam.forward(length);
                    tParam.turn(90);
                    index++;
            }

基本上不知道要tParam.turn();改什么。帮助?

这应该有效:

int height = 100; //the height of the rectangle
int width = 200; //the width of the rectangle
for(int i = 0; i < 2; i++) //repeat the following twice
{
    tParam.forward(height); //go forward the height of the rectangle
    tParam.turn(90); //turn 90 degrees
    tParam.forward(width); //go forward the width of the rectangle
    tParam.turn(90); //turn 90 degrees
} //end loop

最新更新