// ----------------------------------------------------------------- // imports // ----------------------------------------------------------------- import java.awt.Graphics2D; import javax.swing.JPanel; import javax.swing.JFrame; import java.awt.Graphics; // ----------------------------------------------------------------- // Tiling - Based upon "snub square tiling", for additional // information see: // // https://en.wikipedia.org/wiki/Snub_square_tiling // // ----------------------------------------------------------------- public class Tiling extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; int w = getWidth(); int h = getHeight(); int size = Math.min(w, h) / 20; // ----------------------------------------------------------------- // Create our initial, top-level square // ----------------------------------------------------------------- int xc = w / 2; int yc = w / 2; int x0 = xc - size / 2; int y0 = yc - size / 2; int x1 = xc + size / 2; int y1 = yc + size / 2; Square top = new Square( new XY(x0, y0), new XY(x0, y1), new XY(x1, y1), new XY(x1, y0) ); // ----------------------------------------------------------------- // Create our neighbors and render the image // ----------------------------------------------------------------- top.makeNeighbors(7); top.draw(g2d); } // ----------------------------------------------------------------- // main // ----------------------------------------------------------------- public static void main(String[] args) { JFrame frame = new JFrame("Tiling"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new Tiling()); frame.setSize(750, 750); frame.setLocationRelativeTo(null); frame.setVisible(true); } }