package image;

import stdlib.Color;
import stdlib.StdDraw;


/*************************************************************************
 *  Compilation:  javac Rose.java
 *  Execution:    java Rose N
 *  Dependencies: StdDraw.java
 *
 *  Plots an N petal rose (if N is odd) and a 2N-petal rose if N is
 *  even, using standard graphics.
 *
 *************************************************************************/

public class Rose { 

    public static void main(String[] args) { 
//        int N = Integer.parseInt(args[0]);
        int N = 8;
        StdDraw sd = new StdDraw();
        sd.setXscale(-1, +1);
        sd.setYscale(-1, +1);
        sd.setPenColor(Color.PURPLE);

        double x0 = 0, y0 = 0;
        for (double t = 0.0; t <= 360.0; t += 0.1) {
            double theta = Math.toRadians(t);
            double r = Math.sin(N * theta);
            double x1 = r * Math.cos(theta);
            double y1 = r * Math.sin(theta);
            sd.line(x0, y0, x1, y1);
            x0 = x1;
            y0 = y1;
        }
    }

}