Heart.java


Below is the syntax highlighted version of Heart.java from §1.5 Input and Output.


/******************************************************************************
 *  Compilation:  javac Heart.java
 *  Execution:    java Heart
 *  Dependencies: StdDraw.java
 *
 *  Draw a pink heart (a filled diamond plus two filled circles).
 *
 ******************************************************************************/

public class Heart {
    public static void main(String[] args) {
        StdDraw.setXscale(-1.5, +1.5);
        StdDraw.setYscale(-1.5, +1.5);
        StdDraw.setPenColor(StdDraw.PINK);

        // draw diamond
        double[] xs = { -1,  0, 1, 0 };
        double[] ys = {  0, -1, 0, 1 };
        StdDraw.filledPolygon(xs, ys);

        // circles
        StdDraw.filledCircle(+0.5, 0.5, 1 / Math.sqrt(2));
        StdDraw.filledCircle(-0.5, 0.5, 1 / Math.sqrt(2));
    }

}


Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne.
Last updated: Fri Oct 20 14:12:12 EDT 2017.