Пример #1
0
  // main(): application entry point
  public void disp(String args) {
    // set up scanner
    Scanner scan = new Scanner(System.in);

    // display program's purpose
    System.out.println(
        "This program will draw a Sierpinski Fractal to the user's specified depth.\n");

    // determine desired cycles and color
    System.out.println(
        "How many cycles would you like the Sierpinski Fractal to be taken out to?\n");
    int a = scan.nextInt();
    System.out.println();

    // produce Sierpinski Fractal
    Point p1 = new Point(50, 50);
    Point p2 = new Point(50, 450);
    Point p3 = new Point(450, 50);
    // Color c =new
    // Color((int)((Math.random()*20000)%256),(int)((Math.random()*10000)%256),(int)((Math.random()*30000)%256));
    Color c = Color.BLACK;
    JFrame window = new JFrame("Sierpinski Fractal-" + a + ".");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setSize(500, 500);
    window.setVisible(true);

    Graphics g = window.getGraphics();
    Graphics2D g2d = (Graphics2D) g;
    // Container con=getContentPane();
    // con.setBackground(Color.BLACK);

    // g2d.setBackground(Color.BLACK);
    System.out.println("\nEnter any character when ready.\n");
    Scanner stdin = new Scanner(System.in);
    stdin.nextLine();

    Sierpinski(g, p1, p2, p3, c, a);
    System.out.println("\nEnter any character if you wish to exit!\n");
    stdin = new Scanner(System.in);
    stdin.nextLine();
    System.exit(0);
  }
Пример #2
0
  /** Returns a DebugGraphics for use in buffering window. */
  private Graphics debugGraphics() {
    DebugGraphics debugGraphics;
    DebugGraphicsInfo info = info();
    JFrame debugFrame;

    if (info.debugFrame == null) {
      info.debugFrame = new JFrame();
      info.debugFrame.setSize(500, 500);
    }
    debugFrame = info.debugFrame;
    debugFrame.show();
    debugGraphics = new DebugGraphics(debugFrame.getGraphics());
    debugGraphics.setFont(getFont());
    debugGraphics.setColor(getColor());
    debugGraphics.translate(xOffset, yOffset);
    debugGraphics.setClip(getClipBounds());
    if (debugFlash()) {
      debugGraphics.setDebugOptions(FLASH_OPTION);
    }
    return debugGraphics;
  }