读书人

分形(1)

发布时间: 2013-07-16 22:38:05 作者: rapoo

分形(一)


?

因为觉得这个好漂亮,于是很想画出来,公式已经给出,只要套入程序递归就可以。先初始化常数的值,再代入公式计算,画点的时候注意将类型转化为整型,再改变其值,继续调用。

public class Beati {public static void main(String [] args){Beati window = new Beati();window.showGUI();}public void showGUI(){JFrame window = new JFrame();window.setTitle("Draw");window.setSize(600,600);window.setLocation(200,200);window.setLayout(new FlowLayout());JButton bu =new JButton("我是艺术家");window.add(bu);window.setVisible(true);Graphics g;g=window.getGraphics();Listener al =new Listener(g);bu.addActionListener(al);}}

public class Listener implements ActionListener{private Graphics g;double a,b,c,d;double x1=0;double y1=0;double x2,y2;public Listener(Graphics g){this.g=g;}public void actionPerformed(ActionEvent e){a = 1.40;b = 1.56;c = 1.40; d = -6.56; for(int i=0;i<12133;i++){for(int t=0;t<80;t++){Color co = new Color(t++,t*2,t*3);g.setColor(co);}double x2=d*Math.sin(a*x1)-Math.sin(b*y1);double y2=c*Math.cos(a*x1)+Math.cos(b*y1);int x22= (int) (x2*30)+300;int y22=(int) (y2*30)+200;System.out.println(x22+","+y22);g.drawLine(x22,y22,x22,y22);x1=x2; y1=y2;}}}

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

读书人网 >编程

热点推荐