Rose.java
Below is the syntax highlighted version of Rose.java
from §2.4 Input and Output.
/*************************************************************************
* 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.
*
*************************************************************************/
import java.awt.Color;
public class Rose {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
int SIZE = 512;
StdDraw.create(SIZE, SIZE);
StdDraw.setScale(-1, -1, 1, 1);
StdDraw.setColor(Color.pink);
for (double theta = 0.0; theta <= 360.0; theta += 0.01) {
double r = Math.sin(N * Math.toRadians(theta));
// fly to center
StdDraw.go(0, 0);
// set angle to theta
StdDraw.rotate(theta);
StdDraw.goForward(r);
StdDraw.spot();
StdDraw.rotate(-theta);
}
StdDraw.show();
}
}
Last updated: Thu Sep 23 16:38:21 EDT 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.