Ejemplo n.º 1
0
 public void actionPerformed(ActionEvent arg0) {
   Fractal fractal = view.getFractal();
   if (fractal.getOrder() > 0) {
     fractal.setOrder(fractal.getOrder() - 1);
   }
   view.updateDrawing();
 }
Ejemplo n.º 2
0
  private static void createAndShowGUI() {
    JFrame frame = new JFrame("Fractal");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout layout = new SpringLayout();
    frame.setLayout(layout);

    Orientation nw = new Orientation();
    nw.setOffset(0, 0);
    Orientation sw = new Orientation();
    sw.setOffset(0, regionSize);
    Orientation se = new Orientation();
    se.setOffset(regionSize, regionSize);

    Fractal fractal = new Fractal(regionSize);
    fractal.setOrientations(nw, sw, se);

    layout.putConstraint(SpringLayout.WEST, fractal, 5, SpringLayout.WEST, frame.getContentPane());
    layout.putConstraint(
        SpringLayout.NORTH, fractal, 5, SpringLayout.NORTH, frame.getContentPane());

    layout.putConstraint(SpringLayout.WEST, nw, 5, SpringLayout.EAST, fractal);
    layout.putConstraint(SpringLayout.NORTH, nw, 0, SpringLayout.NORTH, fractal);

    layout.putConstraint(SpringLayout.NORTH, sw, 5, SpringLayout.SOUTH, nw);
    layout.putConstraint(SpringLayout.WEST, sw, 0, SpringLayout.WEST, nw);

    layout.putConstraint(SpringLayout.NORTH, se, 5, SpringLayout.SOUTH, nw);
    layout.putConstraint(SpringLayout.WEST, se, 5, SpringLayout.EAST, sw);

    layout.putConstraint(
        SpringLayout.SOUTH, frame.getContentPane(), 5, SpringLayout.SOUTH, fractal);
    layout.putConstraint(SpringLayout.EAST, frame.getContentPane(), 5, SpringLayout.EAST, se);

    frame.add(nw);
    frame.add(sw);
    frame.add(se);

    frame.add(fractal);

    frame.setResizable(false);
    frame.pack();
    frame.setVisible(true);
  }
Ejemplo n.º 3
0
  /** Builds the fractal. Draws the fractal on screen. Writes the fractal to image. */
  public BuildFractal() {

    pix = new int[width * height];
    int index = 0;
    for (int y = hOffset; y < height + hOffset; y++) {
      for (int x = wOffset; x < width + wOffset; x++) {
        pix[index] = Fractal.countVariable(x, y, 0xFF000000, variablesCollection);
        // pix[index] = Fractal.countDrippingMatrix(x, y);
        index++;
      }
      if (y % 1000 == 0) System.out.println("Lines " + y);
    }

    System.gc();

    i =
        Toolkit.getDefaultToolkit()
            .createImage(new MemoryImageSource(width, height, pix, 0, width));
    bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    bi.getGraphics().drawImage(i, 0, 0, null);

    Frame frame = new Frame("Fractal");
    frame.add(new DrawFractal(this));
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    frame.setSize(
        Toolkit.getDefaultToolkit().getScreenSize().width / 2,
        Toolkit.getDefaultToolkit().getScreenSize().height / 2);

    file = new File(imgName + ".jpg");
    try {
      ImageIO.write(bi, "jpg", file);
    } catch (IOException e) {
      e.printStackTrace();
    }

    frame.setVisible(true);

    while (file.canRead() == false) {}

    // System.exit(0);

  }
Ejemplo n.º 4
0
 public static int countCheckboards(int x, int y) {
   Collection<Rules> c = new ArrayList<Rules>();
   c.add(Rules.TAN);
   c.add(Rules.SQRT);
   return Fractal.countVariable(x, y, 0xFF000000, c);
 }