Sierpinski.java - Compilation javac Sierpinski.java...

This preview shows page 1 - 2 out of 2 pages.

/************************************************************************* * Compilation: javac Sierpinski.java * Execution: java Sierpinski * * @author: Monica Muthuraj, NETID: mm2775 * *************************************************************************/ public class Sierpinski { // Height of an equilateral triangle whose sides are of the specified length. public static double height(double length) { double height = (length*Math.sqrt(3))*(0.5); return height; } // Draws a filled equilateral triangle whose bottom vertex is (x, y) // of the specified side length. public static void filledTriangle(double x, double y, double length) { double height = height(length); double mid = length/2.0; double[] xcord = {x, x-mid, x+mid}; double[] ycord = {y, y+height, y+height}; StdDraw.filledPolygon(xcord,ycord); } // Draws a Sierpinski triangle of order n, such that the largest filled // triangle has bottom vertex (x, y) and sides of the specified length.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture