用裴波那契数列所得半径,作为圆的半斤,画图如下:

 

用裴波那契数列简单构图_休闲

以下为源代码:

  1. import java.awt.Color;  
  2. import java.awt.Graphics;  
  3. import javax.swing.JFrame;  
  4. import javax.swing.JPanel;  
  5. public class Draw{  
  6.     public static void main(String[] args){  
  7.         //初始化frame容器  
  8.         Circle e=new Circle();  
  9.         e.setVisible(true);  
  10.           
  11.     }  
  12.  
  13. }  
  14. //定义窗口  
  15. class Circle extends JFrame{      
  16.     private static final long serialVersionUID = 1L;  
  17.  
  18.     public Circle(){  
  19.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  20.         setSize(1280,768);  
  21.         getContentPane().setBackground(Color.red);  
  22.         setVisible(true);  
  23.         DrawPanel panel=new DrawPanel();  
  24.         add(panel);  
  25.     }  
  26.       
  27. }  
  28. //定义画板  
  29. class DrawPanel extends JPanel{  
  30.       
  31.     /**  
  32.      *   
  33.      */  
  34.     private static final long serialVersionUID = 2L;  
  35.     public void paintComponent(Graphics g){  
  36.         super.paintComponent(g);  
  37.         for(int i=0;i<20;i++)  
  38.         {  
  39.             g.fillOval(fibo(i),fibo(i), fibo(i), fibo(i));  
  40.         }  
  41.           
  42.           
  43.     }  
  44.     //递归调用实现裴波那契数列,并将其值作为圆的的半径  
  45.     public static int fibo(int x){  
  46.         if(x<=2){  
  47.             if(x<=0)return 0;  
  48.             else  
  49.                 return 1;  
  50.         }  
  51.         else{  
  52.             return fibo(x-1)+fibo(x-2);  
  53.         }  
  54.     }