/* Laura Toma csci 101 */ //for graphics import java.awt.*; public class Sierpinski { public static int DEPTH = 10; public Sierpinski (String[] args) {} public void main (int x1, int y1, int x2, int y2, int x3, int y3, Graphics2D g) { /* note the parameters of main(): When main() is called by the * FractalDriver program, it is given specific values for * these parameters. FractalDriver program is the one that * handles the graphics, opens a window, etc, and computes the * position of the vertices of the initial triangle so that * the initial triangle nicely fis in the graphics window, and * then it calls main with these parameters */ /* call a method to tell the graphics object to minimize the * effects of rounding errors while drawing, so that the * drawing looks better */ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); /* call the method to render a Sierpinski fractal on a * triangle with vertices (x1, y1), (x2, y2), (x3, y3). Note * that the values x1, y1, x2, y2, x3, y3 are the parameters * of main(), and are used in the call to render(): when * main() is called, it is given these arguments, which it * then passes along to render(). */ render(x1, y1, x2, y2, x3, y3, g, DEPTH); } /* parameters: the coordinates of the three vertices of the * triangle in which it draws, a graphics object g * that knows * how to draw, and the desired depth of recursion. All * these * are assumed TO BE KNOWN inside render(). When render() is * * called, it is called with specific values for its parameters function: render the Sierpinski fractal on the given triangle recursively. */ public static void render (int x1, int y1, int x2, int y2, int x3, int y3, Graphics2D g, int depth) { //check stop point } /* this method draws a filled triangle between points (x1, y1), * (x2, y2), (x3,y3). The details of drawing on the screen are * handled by the parameter g, which is an object of type * Graphics2D, a class that knows how to handle 2D graphics in * Java. * Example of calling this method: * drawFilledTriangle(10, 10, 60, 60, 100, 100, g); * This draws a triangle between the points specified as arguments */ public static void drawFilledTriangle(int x1, int y1, int x2, int y2, int x3, int y3, Graphics2D g) { Polygon p = new Polygon(); p.addPoint(x1, y1); p.addPoint(x2, y2); p.addPoint(x3, y3); g.fill(p); } } //end of class