⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ms_p1.cpp

📁 It s an entire application that uses knowdledge of probabilistic and statistical math to generate an
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    char str[20];


    settextstyle(0,0,0);


    for (i=0; i<_NUM_VIEWS; i++)
    {
	if (
	    (SwitchFScreen)&&
	    (i!=SelView)
	   )
	{
	    continue;
	}

	if (SelView==i)
	{
	    setcolor(_SEL_VIEW_COLOR);
	}
	else
	{
	    setcolor(_VIEW_COLOR);
	}

	rectangle(Views[i].x,Views[i].y,Views[i].x+Views[i].width,Views[i].y+Views[i].height);

	if (SelView==i)
	{
	    rectangle(Views[i].x+1,Views[i].y+1,Views[i].x+Views[i].width-1,Views[i].y+Views[i].height-1);
	    rectangle(Views[i].x+2,Views[i].y+2,Views[i].x+Views[i].width-2,Views[i].y+Views[i].height-2);
	}

	setcolor(8);

	sprintf(str,"View %d",i);

	outtextxy(Views[i].x+5,Views[i].y+5,str);

	setcolor(_COORD_SYS_COLOR);


	rectangle(Views[i].csx0,Views[i].csy0,Views[i].csx1,Views[i].csy1);

	setfillstyle(1,Views[i].backcolor);
	bar(Views[i].csx0+1,Views[i].csy0+1,Views[i].csx1-1,Views[i].csy1-1);
    }
}



/***************************************************************************/
/***************************************************************************/
/***  Deseneaza histograma de pe urma distributiei din viewportul "view" ***/
/***************************************************************************/
/***************************************************************************/

void _DrawRV
   (
    unsigned char view
   )

{
    float i,x,y,oldx,oldy;
    float hmax;
    float tempX,tempY,temp;
    char str[20];


    hmax=0;
    for (i=0; i<Views[view].n; i++)
    {
	if (Views[view].nr[i]>hmax)
	{
	    hmax=Views[view].nr[i];
	}
    }

    hmax/=Views[view].N;

    setcolor(Views[view].color);

    tempX=(float)(Views[view].csx1-Views[view].csx0)/Views[view].n;
    tempY=(float)(Views[view].csy1-Views[view].csy0)/hmax;

    for (i=1; i<Views[view].n+1; i++)
    {
	x=Views[view].csx0+i*tempX;
	y=Views[view].csy1-Views[view].nr[i-1]*tempY/Views[view].N;

	setfillstyle(1,Views[view].color);

	if (Views[view].SwitchBar)
	{
	    if (i==Views[view].n)
	    {
		break;
	    }

	    bar(x,y,x+tempX,Views[view].csy1);
	}
	else
	{
	    setcolor(Views[view].color);

	    line(x,Views[view].csy1,x,y);

	    if (Views[view].SwitchBubble)
	    {
		pieslice(x,y,0,360,_BUBBLE_SIZE);
	    }
	}

	if (
	    (i>1)&&
	    (Views[view].SwitchInterp)
	   )
	{
	    setcolor(Views[view].interpcolor);

	    line(oldx,oldy,x,y);
	}


	oldx=x;
	oldy=y;
    }


    if (
	(Views[view].SwitchRuler)||
	(Views[view].SwitchGrid)
       )
    {
	temp=(float)Views[view].n*Views[view].RulerResX;
	i=1;

	settextstyle(2,0,2);
	setcolor(Views[view].rulercolor);

	while (i<=Views[view].n)
	{
	    x=Views[view].csx0+i*tempX;

	    if (Views[view].SwitchRuler)
	    {
		line(x,Views[view].csy1-_HALF_RULER,x,Views[view].csy1+_HALF_RULER);

		sprintf(str,"%.2f",i);
		outtextxy(x-(textwidth(str)>>1),Views[view].csy1+5,str);
	    }

	    if (Views[view].SwitchGrid)
	    {
		line(x,Views[view].csy1,x,Views[view].csy0);
	    }


	    i+=temp;
	}



	temp=(float)hmax*Views[view].RulerResY;
	i=0;

	while (i<=hmax)
	{
	    y=Views[view].csy1-i*tempY;

	    if (Views[view].SwitchRuler)
	    {
		line(Views[view].csx0-_HALF_RULER,y,Views[view].csx0+_HALF_RULER,y);

		sprintf(str,"%.2f",i);
		outtextxy(Views[view].csx0-textwidth(str),y-(textheight(str)>>1),str);
	    }

	    if (Views[view].SwitchGrid)
	    {
		line(Views[view].csx0,y,Views[view].csx1,y);
	    }


	    i+=temp;
	}

	settextstyle(0,0,0);
    }
}



/***************************************************************************/
/***************************************************************************/
/***              Sterge ecranul cu respectiva culoare                   ***/
/***************************************************************************/
/***************************************************************************/

void _ClearScreen
   (
    char color
   )

{
    setfillstyle(1,color);
    bar(0,0,getmaxx(),getmaxy());
}



/***************************************************************************/
/***************************************************************************/
/***            Seteaza viewportul "view" ca fullscreen                  ***/
/***************************************************************************/
/***************************************************************************/

void _FullScreenView
   (
    unsigned int view
   )

{
    _GenerateViews();

    if (SwitchFScreen)
    {
	Views[view].x     =0;
	Views[view].y     =0;
	Views[view].width =getmaxx();
	Views[view].height=getmaxy();
	Views[view].csx0=Views[view].x+_COORD_SYS_DXY;
	Views[view].csy0=Views[view].y+_COORD_SYS_DXY;
	Views[view].csx1=Views[view].x+Views[view].width -_COORD_SYS_DXY;
	Views[view].csy1=Views[view].y+Views[view].height-_COORD_SYS_DXY;
    }
}



/***************************************************************************/
/***************************************************************************/
/***           Deseneaza un frame pe ecran (viewporturile)               ***/
/***************************************************************************/
/***************************************************************************/

void _DrawFrame
   (
   )

{
    int i;


    _ClearScreen(BackColor);
    _DrawViews();
    _FreeBuffers();

    for (i=0; i<_NUM_VIEWS; i++)
    {
	if (
	    (SwitchFScreen)&&
	    (i!=SelView)
	   )
	{
	    continue;
	}

	_RefreshDistrib(i);
	_DrawRV        (i);

	if (i!=SelView)
	{
	    _FreeViewportBuffers(i);
	}
    }
}



/***************************************************************************/
/***************************************************************************/
/***            Elibereaza bufferele continute in fiecare viewport       ***/
/***************************************************************************/
/***************************************************************************/

void _FreeBuffers
   (
   )

{
    unsigned int i;


    for (i=0; i<_NUM_VIEWS; i++)
    {
	if (Views[i].X)
	{
	    free(Views[i].X);
	}

	if (Views[i].P)
	{
	    free(Views[i].P);
	}
	if (Views[i].F)

	{
	    free(Views[i].F);
	}

	if (Views[i].nr)
	{
	    free(Views[i].nr);
	}

	Views[i].X =NULL;
	Views[i].P =NULL;
	Views[i].F =NULL;
	Views[i].nr=NULL;
    }
}



/***************************************************************************/
/***************************************************************************/
/***            Elibereaza bufferele unui singur viewport                ***/
/***************************************************************************/
/***************************************************************************/

void _FreeViewportBuffers
   (
    unsigned int view
   )

{
    if (Views[view].X)
    {
	free(Views[view].X);
    }

    if (Views[view].P)
    {
	free(Views[view].P);
    }

    if (Views[view].F)
    {
	free(Views[view].F);
    }

    if (Views[view].nr)
    {
	free(Views[view].nr);
    }

    Views[view].X =NULL;
    Views[view].P =NULL;
    Views[view].F =NULL;
    Views[view].nr=NULL;
}



/***************************************************************************/
/***************************************************************************/
/***            Reface toate distributiile in urma unei modificari       ***/
/***                           a parametrilor lor                        ***/
/***************************************************************************/
/***************************************************************************/

void _RefreshDistrib
   (
    unsigned int view
   )

{
    _DiscreteSimulation(view);
}



/***************************************************************************/
/***************************************************************************/
/***              Initializeaza variabilele de distributie               ***/
/***************************************************************************/
/***************************************************************************/

void _InitDistributions
   (
   )

{
    unsigned char i;


    for (i=0; i<_NUM_VIEWS; i++)
    {
	Views[i].n=_n;
	Views[i].N=_N;
	Views[i].seed=rand();

	Views[i].color      =_DRAW_COLOR;
	Views[i].rulercolor =_RULER_COLOR;
	Views[i].interpcolor=_INTERP_COLOR;
	Views[i].backcolor  =i+1;
	Views[i].SwitchBubble=1;
	Views[i].SwitchBar   =0;
	Views[i].SwitchRuler =0;
	Views[i].SwitchGrid  =0;
	Views[i].SwitchInterp=0;

	Views[i].RulerResX=0.07;
	Views[i].RulerResY=0.07;


	Views[i].X =NULL;
	Views[i].P =NULL;
	Views[i].F =NULL;
	Views[i].nr=NULL;
    }

    Views[0].SwitchRuler =1;
    Views[0].SwitchGrid  =1;
    Views[0].SwitchInterp=1;

    Views[1].SwitchRuler =0;
    Views[1].SwitchGrid  =0;
    Views[1].SwitchInterp=1;
    Views[1].SwitchBubble=0;

    Views[2].SwitchRuler =0;
    Views[2].SwitchGrid  =0;
    Views[2].SwitchInterp=0;
    Views[2].SwitchBar   =1;

    Views[3].SwitchRuler =1;
    Views[3].SwitchGrid  =1;
    Views[3].SwitchInterp=1;
}



/***************************************************************************/
/***************************************************************************/
/***                       Functia principala                            ***/
/***************************************************************************/
/***************************************************************************/

int main
   (
   )

{
    int i;
    int key;
    int gdriver,gmode;


    gdriver=DETECT;

    initgraph(&gdriver,&gmode,"");

    SelView=0;
    SwitchFScreen=0;
    BackColor=_BACKGROUND;
    strcpy(csCmdLine ,"");
    strcpy(csCmdLine2,"");
    quit=0;

    _InitConsole();
    _InitDistributions();
    _GenerateViews();
    _DrawFrame();

    do
    {
	key=getch();

	if (!SwitchConsole)
	{
	    if (
		(key=='f')||
		(key=='F')
	       )
	    {
		SwitchFScreen=1-SwitchFScreen;
		_FullScreenView(SelView);
	    }

	    if (
		(key=='c')||
		(key=='C')
	       )
	    {
		Views[SelView].SwitchBubble=1-Views[SelView].SwitchBubble;
	    }

	    if (
		(key=='b')||
		(key=='B')
	       )
	    {
		Views[SelView].SwitchBar=1-Views[SelView].SwitchBar;
	    }

	    if (
		(key=='g')||
		(key=='G')
	       )
	    {
		Views[SelView].SwitchGrid=1-Views[SelView].SwitchGrid;
	    }

	    if (
		(key=='r')||
		(key=='R')
	       )
	    {
		Views[SelView].SwitchRuler=1-Views[SelView].SwitchRuler;
	    }

	    if (
		(key=='i')||
		(key=='I')
	       )
	    {
		Views[SelView].SwitchInterp=1-Views[SelView].SwitchInterp;
	    }

	    if (
		(key=='+')&&
		(!SwitchFScreen)
	       )
	    {
		SelView++;
		SelView&=0x3;
	    }

	    if (key==_ESCAPE)
	    {
		quit=1;
	    }
	}


	if (key=='~')
	{
	    _DropConsole();

	    key=_BACKSPACE;
	}

	if (SwitchConsole)
	{
	    if (
		(key!=_ENTER)&&
		(strlen(csCmdLine)<_CS_CH_WIDTH-1)&&
		(key!=_BACKSPACE)&&
		(key!=_UP)
	       )
	    {
		char s[2];

		strcpy(s,"");
		s[0]=(char)key;
		s[1]=NULL;

		strcat(csCmdLine,s);
	    }

	    if (key==_BACKSPACE)
	    {
		if (strlen(csCmdLine)>=1)
		{
		    csCmdLine[strlen(csCmdLine)-1]=NULL;
		}
	    }

	    if (key==_UP)
	    {
		strcpy(csCmdLine,csCmdLine2);
	    }

	    if (key==_ENTER)
	    {
		char str[_CS_CH_WIDTH+1];

		strcpy(csCmdLine2,csCmdLine);

		sprintf(str,">%s",csCmdLine);

		csLineTextColor[_PushConsoleText(str)]=_CS_CMD_COLOR;

		_TokenizeCmdLine();

		_CompileCmdLine();

		_DrawFrame();
		_DrawConsole();

		strcpy(csCmdLine,"");
	    }
	}

	if (!SwitchConsole)
	{
	    _DrawFrame();
	}

	_DrawConsole();
    }
    while (!quit);

    _FreeBuffers();

    closegraph();


    return(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -