📄 l.java~1~
字号:
StartDepth =13; ruleNumber =4; sStart = "K"; sRule[0][0]="S"; sRule[0][1]="[+++G][---H]FFS"; sRule[1][0]="G"; sRule[1][1]="+G[-FH]F"; sRule[2][0]="H"; sRule[2][1]="-H[+FG]F"; sRule[3][0]="K"; sRule[3][1]="FSF"; //reinit(); } else if(k==4){ //枝 pStartX =200; pStartY =5; direction_init =90; lengthF =1.5; rotation =-25.7341; StartDepth =6; ruleNumber =1; sStart = "F"; sRule[0][0]="F"; sRule[0][1]="F[+F]F[-F]F"; //reinit(); } else if(k==5){ //星 pStartX =15; pStartY =200; direction_init =0; lengthF =4.5; rotation =-60; StartDepth =5; ruleNumber =1; sStart = "F"; sRule[0][0]="F"; sRule[0][1]="F-F++F-F"; //reinit(); } else if(k==6){ //蒲公英 pStartX =200; pStartY =10; direction_init =90; lengthF =0.37; rotation =30; StartDepth = 10; ruleNumber =2; sStart = "Y"; sRule[0][0]="X"; sRule[0][1]="X[-FFF][+FFF]FX"; sRule[1][0]="Y"; sRule[1][1]="YFX[+Y][-Y]"; //reinit(); } else if(k==7){ //灌木丛 pStartX =250; pStartY =20; direction_init =90; lengthF =3.5; rotation =-30; StartDepth =6; ruleNumber =1; sStart = "F"; sRule[0][0]="F"; sRule[0][1]="FF-[-F+F+F]+[+F-F-F]"; //reinit(); } else if(k==8){ //棕榈 pStartX =200; pStartY =20; direction_init =90; lengthF =5.6; rotation =-18; StartDepth =12; ruleNumber =5; sStart = "SLFFF"; sRule[0][0]="S"; sRule[0][1]="[+++H][---G]TS"; sRule[1][0]="G"; sRule[1][1]="+H[-G]L"; sRule[2][0]="H"; sRule[2][1]="-G[+H]L"; sRule[3][0]="T"; sRule[3][1]="TL"; sRule[4][0]="L"; sRule[4][1]="[-FFF][+FFF]F"; //reinit(); } else if(k==9){ //开花的草 pStartX =200; pStartY =10; direction_init =90; lengthF =3; rotation =-30; StartDepth = 8; ruleNumber =2; sStart = "G"; sRule[0][0]="G"; sRule[0][1]="[+FGF][-FGF]XG"; sRule[1][0]="X"; sRule[1][1]="XFX"; //reinit(); } else if(k==10){ //灌木丛 pStartX =370; pStartY =30; direction_init =90; lengthF =2; rotation =-1.2; StartDepth =6; ruleNumber =1; sStart = "F"; sRule[0][0]="F"; sRule[0][1]="F[+++++++++++++++++++++++++F]-F[-------------------------F]F"; //reinit(); } else if(k==11){ //杨柳 pStartX =170; pStartY =0; direction_init =90; lengthF =7; rotation =-22.5; StartDepth =5; ruleNumber =1; sStart = "F"; sRule[0][0]="F"; sRule[0][1]="FF+[+F-F-F]-[-F+F+F]"; //reinit(); } else if(k==12){ //Juliet集 pStartX =95; pStartY =250; direction_init =0; lengthF =1; rotation =90; StartDepth = 17; ruleNumber =2; sStart = "X"; sRule[0][0]="X"; sRule[0][1]="X+YF+"; sRule[1][0]="Y"; sRule[1][1]="-FX-Y"; //reinit(); } else if(k==13){ //砖墙 pStartX =30; pStartY =40; direction_init =0; lengthF =13; rotation =90; StartDepth = 4; ruleNumber =2; sStart = "X"; sRule[0][0]="X"; sRule[0][1]="XFYFX+F+YFXFY-F-XFYFX"; sRule[1][0]="Y"; sRule[1][1]="YFXFY-F-XFYFX+F+YFXFY"; //reinit(); } else if(k==14){ //砖砌X形 pStartX =80; pStartY =90; direction_init =0; lengthF =3.5; rotation =90; StartDepth =4; ruleNumber =1; sStart = "F+F+F+F"; sRule[0][0]="F"; sRule[0][1]="F+F-F-FF+F+F-F"; //reinit(); } else if(k==15){ //三角绕三角 pStartX =200; pStartY =10; direction_init =0; lengthF =1.7; rotation =-60; StartDepth = 6; ruleNumber =2; sStart = "X"; sRule[0][0]="X"; sRule[0][1]="--FXF++FXF++FXF--"; sRule[1][0]="F"; sRule[1][1]="FFF"; //reinit(); } else if(k==16){ //一笔迷宫 pStartX =50; pStartY =30; direction_init =0; lengthF =10; rotation =-90; StartDepth = 6; ruleNumber =2; sStart = "X"; sRule[0][0]="X"; sRule[0][1]="-YF+XFX+FY-"; sRule[1][0]="Y"; sRule[1][1]="+XF-YFY-FX+"; //reinit(); } else if(k==17){ //树 pStartX =200; pStartY =10; direction_init =90; lengthF =0.35; rotation =30; StartDepth = 10; ruleNumber =2; sStart = "X"; sRule[0][0]="X"; sRule[0][1]="F[+X]F[-X]+X"; sRule[1][0]="F"; sRule[1][1]="FF"; //reinit(); } else if(k==18){ //对称的树 pStartX =200; pStartY =10; direction_init =90; lengthF =0.35; rotation =30; StartDepth = 10; ruleNumber =2; sStart = "X"; sRule[0][0]="X"; sRule[0][1]="F[+X][-X]FX"; sRule[1][0]="F"; sRule[1][1]="FF"; //reinit(); } reinit(); }public void start(){ if (runner == null){ runner= new Thread(this); runner.start(); }}public void stop(){ if (runner!=null){ runner.stop(); runner=null; start=false; running = false; }}public void run() { while(true){ if(start&&(!running)){ running=true; start=false; bStop=false; g=this.getGraphics(); g.setColor(new Color(110,170,60)); // 定义画笔的颜色 g.clearRect(0,0,400,450); a = new doublePoint(pStartX,pStartY); // 起始点 direction = direction_init; // 起始的方向 turtleGraphic(g, sStart, StartDepth); // 核心程序 running=false; } }}public boolean action(Event ev, Object arg){ if ( ev.target instanceof Button) {//instanceof实例 String button = (String) arg; if (button.equals("单步迭代")) { btnStep.setLabel("迭代一步"); StartDepth = 1; lblStep.setText("第"+String.valueOf(StartDepth)+"步"); //bStop=true; update(this.getGraphics()); } else if (button.equals("设置参数")) { LSet ls=new LSet(this); ls.setSize(420,540); ls.show(); btnStep.setLabel("单步迭代"); lblStep.setText(" "); } else if (button.equals("迭代一步")){ StartDepth= (StartDepth+1) % (initDepth+1); if (StartDepth == 0) StartDepth = 1; lblStep.setText("第"+String.valueOf(StartDepth)+"步"); update(this.getGraphics()); } return true; }else return false;}} class doublePoint { //为保存双精度的点而新建一个类 double x; double y; doublePoint(double x1,double y1){ x=x1;y=y1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -