1
這是一個程序,通過在屏幕上移動烏龜來創建分形。爲什麼我的程序中的烏龜不會移動?任何幫助將不勝感激!我很確定這是一個簡單的修復,但我找不到它。爪哇龜圖形動畫基本
感謝
/**
* This program is to create a fractal
*/
import java.awt.*;
class FractalEngine
{
World world = new World(700,700);
Turtle turt = new Turtle(1,1,world);
public void drawFractal(String rule)
{
turt.penUp();
turt.moveTo(350,350);
int lengthofRule = rule.length();
int start = 0;
int fin = 1;
String tinyChar;
for(int a = 0; a <= lengthofRule; a++)
{
if(start == 9)
tinyChar = rule.substring(start);
else
tinyChar = rule.substring(start,fin);
if(tinyChar == "F")
turt.forward(25);
else if(tinyChar == "-")
turt.turnLeft();
else if(tinyChar == "+")
turt.turnRight();
else
break;
start++;
fin++;
System.out.println(tinyChar);
}
}
}
public class FractalEngineTester
{
public static void main(String[] args)
{
FractalEngine fEng = new FractalEngine();
String rule = "F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F";
//String rule = "F-F+F+F-F";
fEng.drawFractal(rule);
//String rule = "F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F";
//String rule = "F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F-F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F-F-F+F+F-F-F-F+F+F-F+F-F+F+F-F+F-F+F+F-F-F-F+F+F-F";
}
}