-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathRegexFractalMain.java
45 lines (40 loc) · 1.56 KB
/
RegexFractalMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import javax.swing.BorderFactory;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class RegexFractalMain {
private static class ImagePanel extends JPanel {
private final Image img;
public ImagePanel(Image img, String title) {
this.img = img;
this.setToolTipText(title);
this.setPreferredSize(new Dimension(img.getWidth(this), img.getHeight(this)));
this.setBorder(BorderFactory.createEtchedBorder());
}
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, this);
}
}
private static final String[] REGEXES = {
".*(13|31|24|42).*", ".*[^4][^32]3.*",
"[34]*2.*", "[124]*3[24]*(3.*)?",
".*(12|(2(?![34]))).*", ".*(13|32|((?<!4)24)).*(?!\\1)$"
};
public static void main(String[] args) {
JFrame frame = new JFrame("Regular Expression Fractals");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLayout(new GridLayout(3, 4));
for(String regex: REGEXES) {
BufferedImage resultF = RegexFractal.render(regex, 256, false);
frame.add(new ImagePanel(resultF, regex + " with no rotate"));
BufferedImage resultT = RegexFractal.render(regex, 256, true);
frame.add(new ImagePanel(resultT, regex + " with rotate"));
}
frame.pack();
frame.setVisible(true);
}
}