Computer Animation Bouncing Ball Program using MFC C++ code

Basic Computer Animation Program using MS Visual Studio 6.0 with MFC application.Here in this program we make use of flood fill concept . The function is very simple indicating just coordinates which has to be displayed on the screen.

 PROGRAM:
void CBouncingballView::OnDraw(CDC* pDC)
{
	CBouncingballDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
POINT ball[2]={25,150,75,100};
	pDC->Ellipse(ball[0].x,ball[0].y,ball[1].x,ball[1].y);
	for(int k=0;k<600;k++)
	{
		pDC->FloodFill(50,50,RGB(100,100,100));
        pDC->MoveTo(10,150);
	    pDC->LineTo(600,150);
		for(int i=0;i<250;i++)
		{
		for(int i=0;i<250;i++)
	{
		pDC->FloodFill(50,50,RGB(100,100,100));
		pDC->Ellipse(ball[0].x,ball[0].y++,ball[1].x,ball[1].y++);
	    pDC->MoveTo(10,400);
	    pDC->LineTo(600,400);
	}
	for(int j=250;j>=1;j--)
    {	
		pDC->FloodFill(50,50,RGB(100,100,100));
		pDC->Ellipse(ball[0].x++,ball[0].y--,ball[1].x++,ball[1].y--);
        pDC->MoveTo(10,400);
	    pDC->LineTo(600,400);
	    Sleep(1);
	}
		}
	}
}


OUTPUT:



0 comments:

Post a Comment

If You Are Asking Some Question On This Comment Then Click On Subscribe by email Link