好吧我试图用turtlegraphics绘制同心方块,但我无法弄清楚如何使方块在一侧不相互接触。任何帮助?
http://i51.tinypic.com/34gly7b.png
public static void main(String[] args) {
int i,A,M;
A=0;
M=0;
StandardPen pen = new StandardPen();
//RainbowPen pen = new RainbowPen();
//WigglePen pen = new WigglePen();
//WiggleRainbowPen pen = new WiggleRainbowPen();
pen.setColor(Color.green);
pen.setWidth(5);
for (i=1;i<=4;i++){
A=A+20;
M=M+40;
pen.up();
pen.move(A,A);
pen.down();
pen.turn(45);
pen.move(M);
pen.turn(90);
pen.move(M);
pen.turn(90);
pen.move(M);
pen.turn(90);
pen.move(M);
pen.up();
答案 0 :(得分:0)
尝试将此“turtle伪代码”翻译成您的java代码
reset
$startX = 100
$startY = 100
$length = 20
gox $startX
goy $startY
turnleft 45
repeat(4) {
repeat(4) {
# this draws the actual square
forward $length
turnleft 90
}
# move half the square size away
penup
turnright 90
forward $length / 2
turnright 90
forward $length / 2
turnright 180
pendown
#define the size for the next square
$length = $length * 2
}