|
|
发表于 2011-5-29 23:57:03
|
显示全部楼层
- #include <graphics.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include <conio.h>
- #define PI 3.14159265
- int X_maxd,Y_maxd,foregrcolor,backgrcolor,colorsum;
- float x_maxs=10.0,y_maxs=7.0,horfact,vertfact;
- float fx,fy,f,xc,yc,xmin0=100,xmax0=-100,ymin0=100,ymax0=-100,xc0,yc0,a,b,c,d,x0,x,y;
- int count=0,recdepth,level_5;
- void initgr()
- {
- int gdriver=DETECT,gmode;
- initgraph(&gdriver,&gmode,"d:\\turboc2");
- foregrcolor=getcolor();
- backgrcolor=getbkcolor();
- colorsum=foregrcolor+(backgrcolor<<4);
- X_maxd=getmaxx();
- Y_maxd=getmaxy();
- horfact=X_maxd/x_maxs;
- vertfact=Y_maxd/y_maxs;
- }
- int lx(float x)
- {
- return ((int)(x*horfact+0.5));
- }
- int ly(float y)
- {
- return ((int)(Y_maxd)-(int)(y*vertfact+0.5));
- }
- float xreal(float x)
- {
- return (xc+f*(x-xc0));
- }
- float yreal(float y)
- {
- return (yc+f*(y-yc0));
- }
- void transf(float x,float y,int n,int prescan)
- {
- float x1,y1;
- if(n>0)
- {
- if(prescan)
- {
- if(x<xmin0)
- xmin0=x;
- if(x>xmax0)
- xmax0=x;
- if(y<ymin0)
- ymin0=y;
- if(y>ymax0)
- ymax0=y;
- }
- else
- {
- if(n==level_5)
- putpixel(count+=8,0,foregrcolor);
- putpixel(lx(xreal(x)),ly(yreal(y)),foregrcolor);
- }
- x1=a*x+b*y;
- y1=b*x-a*y;
- transf(x1,y1,n-1,prescan);
- x1=c*(x-x0)-d*y+x0;
- y1=d*(x-x0)+c*y;
- transf(x1,y1,n-1,prescan);
- }
- }
- main()
- {
- int i;
- recdepth=14;
- level_5=recdepth-5;
- a=0.7;
- b=0.3;
- c=0.5;
- d=0.2;
- x0=2;
- transf(1.0,0.0,recdepth,1);
- initgr();
- setviewport(15,15,625,465,1);
- foregrcolor=2;
- setfillstyle(SOLID_FILL,DARKGRAY);
- floodfill(16,16,DARKGRAY);
- fx=x_maxs/(xmax0-xmin0);
- fy=y_maxs/(ymax0-ymin0);
- f=(fx<fy?fx:fy)*0.8;
- xc0=(xmin0+xmax0)/2;
- yc0=(ymin0+ymax0)/2;
- xc=x_maxs/2;
- yc=y_maxs/2;
- count=0;
- transf(1.0,0.0,recdepth,0);
- for(i=1;i<32;i++)
- putpixel(8*i,0,backgrcolor);
- getch();
- closegraph();
- }
复制代码 |
|