www.pudn.com > TreeFlower.rar > TREE3.C
#include"glib.h"
#include"stdlib.h"
int N=8;
void tree(double leng,int n,int branchcolor,int leafcolor,double branch[][2])
{
int i=0;
if(n<=N)
{setcolor(branchcolor);
if(1==n)
{move(leng);
tree(leng,n+1,branchcolor,leafcolor,branch);
}
else
while(END!=branch[i][0])
{
turn(branch[i][0]);
move(branch[i][1]*leng);
tree(branch[i][1]*leng,n+1,branchcolor,leafcolor,branch);
turn(180.0);
warp(branch[i][1]*leng);
turn(180-branch[i][0]);
i++;
}
}
else
{
setcolor(leafcolor);
warp(leng*0.3);
circle(LPX,LPY,leng*0.3);
setfillstyle(1,15);
turn(180.0);
warp(leng*0.3);
turn(180.0);
}
setcolor(branchcolor/*n-1*/);
}
drawtree(double sx,double sy,double leng1)
{
double branch[][2]={{0.0,0.8},{30.0,0.5},{-30.0,0.5},END};
setlp(sx,sy);
setangle(90.0);
tree(leng1,3,DARKGRAY,GREEN,branch);
}
drawflower(double sx,double sy,double leng1)
{
double branch[][2]={{30.0,0.7},{-30.0,0.7},END};
setlp(sx,sy);
setangle(90.0);
tree(leng1,4,GREEN,RED,branch);
}
void fillcolor(x,y,fill_color,boundary_color)
int x,y,fill_color,boundary_color;
{
int c;
c=getpixel(x,y); /*的颜色*/
if((c!=boundary_color)&&(c!=fill_color)) /*如果颜色为边界色则不填充*/
{
putpixel(x, y, fill_color); /*画点*/
/*getch(); 加上这条语句可以显示填充状态 */
fillcolor(x+1,y, fill_color, boundary_color);
fillcolor(x-1,y, fill_color, boundary_color);
fillcolor(x, y+1, fill_color, boundary_color);
fillcolor(x, y-1, fill_color, boundary_color);
}
}
void fill(/*int point[4][2]int x1,int,y1,int x2,int y2,int x3,int y3,int x4,int y4*/)
{ int i,j;
for(i=160;i<=479;i++)
for(j=-i*177/319+300;j<=-i*160/319+214;j++)
putpixel(j,i,DARKGRAY);
}
main()
{
double *poly[10];
int i,j=-2,l1,l2;
ginit();
/*for(i=10;i<600;i++)
for(j=10;j<350;j++)
{if(random(2)==1)
putpixel(i,j,WHITE);
else putpixel(i,j,LIGHTBLUE);
} */
setbkcolor(15);/*
for(i=140;i<=479;i++)
for(j=-(double)i*215/319+260;j<=(double)i*160/319+420;j++)
putpixel(j,i,YELLOW); */
N=6;
setcolor(GREEN);
for(i=0;i<600;i++)
{ l1=150-i/6+random(i/2+288);l2=138+i/2+random(50);
line(l1,l2,l1-i/120+random(3),l2+i/60+random(4));
line(l1+random(5),l2+random(5),l1-i/120+random(5)+2,l2+i/60+random(5)+2);
}
for(i=0;i<150;i++)
drawflower(150-i*2/3+random(2*i+288),150+2*i+random(20),i/20+random(4));
/*poly[0]=48;
poly[1]=getmaxy();
poly[2]=142;
poly[3]=getmaxy();
poly[4]=222;
poly[5]=160;
poly[6]=218;
poly[7]=160;
poly[8]=poly[0];
poly[9]=poly[1];
setcolor(BLUE);
drawpoly(5,poly);*/
for(i=160;i<=479;i++)
for(j=-(double)i*170/319+303;j<=-(double)i*80/319+262;j++)
if(random(3)==2) putpixel(j,i,15);
else putpixel(j,i,LIGHTGRAY);
N=8;
for(i=0,j=-2;i<10;i++)
{/*drawtree(random(700),random(400),40); */
j++;
drawtree(30+20*i,500-55*i+20*j,40-4*i);
drawtree(160+8*i,500-55*i+20*j,40-4*i);
}
N=7;
for(j=0;j<12;j++)
{drawtree(250+20*j,200,8);
/* drawtree(220+20*j,200,8); */
}
gend();
}