Skip to content

Commit

Permalink
TurtleSoup Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Wang committed Sep 9, 2013
1 parent ab90143 commit e2c6882
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions src/turtle/TurtleSoup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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);
}
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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<Double> calculateHeadings(List<Integer> xCoords, List<Integer> yCoords) {
throw new RuntimeException();
List<Double> headings = new ArrayList<Double>();

//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;
}

/**
Expand All @@ -104,7 +131,14 @@ public static List<Double> calculateHeadings(List<Integer> xCoords, List<Integer
* @param turtle the turtle context
*/
public static void drawPersonalArt(Turtle turtle) {
throw new RuntimeException();
int length = 1;
int angle = 90;
while (angle < 180) {
turtle.forward(length);
turtle.turn(angle);
length++;
angle++;
}
}

/**
Expand All @@ -116,7 +150,7 @@ public static void drawPersonalArt(Turtle turtle) {
public static void main(String args[]) {
DrawableTurtle turtle = new DrawableTurtle();

drawSquare(turtle, 40);
drawPersonalArt(turtle);

// draw the window
turtle.draw();
Expand Down

0 comments on commit e2c6882

Please sign in to comment.