作者在 2009-02-22 13:11:55 发布以下内容
C语言的魅力,就是这么的无尽。一个程序编出的tc图形竟如此的美丽:
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
float asp_ratio;
void Set_color(int colornum,int red0,int green0,int blue0);
void InitScr2()
{
union REGS In;
In.x.ax=0x13;
int86(0x10,&In,&In);
}
void InitScr()
{
int i,color1,color2,color3;
union REGS In;
In.x.ax=0x13;
int86(0x10,&In,&In);
void Set_color(int colornum,int red0,int green0,int blue0);
void InitScr2()
{
union REGS In;
In.x.ax=0x13;
int86(0x10,&In,&In);
}
void InitScr()
{
int i,color1,color2,color3;
union REGS In;
In.x.ax=0x13;
int86(0x10,&In,&In);
for(i=0;i<256;i++)
{if(i<64)
{color1=i;color2=0;color3=0;}
else if(i>=64&&i<128)
{color2=i;color1=0;color3=0;}
else if(i>=128&&i<192)
{color3=i;color2=0;color1=0;}
else if(i>=192&&i<256)
{color1=i;color2=i;color3=i;}
Set_color(i,color1,color2,color3);
}
{if(i<64)
{color1=i;color2=0;color3=0;}
else if(i>=64&&i<128)
{color2=i;color1=0;color3=0;}
else if(i>=128&&i<192)
{color3=i;color2=0;color1=0;}
else if(i>=192&&i<256)
{color1=i;color2=i;color3=i;}
Set_color(i,color1,color2,color3);
}
}
void RstScr()
{
union REGS In;
In.x.ax=0x03;
int86(0x10,&In,&In);
}
void PutPoint(int x,int y,char color)
{
char far *video_buffer;
video_buffer=(char far *)0xA0000000L;
*(x+y*320+video_buffer)=color;
}
void Rectangle(int x1,int y1,int x2,int y2,char color)
{
int i;
for(i=x1;i<=x2;i++){
PutPoint(i,y1,color);
PutPoint(i,y2,color);}
for(i=y1;i<=y2;i++){
PutPoint(x1,i,color);
PutPoint(x2,i,color);}
}
void Set_color(int colornum,int red0,int green0,int blue0)
{
outportb(0x3c8,colornum);
outportb(0x3c9,red0);
outportb(0x3c9,green0);
outportb(0x3c9,blue0);
}
void PreLine(int x1,int y1,int x2,int y2,char color)
{
int dx,dy,x_inc,y_inc,index,error=0;
unsigned char far *vb_start=0xA0000000L;
vb_start=vb_start+(x1+y1*320);
dx=x2-x1;
dy=y2-y1;
if(dx>=0)
{x_inc=1;}
else
{x_inc=-1;
dx=-dx;}
if(dy>=0)
{y_inc=320;}
else
{y_inc=-320;
dy=-dy;}
if(dx>dy){
for(index=0;index<=dx;index++){
*vb_start=color;
error+=dy;
if(error>dx){
error-=dx;
vb_start+=y_inc;
}
vb_start+=x_inc;
}
}
else{
for(index=0;index<=dy;index++){
*vb_start=color;
error+=dx;
if(error>dy){
error-=dy;
vb_start+=x_inc;
}
vb_start+=y_inc;
}
}
}
void RstScr()
{
union REGS In;
In.x.ax=0x03;
int86(0x10,&In,&In);
}
void PutPoint(int x,int y,char color)
{
char far *video_buffer;
video_buffer=(char far *)0xA0000000L;
*(x+y*320+video_buffer)=color;
}
void Rectangle(int x1,int y1,int x2,int y2,char color)
{
int i;
for(i=x1;i<=x2;i++){
PutPoint(i,y1,color);
PutPoint(i,y2,color);}
for(i=y1;i<=y2;i++){
PutPoint(x1,i,color);
PutPoint(x2,i,color);}
}
void Set_color(int colornum,int red0,int green0,int blue0)
{
outportb(0x3c8,colornum);
outportb(0x3c9,red0);
outportb(0x3c9,green0);
outportb(0x3c9,blue0);
}
void PreLine(int x1,int y1,int x2,int y2,char color)
{
int dx,dy,x_inc,y_inc,index,error=0;
unsigned char far *vb_start=0xA0000000L;
vb_start=vb_start+(x1+y1*320);
dx=x2-x1;
dy=y2-y1;
if(dx>=0)
{x_inc=1;}
else
{x_inc=-1;
dx=-dx;}
if(dy>=0)
{y_inc=320;}
else
{y_inc=-320;
dy=-dy;}
if(dx>dy){
for(index=0;index<=dx;index++){
*vb_start=color;
error+=dy;
if(error>dx){
error-=dx;
vb_start+=y_inc;
}
vb_start+=x_inc;
}
}
else{
for(index=0;index<=dy;index++){
*vb_start=color;
error+=dx;
if(error>dy){
error-=dy;
vb_start+=x_inc;
}
vb_start+=y_inc;
}
}
}
void Circle(int x,int y,int r,int color)
{
int x0,y0,x1,y1,index;
float cos_look[361];
float sin_look[361];
x0=y0=r/sqrt(2);
{
int x0,y0,x1,y1,index;
float cos_look[361];
float sin_look[361];
x0=y0=r/sqrt(2);
for(index=0;index<=360;index++)
{cos_look[index]=(float)cos((double)(index*3.14159/180));
sin_look[index]=(float)sin((double)(index*3.14159/180));
x1=x0*cos_look[index]-y0*sin_look[index];
y1=x0*sin_look[index]+y0*cos_look[index];
PutPoint(x+x1,y+y1,color);}
}
void BCircle(int x,int y,int r,int color)
{
int x0,y0,x1,y1,index;
float cos_look[361];
float sin_look[361];
x0=y0=r/sqrt(2);
{cos_look[index]=(float)cos((double)(index*3.14159/180));
sin_look[index]=(float)sin((double)(index*3.14159/180));
x1=x0*cos_look[index]-y0*sin_look[index];
y1=x0*sin_look[index]+y0*cos_look[index];
PutPoint(x+x1,y+y1,color);}
}
void BCircle(int x,int y,int r,int color)
{
int x0,y0,x1,y1,index;
float cos_look[361];
float sin_look[361];
x0=y0=r/sqrt(2);
for(index=0;index<=360;index++)
{cos_look[index]=(float)cos((double)(index*3.14159/180));
sin_look[index]=(float)sin((double)(index*3.14159/180));
x1=x0*cos_look[index]-y0*sin_look[index];
y1=x0*sin_look[index]+y0*cos_look[index];
PutPoint(x+x1,y+y1,color);
PutPoint(x+x1-1,y+y1+1,color);
PutPoint(x+x1,y+y1-1,color);
PutPoint(x+x1+1,y+y1,color);
PutPoint(x+x1,y+y1+1,color);
PutPoint(x+x1-1,y+y1-1,color);
PutPoint(x+x1+1,y+y1-1,color);
PutPoint(x+x1-1,y+y1+1,color);
PutPoint(x+x1-1,y+y1+1,color);}
}
void Plot_Circle(int x,int y,int x_center,int y_center,int color){
double startx,endx,x1,starty,endy,y1;
starty=y*asp_ratio;
endy=(y+1)*asp_ratio;
startx=x*asp_ratio;
endx=(x+1)*asp_ratio;
for(x1=startx;x1<endx;++x1){
PutPoint(x1+x_center,y+y_center,color);
PutPoint(x1+x_center,-y+y_center,color);
PutPoint(-x1+x_center,-y+y_center,color);
PutPoint(-x1+x_center,y+y_center,color);
PutPoint(x1+x_center,y+y_center-1,color);
PutPoint(x1+x_center,-y+y_center+1,color);
PutPoint(-x1+x_center,-y+y_center+1,color);
PutPoint(-x1+x_center,y+y_center-1,color);}
for(y1=starty;y1<endy;++y1){
PutPoint(y1+x_center,x+y_center,color);
PutPoint(y1+x_center,-x+y_center,color);
PutPoint(-y1+x_center,-x+y_center,color);
PutPoint(-y1+x_center,x+y_center,color);
PutPoint(y1+x_center,x+y_center+1,color);
PutPoint(y1+x_center,-x+y_center-1,color);
PutPoint(-y1+x_center,-x+y_center-1,color);
PutPoint(-y1+x_center,x+y_center+1,color);}
}
void Ellipse(int x_center,int y_center,int x_radius,int y_radius,int color){
register int x,y,delta;
asp_ratio=y_radius;
asp_ratio/=x_radius;
y=x_radius;
delta=3-(x_radius<<1);
for(x=0;x<=y;){
Plot_Circle(x,y,x_center,y_center,color);
if(delta<0) delta+=(x<<2)+6;
else{ delta+=((x-y)<<2)+10;y--;}
x++;}
}
{cos_look[index]=(float)cos((double)(index*3.14159/180));
sin_look[index]=(float)sin((double)(index*3.14159/180));
x1=x0*cos_look[index]-y0*sin_look[index];
y1=x0*sin_look[index]+y0*cos_look[index];
PutPoint(x+x1,y+y1,color);
PutPoint(x+x1-1,y+y1+1,color);
PutPoint(x+x1,y+y1-1,color);
PutPoint(x+x1+1,y+y1,color);
PutPoint(x+x1,y+y1+1,color);
PutPoint(x+x1-1,y+y1-1,color);
PutPoint(x+x1+1,y+y1-1,color);
PutPoint(x+x1-1,y+y1+1,color);
PutPoint(x+x1-1,y+y1+1,color);}
}
void Plot_Circle(int x,int y,int x_center,int y_center,int color){
double startx,endx,x1,starty,endy,y1;
starty=y*asp_ratio;
endy=(y+1)*asp_ratio;
startx=x*asp_ratio;
endx=(x+1)*asp_ratio;
for(x1=startx;x1<endx;++x1){
PutPoint(x1+x_center,y+y_center,color);
PutPoint(x1+x_center,-y+y_center,color);
PutPoint(-x1+x_center,-y+y_center,color);
PutPoint(-x1+x_center,y+y_center,color);
PutPoint(x1+x_center,y+y_center-1,color);
PutPoint(x1+x_center,-y+y_center+1,color);
PutPoint(-x1+x_center,-y+y_center+1,color);
PutPoint(-x1+x_center,y+y_center-1,color);}
for(y1=starty;y1<endy;++y1){
PutPoint(y1+x_center,x+y_center,color);
PutPoint(y1+x_center,-x+y_center,color);
PutPoint(-y1+x_center,-x+y_center,color);
PutPoint(-y1+x_center,x+y_center,color);
PutPoint(y1+x_center,x+y_center+1,color);
PutPoint(y1+x_center,-x+y_center-1,color);
PutPoint(-y1+x_center,-x+y_center-1,color);
PutPoint(-y1+x_center,x+y_center+1,color);}
}
void Ellipse(int x_center,int y_center,int x_radius,int y_radius,int color){
register int x,y,delta;
asp_ratio=y_radius;
asp_ratio/=x_radius;
y=x_radius;
delta=3-(x_radius<<1);
for(x=0;x<=y;){
Plot_Circle(x,y,x_center,y_center,color);
if(delta<0) delta+=(x<<2)+6;
else{ delta+=((x-y)<<2)+10;y--;}
x++;}
}
void main()
{
int i,j,k,x,y,num,num1=0;
int x1,y1,x2,y2,color1=0,goout_color=0;
x=50;
y=145;
randomize();
InitScr();
for(i=0;i<=255;i++)
PutPoint(random(320),random(200),i);
getch();
RstScr();
InitScr();
for(j=0;j<=199;j++)
for(i=0;i<=256;i++)
PutPoint(i,j,i);
getch();
RstScr();
InitScr();
PutPoint(random(320),random(200),i);
getch();
RstScr();
InitScr();
for(j=0;j<=199;j++)
for(i=0;i<=256;i++)
PutPoint(i,j,i);
getch();
RstScr();
InitScr();
for(i=1;i<=4;i++){
k=0;
y+=10;
for(num=45;num>=0;num--){
for(j=0;j<=k;j++)
PutPoint(x+j,y,num+num1);
x=x+k;
//k++;
for(j=0;j<=k;j++)
PutPoint(x,y+j,num+num1);
y=y+k;
k++;
for(j=0;j<=k;j++)
PutPoint(x-j,y,num+num1);
x=x-k;
//k++;
for(j=0;j<=k;j++)
PutPoint(x,y-j,num+num1);
y=y-k;
k++;
}
k=0;
y+=10;
for(num=45;num>=0;num--){
for(j=0;j<=k;j++)
PutPoint(x+j,y,num+num1);
x=x+k;
//k++;
for(j=0;j<=k;j++)
PutPoint(x,y+j,num+num1);
y=y+k;
k++;
for(j=0;j<=k;j++)
PutPoint(x-j,y,num+num1);
x=x-k;
//k++;
for(j=0;j<=k;j++)
PutPoint(x,y-j,num+num1);
y=y-k;
k++;
}
x+=115;
num1+=64;
num1+=64;
}
getch();
RstScr();
InitScr();
for(j=50;j<=114;j++)
for(i=64;i<128;i++)
if(i<=96)
PutPoint(i,j,160-i);
for(j=0;j<=8;j++)
{PreLine(55+j,42+j,55+j,106+j,70+j);
PreLine(55+j,42+j,87+j,42+j,66+j);}
getch();
RstScr();
InitScr();
Circle(60,100,30,1);
for(i=0;i<=29;i++)
BCircle(60,100,i,158-i);
Circle(150,100,64,1);
for(i=0;i<=64;i++)
BCircle(150,100,i,64-i);
getch();
RstScr();
InitScr();
for(i=35;i<=50;i++)
{Ellipse(150,100,i+50,i+50,192-i);
Ellipse(150,100,51-i,51-i,105+i);}
for(i=20;i<=35;i++)
Ellipse(150,100,i+50,i+50,120+i);
getch();
RstScr();
InitScr();
for(j=50;j<=114;j++)
for(i=64;i<128;i++)
if(i<=96)
PutPoint(i,j,160-i);
for(j=0;j<=8;j++)
{PreLine(55+j,42+j,55+j,106+j,70+j);
PreLine(55+j,42+j,87+j,42+j,66+j);}
getch();
RstScr();
InitScr();
Circle(60,100,30,1);
for(i=0;i<=29;i++)
BCircle(60,100,i,158-i);
Circle(150,100,64,1);
for(i=0;i<=64;i++)
BCircle(150,100,i,64-i);
getch();
RstScr();
InitScr();
for(i=35;i<=50;i++)
{Ellipse(150,100,i+50,i+50,192-i);
Ellipse(150,100,51-i,51-i,105+i);}
for(i=20;i<=35;i++)
Ellipse(150,100,i+50,i+50,120+i);
getch();
RstScr();
InitScr2();
x1=y1=0;
x2=319;
y2=199;
while(!kbhit()){
color1++;
x2=319;
y2=199;
x1=y1=0;
if(color1>=256) color1=0;
delay(30);
for(i=100;i>=0;i--)
Rectangle(x1++,y1++,x2--,y2--,i+color1);
}
getch();
RstScr();
InitScr();
x1=y1=0;
x2=319;
y2=199;
while(!kbhit()){
color1++;
goout_color++;
RstScr();
InitScr2();
x1=y1=0;
x2=319;
y2=199;
while(!kbhit()){
color1++;
x2=319;
y2=199;
x1=y1=0;
if(color1>=256) color1=0;
delay(30);
for(i=100;i>=0;i--)
Rectangle(x1++,y1++,x2--,y2--,i+color1);
}
getch();
RstScr();
InitScr();
x1=y1=0;
x2=319;
y2=199;
while(!kbhit()){
color1++;
goout_color++;
x2=319;
y2=199;
x1=y1=0;
if(color1>=256) color1=0;
delay(30);
if(goout_color<500)
for(i=100;i>=0;i--)
Rectangle(x1++,y1++,x2--,y2--,i+color1);
Rectangle(x1++,y1++,x2--,y2--,i+color1);
else if(goout_color>=500&&goout_color<1000)
for(i=100;i>=0;i--)
Rectangle(x1++,y1++,x2--,y2--,i+color1);
if(goout_color==1000) goout_color=0;
for(i=100;i>=0;i--)
Rectangle(x1++,y1++,x2--,y2--,i+color1);
if(goout_color==1000) goout_color=0;
}
for(i=18;i<50;i++)
Rectangle(x1--,y1--,x2++,y2++,i);
getch();
RstScr();
}
Rectangle(x1--,y1--,x2++,y2++,i);
getch();
RstScr();
}