孤独的猫

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

圆为构成元素的递归图形

/*圆为构成元素的递归图形*/
#include "glib.h"
int n_rot=5;            /*旋转对称次数*/
int N=6;               /*递归次数*/
double ang,scale=0.38;    /*scale缩小率*/
double r1=64.0;       /*中心到下个分枝点的长度*/

void recurs(double r,int n)
{
  int i,j,k;
  if (n<=N)
  {
  setcolor(n);
  circle(LPX,LPY,r);
  setfillstyle(1,n);
  floodfill(LPX,LPY,n);
  if (1==n)
  {
    j=n_rot;
    k=0;
  }
  else
  {
    j=3;
    k=1;
  }
  for (i=0;i<j;i++)
  {
    turn((i-k)*ang);
    warp(r*(1+scale));
    recurs(r*scale,n+1);
    turn(180.0);
    warp(r*(1+scale));
    turn(180-(i-k)*ang);
  }
  setcolor(n-1);
  }
}

void main
{
  ginit();
  setbkcolor(15);
  ang=360.0/n_rot;
  setlp(320.0,200.0);
  setangle(90.0);
  recurs(r1,1);
  gend();
}

posted on 2011-03-04 21:41  孤独的猫  阅读(216)  评论(0)    收藏  举报