-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRose.java
More file actions
32 lines (27 loc) · 949 Bytes
/
Copy pathRose.java
File metadata and controls
32 lines (27 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*************************************************************************
* 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]);
StdDraw.setXscale(-1, +1);
StdDraw.setYscale(-1, +1);
StdDraw.setPenColor(StdDraw.PINK);
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);
StdDraw.line(x0, y0, x1, y1);
x0 = x1;
y0 = y1;
}
}
}