C Programming the drawing program package source code

Source: Internet
Author: User

#include <dos.h>
#define MAXX 640
#define MAXY 480

static float asp_ratio=1;

static void Selectpage (int page)//page-shift function * *
{
Union regs R;
r.x.ax=0x4f05;
r.x.bx=0;
R.x.dx=page;
Int86 (0X10,&R,&R);
}

void init256 (void)
{
Union regs R;
R.X.AX=0X4F02;
r.x.bx=0x101;
Int86 (0X10,&R,&R);
}

void exit256 (void)
{
Union regs R;
r.h.ah=0;
r.h.al=3;
Int86 (0X10,&R,&R);
}

void Putpixel (int x,int y,int color)
{Long I;
static int t=0;
int tt=0;
char far *p=0xa0000000;
I=y;
I*=maxx;
I+=x;
tt=i>>16;
i&=0xffff;
if (T!=TT) selectpage (TT);
* (p+i) = (char) color;
T=tt;
}

int getpixel (int x,int y)
{
Long I;
static int t=0;
int tt=0;
char far *p=0xa0000000;
I=y;
I*=maxx;
I+=x;
tt=i<<16;
i&=0xffff;
if (T!=TT) selectpage (TT);
T=tt;
return ((int) * (p+i));
}


void line (int startx,int starty,int endx,int endy,int color)
{
register int t,distance;
int x=0,y=0,delta_x,delta_y;
int incx,incy;

Delta_x=endx-startx;
Delta_y=endy-starty;

if (delta_x>0) incx=1;
else if (delta_x==0) incx=0;
else Incx=-1;
if (delta_y>0) Incy=1;
else if (delta_y==0) incy=0;
else Incy=-1;

if (delta_x<0) delta_x=-delta_x;
if (delta_y<0) delta_y=-delta_y;

if (delta_x>delta_y) distance=delta_x;
else distance=delta_y;

for (t=0;t<=distance+1;t++) {
Putpixel (Startx,starty,color);
x+=delta_x;
y+=delta_y;
if (x>distance) {
X-=distance;
Startx+=incx;
}
if (y>distance) {
Y-=distance;
starty+=incy;
}
}
}

void box (int startx,int starty,int endx,int endy,int color)
{
int i;
for (i=startx+1;i<endx;i++) {
Putpixel (I,starty,color);
Putpixel (I,endy,color);
}
for (i=starty;i<=endy;i++) {
Putpixel (Startx,i,color);
Putpixel (Endx,i,color);
}
}

void Fillbox (int startx,int starty,int endx,int endy,int color)
{
int i,j;
for (j=starty;j<=endy;j++)
for (i=startx;i<=endx;i++)
Putpixel (I,j,color);
}

static void plot_circle (int x,int y,int x_center,int y_center,int color)
{
int 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) {
Putpixel (X1+x_center,y+y_center,color);
Putpixel (X1+x_center,y_center-y,color);
Putpixel (X_center-x1,y_center-y,color);
Putpixel (X_center-x1,y+y_center,color);
}
for (y1=starty;y1<endy;++y1) {
Putpixel (Y1+x_center,x+y_center,color);
Putpixel (Y1+x_center,y_center-x,color);
Putpixel (X_center-y1,y_center-x,color);
Putpixel (X_center-y1,x+y_center,color);
}
}

void Circle (int x_center,int y_center,int radius,int color)
{Register int x,y,delta;
Y=radius;
Delta=3-2*radius;

for (x=0;x<y;) {
Plot_circle (X,y,x_center,y_center,color);
if (delta<0) delta+=6+ (X<<2);
else{
delta+=10+ ((x-y) <<2);
y--;
}
x + +;
}
X=y;
if (y) plot_circle (X,y,x_center,y_center,color);
}

Main ()
{
int x=100,y=100,color=35;
INIT256 ();
Box (X,y,x+100,y+100,color);
Circle (X+200,y+150,200,color);
Fillbox (200,200,350,350,color);
Getch ();
EXIT256 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.