Solved Task 3
This commit is contained in:
parent
124caff620
commit
c8aa16c246
|
@ -6,7 +6,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
/*
|
|
||||||
public class ADS4_2_test {
|
public class ADS4_2_test {
|
||||||
HilbertServer hlb;
|
HilbertServer hlb;
|
||||||
Turtle turtle;
|
Turtle turtle;
|
||||||
|
@ -97,4 +97,3 @@ public class ADS4_2_test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package ch.zhaw.ads;
|
||||||
|
|
||||||
|
import ch.zhaw.ads.CommandExecutor;
|
||||||
|
import ch.zhaw.ads.Turtle;
|
||||||
|
|
||||||
|
public class HilbertServer implements CommandExecutor {
|
||||||
|
Turtle turtle;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(String command) {
|
||||||
|
int depth = Integer.parseInt(command);
|
||||||
|
double dist = 0.8 / (Math.pow(2,depth+1)-1);
|
||||||
|
turtle = new Turtle(0.1, 0.1);
|
||||||
|
hilbert(depth, dist, -90);
|
||||||
|
return turtle.getTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hilbert(int depth, double dist, double angle){
|
||||||
|
if(depth < 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
depth --;
|
||||||
|
turtle.turn(-angle);
|
||||||
|
// draw recursive
|
||||||
|
hilbert(depth, dist, -angle);
|
||||||
|
turtle.move(dist);
|
||||||
|
turtle.turn(angle);
|
||||||
|
// draw recursive
|
||||||
|
hilbert(depth, dist, angle);
|
||||||
|
turtle.move(dist);
|
||||||
|
// draw recursive
|
||||||
|
hilbert(depth, dist, angle);
|
||||||
|
turtle.turn(angle);
|
||||||
|
turtle.move(dist);
|
||||||
|
// draw recursive
|
||||||
|
hilbert(depth, dist, -angle);
|
||||||
|
turtle.turn(-angle);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue