分形(一)

1.套公式的简单分形



 

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

  公式:     d*Math.sin(a*x1)-Math.sin(b*y1);

                  c*Math.cos(a*x1)+Math.cos(b*y1);

 这是显示窗体的类:

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;}

	}
}

                                         

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值