📄 pattern.c
字号:
/* %kw # %v %n %d %t # */
/* Version # 4 PATTERN.C 26-May-94 15:41:44 # */
/* *************************************************** */
/* METAGRAPHICS SOFTWARE CORPORATION (c) 1987-1992 */
/* Demonstrates patterns and shapes */
/* *************************************************** */
#define byte unsigned char
#define word unsigned short
#include <stdlib.h>
#include "metawndo.h" /* master MetaWINDOW include file */
/* special stack size declaration if using Turbo or Borland C++ */
#ifdef TurboC
extern unsigned _stklen = 14336U; /* stack size 14K */
#endif
void Waiting(int a);
void pattern( )
{
int ScrnXmax,ScrnYmax,x,y,z,dx,dy,dxx,dyy,h,i,j,clr,pat,rInset;
int object;
long pnClrInc, maxColr;
rect sR,R;
point p_pts[7]; /* The polygon point series */
polyHead p_hdr; /* the polygon header array */
// long count;
#ifndef CYCLE
void quit(void);
mwEvent waitEvent;
#endif
struct testData /* test pattern */
{patRcd tpHdr;
char tpData[8]; };
struct testData testPattern = { {8,8,0,0,1,1,1},
{0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x80} };
/* init the system */
// i = InitGraphics(2 );
/* init screen */
// SetDisplay (GrafPg0);
ScreenRect(&sR);
RasterOp(zREPz);
ScrnXmax = sR.Xmax;
ScrnYmax = sR.Ymax;
/* set up the polygon header array */
p_hdr.polyBgn = 0;
p_hdr.polyEnd = 6;
p_hdr.polyRect= sR;
/* set up screen variable */
dx = (ScrnXmax+1)/8; dy=(ScrnYmax+1)/4;
dxx = dx/5;
dyy = dy/6;
rInset = dxx;
maxColr = QueryColors();
if (maxColr > 65536) pnClrInc = 0x040c14;
else if (maxColr > 256) pnClrInc = 0x1314;
else pnClrInc = 31;
BackColor(0);
EraseRect(&sR);
for (object = 1; object <= 8; object++){
clr = 1;
/* do 16 iterations */
// for( h=0; h<16; h++) {
for( h=0; h<1; h++) {
clr += pnClrInc;
pat = 0; y = 0;
/* do 4 objects vertically */
for( i=0; i<4; i++ ) {
x=0;
/* do 8 objects horizontally */
for( j=0; j<8; j++) {
SetRect( &R, x, y, x+(dx-dxx), y+(dy-dyy) );
InsetRect(&R, -1,-1);
BackColor(0); EraseRect( &R);
InsetRect(&R, 1,1);
if((clr > maxColr)) clr = 1;
BackColor(clr); PenColor(maxColr-clr);
switch(object) {
case 1:
FillRect(&R,pat);
FrameRect(&R);
break;
case 2:
FillRoundRect(&R,dxx,dyy,pat);
FrameRoundRect(&R,dxx,dyy);
break;
case 3:
FillOval(&R,pat);
FrameOval(&R);
break;
case 4:
PenPattern(1);
PenColor(clr+1);
FrameOval(&R);
InsetRect(&R, rInset,rInset);
FrameRect(&R);
PenPattern(pat);
PenColor(maxColr-clr);
InsetRect(&R, -rInset,-rInset);
FloodFill( (R.Xmax+R.Xmin)/2, R.Ymin+5, &R);
break;
case 5:
PenPattern(1);
PenColor(clr+1);
FrameOval(&R);
InsetRect(&R, rInset,rInset);
FrameRect(&R);
PenPattern(pat);
PenColor(maxColr-clr);
InsetRect(&R, -rInset,-rInset);
BoundaryFill( (R.Xmax+R.Xmin)/2, R.Ymin+5, clr+1, &R);
break;
case 6:
FillArc(&R,pat*80,450,pat);
FrameArc(&R,pat*80,450);
break;
case 7:
z=0;
p_pts[z].X = x;
p_pts[z].Y = y;
z++;
p_pts[z].X = x+((dx-dxx)/2);
p_pts[z].Y = y+(dy-dyy);
z++;
p_pts[z].X = x+(dx-dxx);
p_pts[z].Y = y;
z++;
p_pts[z].X = x+(dx-dxx);
p_pts[z].Y = y+(dy-dyy);
z++;
p_pts[z].X = x+((dx-dxx)/2);
p_pts[z].Y = y;
z++;
p_pts[z].X = x;
p_pts[z].Y = y+(dy-dyy);
z++;
p_pts[z].X = x;
p_pts[z].Y = y;
FillPoly(1,&p_hdr,p_pts,pat);
break;
case 8:
BackColor(-1); PenColor(0);
if((i==0) && (j==0)) DefinePattern(8, &testPattern.tpHdr);
AlignPattern(8,(i << 1),j);
FillRect(&R,8);
break;
default:
break;
}
x+=dx; pat++; clr += pnClrInc;
} /* end of horizontal */
y+=dy;
} /* end of vertical */
} /* end of for n times */
DefinePattern(8, 0);
#ifndef CYCLE
PenColor(-1);
BackColor(0);
MoveTo( 0,sR.Ymax - 20 );
DrawString( "Press 'x' to exit" );
MoveTo( 0,sR.Ymax - 10 );
DrawString( "any other key to continue" );
while(!KeyEvent(1, &waitEvent));
if((waitEvent.eventChar == 'x') || (waitEvent.eventChar == 'X')) quit();
#else
#ifdef _MNT_
KeyEvent(0, &waitEvent);
if((waitEvent.eventChar == 'x') || (waitEvent.eventChar == 'X')) quit();
#endif
#ifdef _MNT_
KeyEvent(0, &waitEvent);
if((waitEvent.eventChar == 'x') || (waitEvent.eventChar == 'X')) quit();
#endif
Waiting(150);
#endif
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -