📄 bgidemo.c
字号:
outs[6].x = cx - dx;
outs[6].y = cy - dy;
setfillstyle( SOLID_FILL, WHITE );
fillpoly( 7, (int far *)outs );
outs[0].x = cx - (w/2);
outs[0].y = cy + h;
outs[1].x = cx + (w/2);
outs[1].y = cy + h;
outs[2].x = cx + (w/2);
outs[2].y = cy - h;
outs[3].x = cx - (w/2);
outs[3].y = cy - h;
outs[4].x = cx - (w/2);
outs[4].y = cy + h;
setfillstyle( SOLID_FILL, BLUE );
fillpoly( 5, (int far *)outs );
/* Draw a Tesseract object on the screen using the LineRel and */
/* MoveRel drawing commands. */
moveto( cx-dx, cy-dy );
linerel( w, -h );
linerel( 3*w, 0 );
linerel( 0, 5*h );
linerel( -w, h );
linerel( -3*w, 0 );
linerel( 0, -5*h );
moverel( w, -h );
linerel( 0, 5*h );
linerel( w+(w/2), 0 );
linerel( 0, -3*h );
linerel( w/2, -h );
linerel( 0, 5*h );
moverel( 0, -5*h );
linerel( -(w+(w/2)), 0 );
linerel( 0, 3*h );
linerel( -w/2, h );
moverel( w/2, -h );
linerel( w, 0 );
moverel( 0, -2*h );
linerel( -w, 0 );
Pause(); /* Wait for user's response */
}
/* */
/* PUTPIXELDEMO: Display a pattern of random dots on the screen */
/* and pick them back up again. */
/* */
void PutPixelDemo(void)
{
int seed = 1958;
int i, x, y, h, w, color;
struct viewporttype vp;
MainWindow( "PutPixel / GetPixel Demonstration" );
getviewsettings( &vp );
h = vp.bottom - vp.top;
w = vp.right - vp.left;
srand( seed ); /* Restart random # function */
for( i=0 ; i<5000 ; ++i ){ /* Put 5000 pixels on screen */
x = 1 + random( w - 1 ); /* Generate a random location */
y = 1 + random( h - 1 );
color = random( MaxColors );
putpixel( x, y, color );
}
srand( seed ); /* Restart Random # at same # */
for( i=0 ; i<5000 ; ++i ){ /* Take the 5000 pixels off */
x = 1 + random( w - 1 ); /* Generate a random location */
y = 1 + random( h - 1 );
color = getpixel( x, y ); /* Read the color pixel */
if( color == random( MaxColors ) ) /* Used to keep RANDOM in sync */
putpixel( x, y, 0 ); /* Write pixel to BLACK */
}
Pause(); /* Wait for user's response */
}
/* */
/* PUTIMAGEDEMO */
/* */
void PutImageDemo(void)
{
static int r = 20;
static int StartX = 100;
static int StartY = 50;
struct viewporttype vp;
int PauseTime, x, y, ulx, uly, lrx, lry, size, i, width, height, step;
void *Saucer;
MainWindow("GetImage / PutImage Demonstration");
getviewsettings( &vp );
/* Draw Saucer */
setfillstyle( SOLID_FILL, getmaxcolor() );
fillellipse(StartX, StartY, r, (r/3)+2);
ellipse(StartX, StartY-4, 190, 357, r, r/3);
line(StartX+7, StartY-6, StartX+10, StartY-12);
circle(StartX+10, StartY-12, 2);
line(StartX-7, StartY-6, StartX-10, StartY-12);
circle(StartX-10, StartY-12, 2);
/* Read saucer image */
ulx = StartX-(r+1);
uly = StartY-14;
lrx = StartX+(r+1);
lry = StartY+(r/3)+3;
width = lrx - ulx + 1;
height = lry - uly + 1;
size = imagesize(ulx, uly, lrx, lry);
Saucer = malloc( size );
getimage(ulx, uly, lrx, lry, Saucer);
putimage(ulx, uly, Saucer, XOR_PUT);
/* Plot some "stars" */
for ( i=0 ; i<1000; ++i )
putpixel(random(MaxX), random(MaxY), random( MaxColors-1 )+1);
x = MaxX / 2;
y = MaxY / 2;
PauseTime = 70;
/* until a key is hit */
while ( !kbhit() ) {
/* Draw the Saucer */
putimage(x, y, Saucer, XOR_PUT); /* draw image */
delay(PauseTime);
putimage(x, y, Saucer, XOR_PUT); /* erase image */
/* Move Saucer */
step = random( 2*r );
if ((step/2) % 2 != 0 )
step = -1 * step;
x = x + step;
step = random( r );
if ((step/2) % 2 != 0 )
step = -1 * step;
y = y + step;
if (vp.left + x + width - 1 > vp.right)
x = vp.right-vp.left-width + 1;
else
if (x < 0)
x = 0;
if (vp.top + y + height - 1 > vp.bottom)
y = vp.bottom-vp.top-height + 1;
else
if (y < 0)
y = 0;
}
free( Saucer );
Pause();
}
/* */
/* LINETODEMO: Display a pattern using moveto and lineto commands. */
/* */
#define MAXPTS 15
void LineToDemo(void)
{
struct viewporttype vp;
struct PTS points[MAXPTS];
int i, j, h, w, xcenter, ycenter;
int radius, angle, step;
double rads;
MainWindow( "MoveTo / LineTo Demonstration" );
getviewsettings( &vp );
h = vp.bottom - vp.top;
w = vp.right - vp.left;
xcenter = w / 2; /* Determine the center of circle */
ycenter = h / 2;
radius = (h - 30) / (AspectRatio * 2);
step = 360 / MAXPTS; /* Determine # of increments */
angle = 0; /* Begin at zero degrees */
for( i=0 ; i<MAXPTS ; ++i ){ /* Determine circle intercepts */
rads = (double)angle * PI / 180.0; /* Convert angle to radians */
points[i].x = xcenter + (int)( cos(rads) * radius );
points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio );
angle += step; /* Move to next increment */
}
circle( xcenter, ycenter, radius ); /* Draw bounding circle */
for( i=0 ; i<MAXPTS ; ++i ){ /* Draw the cords to the circle */
for( j=i ; j<MAXPTS ; ++j ){ /* For each remaining intersect */
moveto(points[i].x, points[i].y); /* Move to beginning of cord */
lineto(points[j].x, points[j].y); /* Draw the cord */
}
}
Pause(); /* Wait for user's response */
}
/* */
/* LINESTYLEDEMO: Display a pattern using all of the standard */
/* line styles that are available. */
/* */
void LineStyleDemo(void)
{
int style, step;
int x, y, w;
struct viewporttype vp;
char buffer[40];
MainWindow( "Pre-defined line styles" );
getviewsettings( &vp );
w = vp.right - vp.left;
x = 35;
y = 10;
step = w / 11;
settextjustify( LEFT_TEXT, TOP_TEXT );
outtextxy( x, y, "Normal Width" );
settextjustify( CENTER_TEXT, TOP_TEXT );
for( style=0 ; style<4 ; ++style ){
setlinestyle( style, 0, NORM_WIDTH );
line( x, y+20, x, vp.bottom-40 );
itoa( style, buffer, 10 );
outtextxy( x, vp.bottom-30, buffer );
x += step;
}
x += 2 * step;
settextjustify( LEFT_TEXT, TOP_TEXT );
outtextxy( x, y, "Thick Width" );
settextjustify( CENTER_TEXT, TOP_TEXT );
for( style=0 ; style<4 ; ++style ){
setlinestyle( style, 0, THICK_WIDTH );
line( x, y+20, x, vp.bottom-40 );
itoa( style, buffer, 10 );
outtextxy( x, vp.bottom-30, buffer );
x += step;
}
settextjustify( LEFT_TEXT, TOP_TEXT );
Pause(); /* Wait for user's response */
}
/* */
/* CRTMODEDEMO: Demonstrate the effects of the change mode */
/* commands on the current screen. */
/* */
void CRTModeDemo(void)
{
struct viewporttype vp;
int mode;
MainWindow( "SetGraphMode / RestoreCRTMode demo" );
getviewsettings( &vp );
mode = getgraphmode();
settextjustify( CENTER_TEXT, CENTER_TEXT );
outtextxy( (vp.right-vp.left)/2, (vp.bottom-vp.top)/2,
"Now you are in graphics mode..." );
StatusLine( "Press any key for text mode..." );
getch();
restorecrtmode();
printf( "Now you are in text mode.\n\n" );
printf( "Press any key to go back to graphics..." );
getch();
setgraphmode( mode );
MainWindow( "SetGraphMode / RestoreCRTMode demo" );
settextjustify( CENTER_TEXT, CENTER_TEXT );
outtextxy( (vp.right-vp.left)/2, (vp.bottom-vp.top)/2,
"Back in Graphics Mode..." );
Pause(); /* Wait for user's response */
}
/* */
/* USERLINESTYLEDEMO: Display line styles showing the user */
/* defined line style functions. */
/* */
void UserLineStyleDemo(void)
{
int x, y, i, h, flag;
unsigned int style;
struct viewporttype vp;
MainWindow( "User defined line styles" );
getviewsettings( &vp );
h = vp.bottom - vp.top;
x = 4;
y = 10;
style = 0;
i = 0;
settextjustify( CENTER_TEXT, TOP_TEXT );
flag = TRUE; /* Set the bits in this pass */
while( x < vp.right-2 ){ /* Draw lines across the screen */
if( flag ) /* If flag, set bits... */
style = style | (1 << i); /* Set the Ith bit in word */
else /* If no flag, clear bits */
style = style & !(0x8000 >> i); /* Clear the Ith bit in word */
setlinestyle( USERBIT_LINE, style, NORM_WIDTH );
line( x, y, x, h-y ); /* Draw the new line pattern */
x += 5; /* Move the X location of line */
i = ++i % 16; /* Advance to next bit pattern */
if( style == 0xffff ){ /* Are all bits set? */
flag = FALSE; /* begin removing bits */
i = 0; /* Start with whole pattern */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -