diff --git a/src/turtle/TurtleSoup.java b/src/turtle/TurtleSoup.java index 3c0407d..5fd1061 100644 --- a/src/turtle/TurtleSoup.java +++ b/src/turtle/TurtleSoup.java @@ -13,7 +13,10 @@ public class TurtleSoup { * @param sideLength length of each side */ public static void drawSquare(Turtle turtle, int sideLength) { - throw new RuntimeException(); + for (int x = 0; x < 4; x++) { + turtle.forward(sideLength); + turtle.turn(90); + } } /** @@ -26,7 +29,8 @@ public static void drawSquare(Turtle turtle, int sideLength) { * @return angle, in degrees between 0 and 360 */ public static double calculateRegularPolygonAngle(int sides) { - throw new RuntimeException(); + double angle = (double)((sides - 2) * 180)/sides; + return angle; } /** @@ -40,7 +44,8 @@ public static double calculateRegularPolygonAngle(int sides) { * @return the integer number of sides */ public static int calculatePolygonSidesFromAngle(double angle) { - throw new RuntimeException(); + int sides = (int)Math.ceil(360/(180 - angle)); + return sides; } /** @@ -53,7 +58,12 @@ public static int calculatePolygonSidesFromAngle(double angle) { * @param sideLength length of each side */ public static void drawRegularPolygon(Turtle turtle, int sides, int sideLength) { - throw new RuntimeException(); + double insideAngle = calculateRegularPolygonAngle(sides); + System.out.println(insideAngle); + for (int x = 0; x < sides; x++) { + turtle.forward(sideLength); + turtle.turn(180 - insideAngle); + } } /** @@ -75,7 +85,15 @@ public static void drawRegularPolygon(Turtle turtle, int sides, int sideLength) */ public static double calculateHeadingToPoint(double currentHeading, int currentX, int currentY, int targetX, int targetY) { - throw new RuntimeException(); + double heading = Math.toDegrees(Math.atan2(targetX - currentX, targetY - currentY)); + double angle = currentHeading; + if (heading < currentHeading) { + angle = 360 - currentHeading - heading; + } + else { + angle = heading - currentHeading; + } + return angle; } /** @@ -90,7 +108,16 @@ public static double calculateHeadingToPoint(double currentHeading, int currentX * @return list of heading adjustments between points, of size #points-1. */ public static List calculateHeadings(List xCoords, List yCoords) { - throw new RuntimeException(); + List headings = new ArrayList(); + + //double currentHeading = calculateHeadingToPoint(0, xCoords.get(0), yCoords.get(0), xCoords.get(1), yCoords.get(1)); + //headings.add(currentHeading); + double currentHeading = 0; + for (int x = 0; x < xCoords.size() - 1; x++) { + currentHeading = calculateHeadingToPoint(currentHeading, xCoords.get(x), yCoords.get(x), xCoords.get(x + 1), yCoords.get(x + 1)); + headings.add(currentHeading); + } + return headings; } /** @@ -104,7 +131,14 @@ public static List calculateHeadings(List xCoords, List