首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

请教怎么在vc中使用tc的graphics函数库

2012-03-22 
【求助】请问如何在vc中使用tc的graphics函数库最近找到一些在tc下实现得有趣程序,因为我习惯用vc,所以想向

【求助】请问如何在vc中使用tc的graphics函数库
最近找到一些在tc下实现得有趣程序,因为我习惯用vc,所以想向前辈们请教一下如何在vc中使用tc的graphics函数库,或者如何将tc下的程序改为vc下可执行的程序,附其中一个源代码如下:
#include<graphics.h>
#include<math.h>
#include<malloc.h>
#define PI 3.1415926
main()
{
  int gdrive,gmode;
  int flowers[10][7]={{50,50,25,15,RED,YELLOW,5},
{120,50,23,70,CYAN,YELLOW,3},
{200,50,20,41,BLUE,MAGENTA,4},
{270,50,15,15,BROWN,RED,9},
{350,50,27,120,LIGHTRED,YELLOW,7},
{50,150,23,150,LIGHTBLUE,GREEN,6},
{120,150,14,40,MAGENTA,YELLOW,5},
{200,150,22,130,RED,CYAN,10},
{270,150,19,10,BROWN,YELLOW,8},
{350,150,22,30,RED,LIGHTBLUE,11}};
  int i;


  gdrive=DETECT;
  initgraph(&gdrive,&gmode,"D:\\tc20\\BGI");

  setbkcolor(15);/*Set white backgroud color.*/

  /* Draw ten flowers.*/
  for(i=0;i<10;i++)
  {
  petal(flowers[i]);
  }
  getch();
  closegraph();
}

int petal(int *flowers)
{
  double x,y;
  double r,cosn,sinn,theta,alpha;
  int i,j,x0,y0;
  int *x1,*x2,*y1,*y2;
  int xyc[2],clrs[2],rad,ang,pt;

  xyc[0]=flowers[0]; /* x coordinate of this flower.*/
  xyc[1]=flowers[1]; /* y coordinate of this flower.*/
  rad=flowers[2]; /* size */
  ang=flowers[3]; /* angle */
  clrs[0]=flowers[4]; /* petal color.*/
  clrs[1]=flowers[5]; /* pistil color.*/
  pt=flowers[6]; /* petal number.*/

  x1=malloc(pt+pt);
  y1=malloc(pt+pt);
  x2=malloc(pt+pt);
  y2=malloc(pt+pt);

  alpha=360.0/pt;
  r=rad*sin(1.0/pt*PI);
  r=r;
  y0=rad*cos(1.0/pt*PI);
  x0=0;

  setcolor(clrs[0]);
  for(i=0;i<pt;i++)
  {
  x1[i]=-1;
  y1[i]=-1;
  }

  for(i=0;i<=180;i++)
  {
  theta=PI/180.0*i;
  cosn=cos(theta);
  sinn=sin(theta);
  x=r*cosn;
  y=r*sinn;

  y=y+y0;

  /*Rotate ang clockwise.*/
  theta=ang*PI/180.0;
  for(j=0;j<pt;j++)
  {
  cosn=cos(theta);
  sinn=sin(theta);
  theta=theta+PI*alpha/180.0;
  x2[j]=x*cosn-y*sinn;
  y2[j]=x*sinn+y*cosn;

  x2[j]=xyc[0]+x2[j];
  y2[j]=xyc[1]-y2[j];

  /* It is not the first point.*/
  if(x1[j]>-1)
  {
line(x1[j],y1[j],x2[j],y2[j]);
  }
  x1[j]=x2[j];
  y1[j]=y2[j];
  }

  }

  setfillstyle(1,clrs[0]);
  floodfill(xyc[0],xyc[1],clrs[0]);


  setcolor(clrs[1]);
  setlinestyle(0,0,1);
  circle(xyc[0],xyc[1],rad);
  setfillstyle(9,clrs[1]);
  floodfill(xyc[0],xyc[1],clrs[1]);

  free(x1);
  free(x2);
  free(y1);
  free(y2);
}


[解决办法]
微软只允许兼容自己的东西,所以在vc下使用tc的东西显然要出问题。
[解决办法]
看懂 tc 的代码,然后自己写一个。
不可能存在自动的转换。
就算你是 VS 也不行。
[解决办法]
tc用的是16位时代的 图形函数。还是继续用tc跑这些程序吧。

vc应该用gdi dx opengl之类的 函数来绘制图形。
[解决办法]
把需要的图形函数都放到tc的工作目录,试试


[解决办法]
http://www.easyx.cn/

热点排行