📄 grdemo.c
字号:
NextColorValue( LIMITED );
/* Fill slices. */
while( tc.xCur >= (-xSize + xInc))
{
PenColor( NextColorIndex( DEFAULT ) );
FillIn();
Move( -xInc );
}
while( !ClickOrPress() )
NextColorValue( LIMITED );
PenDown( TRUE );
SetFill( fFill );
}
/* Polygons - Draws polygons (starting with triangle) of increasing
* size by incrementing the number of sides without changing the
* length of sides. Make sure pen is down.
*
* Params: None
*
* Return: 1 for user interrupt, 0 for edge of screen encountered
*
* Uses: tc
*/
int Polygons()
{
int cSides = 3, atrib = 1;
double dxy = tc.yUnit;
while( TRUE )
{
PenColor( NextColorIndex( DEFAULT ) );
if( !Poly( cSides++, dxy += 1.5 ) )
return FALSE;
if( ClickOrPress() )
return TRUE;
}
}
/* Spiral - Draw a spiral by incrementing the length of each side
* of a rotating figure.
*
* Params: ang - determines tightness
* xyInc - determines size of sides
*
* Return: 1 for user interrupt, 0 for edge of screen encountered
*
* Uses: tc
*/
int Spiral( int ang, double xyInc )
{
double xy = tc.yUnit;
while( TRUE )
{
PenColor( NextColorIndex( DEFAULT ) );
if( !Move( xy += xyInc ) )
return FALSE;
Turn( ang );
if( ClickOrPress() )
return TRUE;
}
}
/* InSpiral - Draw an inverted spiral by increasing each angle
* of a rotating figure while keeping the length of sides constant.
*
* Params: xy - determines size
* ang - initial angle determines shape
* angInc - determines tightness and shape
*
* Return: 1 for user interrupt, 0 for edge of screen encountered
*/
int InSpiral( double xy, int ang, int angInc )
{
while( TRUE )
{
PenColor( NextColorIndex( DEFAULT ) );
if( !Move( xy ) )
return FALSE;
Turn( ang += angInc );
if( ClickOrPress())
return TRUE;
}
}
/* Bug - Draws a winged bug on the screen. Then moves it randomly
* around the screen.
*
* Params: None
*
* Return: None
*
* Uses: tc
*/
void Bug()
{
static unsigned char uTopWing[] = { 0x81, 0x3c, 0xc3, 0x66,
0x66, 0x0f, 0xf0, 0x18 };
static unsigned char uBotWing[] = { 0x66, 0x0f, 0xf0, 0x18,
0x81, 0x3c, 0xc3, 0x66 };
char *buffer; /* Buffer for image */
/* Draw bug. */
PenDown( FALSE );
SetFill( TRUE );
Move( 40.0 ); /* Draw and fill front wings */
Turn( 90 );
Move( 80.0 );
PenColor( 1 );
_setfillmask( uTopWing );
Ellipse( 172.0, 70.0 );
Turn( 180 );
Move( 160.0 );
Ellipse( 172.0, 70.0 );
Turn(-90 );
MoveTo( 0.0, 0.0 );
Move( 25.0 ); /* Draw and fill back wings */
Turn( 90 );
Move( 70.0 );
PenColor( 2 );
_setfillmask( uBotWing );
Ellipse( 150.0, 70.0 );
Turn( 180 );
Move( 140.0 );
Ellipse( 150.0, 70.0 );
Turn(-90 );
MoveTo( 0.0, 0.0 );
_setfillmask( NULL ); /* Draw body */
PenColor( 3 );
BorderColor( 3 );
Ellipse( 52.0, 220.0 );
PenColor( 1 ); /* Drill eyes */
BorderColor( 1 );
SetFill( FALSE );
Move( 90.0 );
Turn( 90 );
Move( 22.0 );
Circle( 20.0 );
PenColor( 0 );
FillIn();
PenColor( 1 );
Turn( 180 );
Move( 44.0 );
Circle( 20.0 );
PenColor( 0 );
FillIn();
/* Move into position - top-right of image. */
MoveTo( 0.0, 0.0 );
TurnTo( 0 );
Move( 120.0 );
Turn( -90 );
Move( 175.0 );
Turn( 90 );
/* Size image and allocate memory for it. */
buffer = (char *)malloc( (size_t)ImageSize( 350.0, 240.0 ) );
GetImage( 350.0, 240.0, buffer );
/* Move randomly, adjusting at edges. */
while( !ClickOrPress() )
{
if( tc.xCur <= (-tc.xMax + 15.0) )
TurnTo( 90 );
else if( tc.yCur <= (-tc.yMax + 15.0) )
TurnTo( 180 );
else if( tc.xCur >= (tc.xMax - 365.0) )
TurnTo( 270 );
else if( tc.yCur >= (tc.yMax - 255.0) )
TurnTo( 0 );
else
Turn( getrandom( -20, 20 ) );
Move( 3.0 );
PutImage( buffer, _GPSET );
}
free( (char *)buffer );
}
/* Adjust - Allow the user to interactively adjust the display window.
* Unshifted direction keys adjust the window size. Shifted direction
* keys move the window. The numeric keypad plus and minus keys adjust
* aspect without changing the window. A window frame and a diamond give
* visual feedback on adjustments.
*
* Params: None
*
* Return: None
*
* Uses: tc and vc
*/
#define WININC 4
void Adjust()
{
short iWriteMode;
double xyRadius = 400.0, xEdge, yEdge;
char achT[80];
/* Display instructions. */
_clearscreen( _GCLEARSCREEN );
_settextposition( 2, 2 );
_outtext(" Grey PLUS and MINUS Adjust aspect" );
_settextposition( 3, 2 );
_outtext(" Cursor keys Size window" );
_settextposition( 4, 2 );
_outtext(" SHIFT cursor keys Move window" );
_settextposition( 5, 2 );
_outtext(" ENTER Finished" );
/* Save old write mode and set XOR so you can erase figures by
* redrawing. This allows lines to overwrite text without erasing.
*/
iWriteMode = _getwritemode();
_setwritemode( _GXOR );
while( TRUE )
{
/* Display data. */
_settextposition( 6, 2 );
sprintf( achT,
" Ratio=%1.2f Left=%.3i Top=%.3i Right=%.3i Bottom=%.3i",
tc.yxRatio, tc.xsLeft, tc.ysTop, tc.xsRight, tc.ysBot );
_outtext( achT );
/* Calculate current box edges. */
xEdge = 2 * tc.xMax;
yEdge = 2 * tc.yMax;
/* Draw border rectangle and diamond that illustrates ratio. */
Rectangle( xEdge, yEdge );
Diamond( xyRadius );
switch( GetKey( CLEAR_WAIT ) )
{
/* Adjust aspect. */
case N_MINUS:
if( tc.yxRatio > 0.4 )
tc.yxRatio = (tc.xMax - (WININC * tc.yUnit)) / tc.yMax;
break;
case N_PLUS:
if( tc.yxRatio < 8.0 )
tc.yxRatio = (tc.xMax + (WININC * tc.yUnit)) / tc.yMax;
break;
/* Adjust window size. */
case U_RT:
if( tc.xsLeft < (vc.numxpixels / 3) )
tc.xsLeft += WININC;
if( tc.xsRight > (vc.numxpixels - (vc.numxpixels / 3)) )
tc.xsRight -= WININC;
break;
case U_LT:
if( tc.xsLeft > WININC )
tc.xsLeft -= WININC;
if( tc.xsRight < vc.numxpixels )
tc.xsRight += WININC;
break;
case U_DN:
if( tc.ysTop < (vc.numypixels / 3) )
tc.ysTop += WININC;
if( tc.ysBot > (vc.numypixels - (vc.numypixels / 3)) )
tc.ysBot -= WININC;
break;
case U_UP:
if( tc.ysTop > WININC )
tc.ysTop -= WININC;
if( tc.ysBot < vc.numypixels )
tc.ysBot += WININC;
break;
/* Adjust window position. */
case S_LT:
if( tc.xsLeft > WININC )
{
tc.xsLeft -= WININC;
tc.xsRight -= WININC;
}
break;
case S_RT:
if( tc.xsRight < vc.numxpixels )
{
tc.xsLeft += WININC;
tc.xsRight += WININC;
}
break;
case S_UP:
if( tc.ysTop > WININC )
{
tc.ysTop -= WININC;
tc.ysBot -= WININC;
}
break;
case S_DN:
if( tc.ysBot < vc.numypixels )
{
tc.ysTop += WININC;
tc.ysBot += WININC;
}
break;
/* Finished. */
case ENTER:
_setwritemode( iWriteMode );
return;
/* Ignore unknown key. */
default:
break;
}
/* Redraw figures to erase them. Reset defaults. */
Rectangle( xEdge, yEdge );
Diamond( xyRadius );
Home();
}
}
/* Routine used by Adjust to draw its diamond. */
void Diamond( double xy )
{
PenDown( FALSE );
MoveTo( 0.0, xy );
PenDown( TRUE );
MoveTo( xy, 0.0 );
MoveTo( 0.0, -xy );
MoveTo( -xy, 0.0 );
MoveTo( 0.0, xy );
PenDown( FALSE );
MoveTo( 0.0, 0.0 );
PenDown( TRUE );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -