📄 graphic.h
字号:
int Get_Pixel(int x,int y)
{
int color;
color=video_buffer[((y<<8)+(y<<6))+x];
return (color);
}
void Plot_Pixel_Fast(int x,int y,char color)
{
video_buffer[((y<<8)+(y<<6))+x]=color;
}
void H_Line(int x1,int x2,int y,unsigned int color)
{
memset( (char far *) (video_buffer + ( (y<<8) + (y<<6) ) + x1) , color , x2-x1+1 );
}
void V_Line(int y1,int y2,int x,unsigned int color)
{
int i;
for(i=y1;i<y2;i++)
video_buffer[ (i<<8) + (i<<6) + x]=color;
}
void BPlot_Pixel_Fast(int x,int y,char color)
{
video_buffer[((y<<8)+(y<<6))+x]=color;
video_buffer[((y<<8)+(y<<6))+x-1]=color;
video_buffer[((y<<8)+(y<<6))+x-320]=color;
video_buffer[((y<<8)+(y<<6))+x-321]=color;
}
void Bline(int x0,int y0,int x1,int y1,unsigned char color)
{
int dx,dy,x_inc,y_inc,error=0,index;
unsigned char far *vb_start=video_buffer;
vb_start=vb_start+((unsigned int )y0<<6)+((unsigned int)y0<<8)+(unsigned int)x0;
dx=x1-x0;
dy=y1-y0;
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>0)
{
error-=dy;
vb_start+=x_inc;
}
vb_start+=y_inc;
}
}
}
void Square(int x,int y,int side,int color)
{
H_Line(x,x+side,y,color);
H_Line(x,x+side,y+side,color);
V_Line(y,y+side,x,color);
V_Line(y,y+side,x+side,color);
}
void Fill_Square(int x,int y,int side,int color)
{
int i;
for(i=y;i<=y+side;i++)
{
H_Line(x,x+side,i,color);
}
}
void Rectangle(int x1,int y1,int x2,int y2,int color)
{
H_Line(x1,x2,y1,color);
H_Line(x1,x2,y2,color);
V_Line(y1,y2,x1,color);
V_Line(y1,y2,x2,color);
}
void Fill_Rectangle(int x1,int y1,int x2,int y2,int color)
{
int i;
for(i=y1;i<=y2;i++)
{
H_Line(x1,x2,i,color);
}
}
float sin_look[361];
float cos_look[361];
void Create_Tables(void)
{
int index;
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));
}
}
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_look[index]-y0*sin_look[index];
y1=x0*sin_look[index]+y0*cos_look[index];
Plot_Pixel_Fast(x+x1,y+y1,color);
}
}
void BCircle(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_look[index]-y0*sin_look[index];
y1=x0*sin_look[index]+y0*cos_look[index];
Plot_Pixel_Fast(x+x1,y+y1,color);
Plot_Pixel_Fast(x+x1-1,y+y1,color);
Plot_Pixel_Fast(x+x1,y+y1-1,color);
Plot_Pixel_Fast(x+x1+1,y+y1,color);
Plot_Pixel_Fast(x+x1,y+y1+1,color);
Plot_Pixel_Fast(x+x1-1,y+y1-1,color);
Plot_Pixel_Fast(x+x1+1,y+y1-1,color);
Plot_Pixel_Fast(x+x1+1,y+y1+1,color);
Plot_Pixel_Fast(x+x1-1,y+y1+1,color);
}
}
void Fill_Circle(int x,int y,int r,int color)
{
int index;
for(index=r;index>0;index--)
{
BCircle(x,y,index,color);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -