//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //A Simple Fractal //Description: Draws a Sierpinski Triangle with a square for a starting shape. //CS 284 //Programmed by Jonathan Voris //for 1/24/06 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //for graphics usage import java.awt.*; //for keyboard input import java.util.Scanner; //the fractal class extends Frame to use its window calls class fractal extends Frame { private int windowSize = 700; private int numSteps = 1; public static void main(String[] args) { //call fractal's constructor fractal fract = new fractal(); //start the fractal drawing process fract.run(); } //fractal constructor creates a window by calling Frame methods public fractal() { //window title setTitle("Sierpinski Triangle"); //window location setLocation(0, 0); //window size setSize(windowSize, windowSize); //background color of the window setBackground(Color.white); //make the window appear setVisible(true); } //run performs the fractal's drawing process private void run() { //create a new scanner for reading keyboard input Scanner sc = new Scanner(System.in); //loop continuously while (true) { //input the number of steps of the fractal to draw System.out.print("Please input the number of steps to use:"); numSteps = sc.nextInt(); System.out.println(); // ask window system to call paint() to draw fractal with // the new number of steps repaint(); } } public void paint(Graphics g) { g.setColor(Color.black); //PLACE RECURSIVE FRACTAL CALL HERE } }