Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Fractal-tree/Java/fractal-tree.java
Normal file
32
Task/Fractal-tree/Java/fractal-tree.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class FractalTree extends JFrame {
|
||||
|
||||
public FractalTree() {
|
||||
super("Fractal Tree");
|
||||
setBounds(100, 100, 800, 600);
|
||||
setResizable(false);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
private void drawTree(Graphics g, int x1, int y1, double angle, int depth) {
|
||||
if (depth == 0) return;
|
||||
int x2 = x1 + (int) (Math.cos(Math.toRadians(angle)) * depth * 10.0);
|
||||
int y2 = y1 + (int) (Math.sin(Math.toRadians(angle)) * depth * 10.0);
|
||||
g.drawLine(x1, y1, x2, y2);
|
||||
drawTree(g, x2, y2, angle - 20, depth - 1);
|
||||
drawTree(g, x2, y2, angle + 20, depth - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.BLACK);
|
||||
drawTree(g, 400, 500, -90, 9);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new FractalTree().setVisible(true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue