public void paintComponent(Graphics g) {
new FractalTree().setVisible(true);
}
public class FractalTree extends JFrame {
public FractalTree() {
// super("Fractal Tree");
setBounds(100, 100, 800, 600);
// setResizable(false);
}
private void RecurLine(Graphics g, int x1, int y1, double angle, int n) {
if (n == 1) return;
int x2 = x1 + (int) (Math.cos(Math.toRadians(angle)) * n * 10.0);
int y2 = y1 + (int) (Math.sin(Math.toRadians(angle)) * n * 10.0);
g.drawLine(x1, y1, x2, y2);
RecurLine(g, x2, y2, angle - 20, n - 1);
RecurLine(g, x2, y2, angle + 20, n - 1);
}
@Override
public void paint(Graphics g) {
g.setColor(Color.BLUE);
RecurLine(g, 400, 500, -90, 9);
}
}