/*
 * Polygon program
 */

// First include standard declarations

#include<iostream>
#include "Myro.h"
using namespace std;

// Define the new functions...

// travelStraight (D) goes forward D inches.
void travelStraight(double distance) {
    // set up your robotŐs speed
    double inchesPerSec = 12.0;
    // Travel in a straight line for distance inches
    robot.forward(1, distance/inchesPerSec);
}

void degreeTurn(double angle) {
    double degreesPerSec = 185;
    // Spin a total of angle degrees (positive or negative)
    // Positive angles turn left
    if (angle >= 0) {
        robot.turnLeft(1,angle/degreesPerSec);
    } else { // angle < 0
        robot.turnRight(1,-angle/degreesPerSec);
    }
}

void drawPolygon (int Sides, double Length) {
    // Draw a regular polygon with Sides number of sides
    // and each side of length Length.
    travelStraight(Length);
    for (int side = 1; side < Sides; side++) { // side = number of sides drawn
        degreeTurn(360/Sides);
        travelStraight(Length);
    }
}

int main() {

    string userInput = askQuestion("Change my pen to a "
        "different color and press 'OK' when ready",
                                   "OK");

    // Given the number of sides and the length of each side,
    // draw a regular polygon

    int nSides;         // number of polygon sides
    double sideLength;  // length of polygon side
    connect();

    // First, ask the user for the number of sides and
    // side length
    cout << "Given # of sides and side length I will draw"
        << endl;
    cout << "a polygon for you. " // string continues...
        << "Specify side length in inches." << endl;

    cout << "Enter # of sides in the polygon: ";
    cin >> nSides;
    cout << "Enter the length of each side: ";
    cin >> sideLength;

// Draw the polygon
    drawPolygon(nSides, sideLength);

    speak("Look! I can draw.");
    disconnect();
}

