/*用 画点函数实现小图形 T2 T3 编译*/
#include<graphics.h>#include<math.h>
#include<stdlib.h>
float cos_lk[361],sin_lk[361];
void Create_Tables(void)
{
int index;
for(index=0;index<=360;index++)
{
cos_lk[index]=(float)cos((float)(index*3.14159/180));
sin_lk[index]=(float)sin((float)(index*3.14159/180));
}
}
/*用点画圆函数*/
void Circle(int x,int y,int r,int color)
{
int x0,y0,x1,y1,index;
x0=y0=r/sqrt(2);
for(index=0;index<=360;index++)
{
x1=x0*cos_lk[index]-y0*sin_lk[index];
y1=y0*sin_lk[index]+y0*cos_lk[index]; /*[local]1[/local][local]1[/local] 论坛的小bug *//*把这几个 local 注释掉*/
putpixel(x+x1,y+y1,color);
}
}
/*点画线函数*/
void linee(int x1,int y1,int x2,int y2)
{
int addx,addy,x_in,y_in,comp=0,index,color=0;
addx=x2-x1;
addy=y2-y1;
if(addx>=0)
x_in=1;
else
{
x_in=-1;
addx=-addx;
}
if(addy>=0)
y_in=1;
else
{
y_in=-1;
addy=-addy;
}
if(addx>addy)
{
for(index=0;index<=addx;index++)
{
putpixel(x1,y1,color);
color++;
if(color>15) color=1;
comp+=addy;
if(comp>=addx)
{
comp-=addx;
y1+=y_in;
}
x1+=x_in;
}
}
else
{
for(index=0;index<=addy;index++)
{
putpixel(x1,y1,color);
color++;
if(color>15) color=1;
comp+=addx;
if(comp>=addy)
{
comp-=addy;
x1+=x_in;
}
y1+=y_in;
}
}
}
int main(void)
{
int driver,mode,i;
driver=DETECT;
mode=0;
/*registerbgidriver(EGAVGA_driver);*/
initgraph(&driver,&mode,"d:\\tc\\bgi");
Create_Tables();
randomize();
/*画框*/
for(i=0;i<=50;i+=2)
{
linee(1*i,1*i,5*i,1*i);
linee(1*i,1*i,1*i,5*i);
linee(5*i,1*i,5*i,5*i);
linee(1*i,5*i,5*i,5*i);
}
getch();
cleardevice();
/*画饼*/
for(i=1;i<=80;i++)
Circle(320,240,2*i,random(16)+1);
getch();
cleardevice();
/*画任意直线*/
for(i=1;i<=500;i++)
linee(random(640),random(480),random(640),random(480));
getch();
cleardevice();
/*动态圆环*/
while(!kbhit())
for(i=0;i<=60;i++)
{
Circle(100+i,100+i,2*i,random(16)+1);
delay(5);
/*Circle(100+i,100+i,2*i,0);*/
}
getch();
closegraph();
return 0;
}/*
NONAME00.rar
(35.57 KB)
可执行独立图形文件*/[[it] 本帖最后由 xianshizhe111 于 2008-3-5 19:13 编辑 [/it]]