package image;

/*************************************************************************
 *  Compilation:  javac Turtle.java
 *  Execution:    java Turtle
 *
 *  Data type for turtle graphics using standard draw.
 *
 *************************************************************************/

import math.Maths;
import stdlib.Color;
import stdlib.StdDraw;

public class Turtle {
    private double x, y;     // turtle is at (x, y)
    private double angle;    // facing this many degrees counterclockwise from the x-axis

    static private StdDraw sd = new StdDraw();;
    // start at (x0, y0), facing a0 degrees counterclockwise from the x-axis
    public Turtle(double x0, double y0, double a0) {
        x = x0;
        y = y0;
        angle = a0;
    }

    // rotate orientation delta degrees counterclockwise
    public void turnLeft(double delta) {
        angle += delta;
    }

    // move forward the given amount, with the pen down
    public void goForward(double step) {
        double oldx = x;
        double oldy = y;
        x += step * Maths.cosd(angle);
        y += step * Maths.sind(angle);
        sd.line(oldx, oldy, x, y);
    }

    // pause t milliseconds
    public void pause(int t) {
        sd.show(t);
    }


    public void setPenColor(Color color) {
        sd.setPenColor(color);
    }

    public void setPenRadius(double radius) {
        sd.setPenRadius(radius);
    }

    public void setCanvasSize(int width, int height) {
        sd.setCanvasSize(width, height);
    }

    public void setXscale(double min, double max) {
        sd.setXscale(min, max);
    }

    public void setYscale(double min, double max) {
        sd.setYscale(min, max);
    }


    // sample client for testing
    public static void main(String[] args) {
        double x0 = 0.5;
        double y0 = 0.0;
        double a0 = 60.0;
        double step = Math.sqrt(3)/2.;
        Turtle turtle  = new Turtle(x0, y0, a0);
        turtle.goForward(step);
        turtle.turnLeft(120.0);
        turtle.goForward(step);
        turtle.turnLeft(120.0);
        turtle.goForward(step);
        turtle.turnLeft(120.0);
    }

}
