HelloTurtle.java
Below is the syntax highlighted version of HelloTurtle.java
from §2.4 Input and Output.
/*************************************************************************
* Compilation: javac HelloTurtle.java
* Execution: java HelloTurtle s N
* Dependencies: StdDraw.java
*
* Plots the String s, N times at random locations, and in random
* colors.
*
* % java HelloTurtle Hello 10
*
* % java HelloTurtle World 15
*
* % java HelloTurtle Java 20
*
*
*************************************************************************/
import java.awt.Color;
import java.awt.Font;
public class HelloTurtle {
public static void main(String[] args) {
String s = args[0];
int N = Integer.parseInt(args[1]);
int SIZE = 512;
StdDraw.create(SIZE, SIZE);
StdDraw.setScale(0, 0, 1, 1);
StdDraw.clear(Color.black);
Font f = new Font("Arial", Font.BOLD, 60);
StdDraw.setFont(f);
for (int i = 0; i < N; i++) {
StdDraw.setColor(Color.getHSBColor((float) Math.random(), 1.0f, 1.0f));
StdDraw.go(Math.random(), Math.random());
StdDraw.write(s);
}
StdDraw.show();
}
}
Last updated: Sun Oct 24 22:27:35 EDT 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.