?? tree.java
字號:
//分形樹(分形頻道:fractal.cn)
import java.awt.*;
import javax.swing.*;
import java.lang.*;
public class Tree extends JApplet{
public static final int MINI_LENGTH = 3;
public void init(){
new Tree();
}
public void frameSet(){
Tree shapes = new Tree();
JFrame fra = new JFrame("welcome");
fra.getContentPane().add(shapes,BorderLayout.CENTER);
fra.setSize(new Dimension(670,400));
fra.setResizable(false);
fra.setVisible(true);
}
public static void main(String args[]){
new Tree().frameSet();
}
// /////////////////////////////////////////////////////////////
public void paint(Graphics g){
g.setColor(Color.black);
drawShape(g, 300, 550, -Math.PI / 2, 300);
}
public void drawShape(Graphics g, double x, double y,
double angle, int length){
double x1,y1;
if (length > MINI_LENGTH){
x1 = Math.cos(angle) * length + x;
y1 = Math.sin(angle) * length + y;
g.drawLine((int) x1,(int) y1, //the first point.
(int) x, (int) y); //the second point.
drawShape(g, (x1 + x) / 2, (y1 + y) / 2,
angle - Math.PI / 8, length / 2);
drawShape(g, x1, y1, angle + Math.PI / 8, length / 2);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -