Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Koch {
- private static int startingn;
- // plot Koch curve of order n, with given step size
- public static void koch(int n, double step, Turtle turtle) {
- if (n == 0) {
- turtle.goForward(step);
- return;
- }
- koch(n-1, step, turtle);
- turtle.turnLeft(60.0);
- koch(n-1, step, turtle);
- turtle.turnLeft(-120.0);
- koch(n-1, step, turtle);
- turtle.turnLeft(60.0);
- koch(n-1, step, turtle);
- }
- private static double getArea(double step) {
- double output = 0;
- int pow = startingn-1;
- double len = step;
- output += (Math.sqrt(3)/4)*Math.pow(len,2);
- for(int i = 1; i < startingn; i++) {
- int push = 3*(4*i);
- output += push*(Math.sqrt(3)/4)*Math.pow((len/Math.pow(3,i)),2);
- System.out.println(i);
- }
- //Returning the total area.
- return output;
- }
- public static void main(String[] args) {
- startingn = 3;
- double step = 1.0 / Math.pow(3.0, startingn);
- Turtle turtle = new Turtle(0.0, 0.0, 0.0);
- koch(startingn, step, turtle);
- System.out.println(getArea(3));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement